]>
Commit | Line | Data |
---|---|---|
1 | # Erebus IRC bot - Author: Erebus Team | |
2 | # !EVAL and !EXEC commands | |
3 | # This file is released into the public domain; see http://unlicense.org/ | |
4 | ||
5 | # module info | |
6 | modinfo = { | |
7 | 'author': 'Erebus Team', | |
8 | 'license': 'public domain', | |
9 | 'compatible': [1], | |
10 | 'depends': [], | |
11 | } | |
12 | ||
13 | # preamble | |
14 | import modlib | |
15 | lib = modlib.modlib(__name__) | |
16 | modstart = lib.modstart | |
17 | modstop = lib.modstop | |
18 | ||
19 | # module code | |
20 | import sys | |
21 | import ctlmod | |
22 | ||
23 | ||
24 | def module(name): | |
25 | return lib.mod(name) | |
26 | ||
27 | @lib.hook('eval', needchan=False, glevel=lib.MANAGER) | |
28 | @lib.help("<python>", "eval") | |
29 | @lib.argsGE(1) | |
30 | def cmd_eval(bot, user, chan, realtarget, *args): | |
31 | if chan is not None and realtarget == chan.name: replyto = chan | |
32 | else: replyto = user | |
33 | ||
34 | try: ret = eval(' '.join(args)) | |
35 | except Exception: bot.msg(replyto, "Error: %s %s" % (sys.exc_info()[0], sys.exc_info()[1])) | |
36 | else: bot.msg(replyto, "Done: %r" % (ret,)) | |
37 | ||
38 | ||
39 | @lib.hook('exec', needchan=False, glevel=lib.MANAGER) | |
40 | @lib.help("<python>", "exec") | |
41 | @lib.argsGE(1) | |
42 | def cmd_exec(bot, user, chan, realtarget, *args): | |
43 | if chan is not None and realtarget == chan.name: replyto = chan | |
44 | else: replyto = user | |
45 | ||
46 | try: exec ' '.join(args) | |
47 | except Exception: bot.msg(replyto, "Error: %s %s" % (sys.exc_info()[0], sys.exc_info()[1])) | |
48 | else: bot.msg(replyto, "Done.") | |
49 | ||
50 | @lib.hook('exception', needchan=False, glevel=lib.OWNER) | |
51 | @lib.help(None, "cause an exception") | |
52 | def cmd_exception(*args, **kwargs): | |
53 | raise Exception() |