]> jfr.im git - erebus.git/blame_incremental - modules/eval.py
beginning to write a trivia-bot module.
[erebus.git] / modules / eval.py
... / ...
CommitLineData
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
6modinfo = {
7 'author': 'Erebus Team',
8 'license': 'public domain',
9 'compatible': [1],
10 'depends': [],
11}
12
13# preamble
14import modlib
15lib = modlib.modlib(__name__)
16modstart = lib.modstart
17modstop = lib.modstop
18
19# module code
20import sys
21
22@lib.hook('eval', needchan=False, glevel=lib.MANAGER)
23@lib.argsGE(1)
24def cmd_eval(bot, user, chan, realtarget, *args):
25 if chan is not None: replyto = chan
26 else: replyto = user
27
28 try: ret = eval(' '.join(args))
29 except SystemExit: raise
30 except: bot.msg(replyto, "Error (%s): %s" % (sys.exc_info()[0], sys.exc_info()[1]))
31 else: bot.msg(replyto, "Done: %r" % (ret))
32
33
34@lib.hook('exec', needchan=False, glevel=lib.MANAGER)
35@lib.argsGE(1)
36def cmd_exec(bot, user, chan, realtarget, *args):
37 if chan is not None: replyto = chan
38 else: replyto = user
39
40 try: exec ' '.join(args)
41 except SystemExit: raise
42 except: bot.msg(replyto, "Error: %s %s" % (sys.exc_info()[0], sys.exc_info()[1]))
43 else: bot.msg(replyto, "Done.")