]> jfr.im git - erebus.git/blame_incremental - modules/eval.py
control - adjust formatting of dependent list
[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
21import ctlmod
22
23
24def 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)
30def 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)
42def 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', glevel=lib.OWNER)
51@lib.help(None, "cause an exception")
52def cmd_exception(*args, **kwargs):
53 raise Exception()