]> jfr.im git - erebus.git/blame_incremental - modules/eval.py
msg 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,2],
10 'depends': [],
11 'softdeps': ['help'],
12}
13
14# preamble
15import modlib
16lib = modlib.modlib(__name__)
17modstart = lib.modstart
18modstop = lib.modstop
19
20# module code
21import sys
22import ctlmod
23
24
25def module(name):
26 return lib.mod(name)
27
28@lib.hook('eval', needchan=False, glevel=lib.MANAGER)
29@lib.help("<python>", "eval")
30@lib.argsGE(1)
31def cmd_eval(bot, user, chan, realtarget, *args):
32 if chan is not None and realtarget == chan.name: replyto = chan
33 else: replyto = user
34
35 try: ret = eval(' '.join(args))
36 except Exception: bot.msg(replyto, "Error: %s %s" % (sys.exc_info()[0], sys.exc_info()[1]))
37 else: bot.msg(replyto, "Done: %r" % (ret,))
38
39
40@lib.hook('exec', needchan=False, glevel=lib.MANAGER)
41@lib.help("<python>", "exec")
42@lib.argsGE(1)
43def cmd_exec(bot, user, chan, realtarget, *args):
44 if chan is not None and realtarget == chan.name: replyto = chan
45 else: replyto = user
46
47 try: exec ' '.join(args)
48 except Exception: bot.msg(replyto, "Error: %s %s" % (sys.exc_info()[0], sys.exc_info()[1]))
49 else: bot.msg(replyto, "Done.")
50
51@lib.hook('exception', needchan=False, glevel=lib.OWNER)
52@lib.help(None, "cause an exception")
53def cmd_exception(*args, **kwargs):
54 raise Exception()