]> jfr.im git - erebus.git/blame - modules/eval.py
update version link to source
[erebus.git] / modules / eval.py
CommitLineData
9bd05cf6 1# Erebus IRC bot - Author: Erebus Team
4477123d 2# vim: fileencoding=utf-8
931c88a4 3# !EVAL and !EXEC commands
9bd05cf6 4# This file is released into the public domain; see http://unlicense.org/
931c88a4 5
e4255e70 6# module info
7modinfo = {
9bd05cf6 8 'author': 'Erebus Team',
e4255e70 9 'license': 'public domain',
fa93b933 10 'compatible': [0],
e4255e70 11 'depends': [],
a62d0d18 12 'softdeps': ['help'],
e4255e70 13}
14
db50981b 15# preamble
16import modlib
17lib = modlib.modlib(__name__)
18modstart = lib.modstart
19modstop = lib.modstop
20
e4255e70 21# module code
db50981b 22import sys
9557ee54 23import ctlmod
db50981b 24
132e8a0e 25
26def module(name):
43540339 27 return lib.mod(name)
132e8a0e 28
889eeb24 29@lib.hook('eval', needchan=False, wantchan=True, glevel=lib.OWNER)
5f03d045 30@lib.help("<python>", "eval")
d431e543 31@lib.argsGE(1)
861f83ef 32def cmd_eval(bot, user, chan, realtarget, *args):
f5aec865 33 if chan is not None: replyto = chan
839d2b35 34 else: replyto = user
35
db50981b 36 try: ret = eval(' '.join(args))
b79721ee 37 except Exception: bot.msg(replyto, "Error: %s %s" % (sys.exc_info()[0], sys.exc_info()[1]))
e5a24146 38 else: bot.msg(replyto, "Done: %r" % (ret,))
db50981b 39
40
889eeb24 41@lib.hook('exec', needchan=False, wantchan=True, glevel=lib.OWNER)
5f03d045 42@lib.help("<python>", "exec")
d431e543 43@lib.argsGE(1)
861f83ef 44def cmd_exec(bot, user, chan, realtarget, *args):
f5aec865 45 if chan is not None: replyto = chan
839d2b35 46 else: replyto = user
47
a28e2ae9 48 try: exec(' '.join(args))
b79721ee 49 except Exception: bot.msg(replyto, "Error: %s %s" % (sys.exc_info()[0], sys.exc_info()[1]))
839d2b35 50 else: bot.msg(replyto, "Done.")
f7628a8c 51
ea3cbbdc 52@lib.hook('exception', needchan=False, glevel=lib.OWNER)
5f03d045 53@lib.help(None, "cause an exception")
f7628a8c 54def cmd_exception(*args, **kwargs):
55 raise Exception()