]>
jfr.im git - erebus.git/blob - modules/eval.py
1 # Erebus IRC bot - Author: Erebus Team
2 # vim: fileencoding=utf-8
3 # !EVAL and !EXEC commands
4 # This file is released into the public domain; see http://unlicense.org/
8 'author' : 'Erebus Team' ,
9 'license' : 'public domain' ,
17 lib
= modlib
. modlib ( __name__
)
18 modstart
= lib
. modstart
29 @lib.hook ( 'eval' , needchan
= False , wantchan
= True , glevel
= lib
. OWNER
)
30 @lib.help ( "<python>" , "eval" )
32 def cmd_eval ( bot
, user
, chan
, realtarget
, * args
):
33 if chan
is not None : replyto
= chan
36 try : ret
= eval ( ' ' . join ( args
))
37 except Exception : bot
. msg ( replyto
, "Error: %s %s " % ( sys
. exc_info ()[ 0 ], sys
. exc_info ()[ 1 ]))
38 else : bot
. msg ( replyto
, "Done: %r " % ( ret
,))
41 @lib.hook ( 'exec' , needchan
= False , wantchan
= True , glevel
= lib
. OWNER
)
42 @lib.help ( "<python>" , "exec" )
44 def cmd_exec ( bot
, user
, chan
, realtarget
, * args
):
45 if chan
is not None : replyto
= chan
48 try : exec ( ' ' . join ( args
))
49 except Exception : bot
. msg ( replyto
, "Error: %s %s " % ( sys
. exc_info ()[ 0 ], sys
. exc_info ()[ 1 ]))
50 else : bot
. msg ( replyto
, "Done." )
52 @lib.hook ( 'exception' , needchan
= False , glevel
= lib
. OWNER
)
53 @lib.help ( None , "cause an exception" )
54 def cmd_exception (* args
, ** kwargs
):
57 @lib.hook ( needchan
= False , wantchan
= True , glevel
= lib
. ADMIN
)
58 @lib.help ( "<nick> <message>" , "inject a line as though it came from <nick>" , "note that this injects lines, not commands" , "ex: INJECT DimeCadmium !WHOAMI" )
59 def inject ( bot
, user
, chan
, realtarget
, * args
):
60 targetuser
= bot
. parent
. user ( args
[ 0 ], create
= False )
61 if targetuser
is None :
62 bot
. msg ( user
, "User is unknown." )
64 if targetuser
. glevel
> user
. glevel
:
65 bot
. msg ( user
, "That user has a higher access level than you." )
69 bot
. parsemsg ( bot
. parent
. user ( args
[ 0 ], create
= False ), str ( chan
), ' ' . join ( args
[ 1 :]))
71 bot
. parsemsg ( bot
. parent
. user ( args
[ 0 ], create
= False ), str ( bot
), ' ' . join ( args
[ 1 :]))