]> jfr.im git - erebus.git/blame_incremental - modules/control.py
trivia - add last win to topic
[erebus.git] / modules / control.py
... / ...
CommitLineData
1# Erebus IRC bot - Author: Erebus Team
2# Various highly recommended "control" 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
24@lib.hook(needchan=False, glevel=lib.MANAGER)
25def die(bot, user, chan, realtarget, *args):
26 sys.exit(0)
27 os._exit(0)
28
29@lib.hook(needchan=False, glevel=lib.MANAGER)
30@lib.argsEQ(1)
31def modload(bot, user, chan, realtarget, *args):
32 okay = ctlmod.load(bot.parent, args[0])
33 if okay:
34 bot.msg(user, "Loaded %s" % (args[0]))
35 else:
36 bot.msg(user, "Error loading %s: %r" % (args[0], okay))
37
38@lib.hook(needchan=False, glevel=lib.MANAGER)
39@lib.argsEQ(1)
40def modunload(bot, user, chan, realtarget, *args):
41 okay = ctlmod.unload(bot.parent, args[0])
42 if okay:
43 bot.msg(user, "Unloaded %s" % (args[0]))
44 else:
45 bot.msg(user, "Error unloading %s: %r" % (args[0], okay))
46
47@lib.hook(needchan=False, glevel=lib.MANAGER)
48@lib.argsEQ(1)
49def modreload(bot, user, chan, realtarget, *args):
50 okay = ctlmod.reloadmod(bot.parent, args[0])
51 if okay:
52 bot.msg(user, "Reloaded %s" % (args[0]))
53 else:
54 bot.msg(user, "Error occurred: %r" % (okay))
55
56@lib.hook(needchan=False, glevel=lib.STAFF)
57@lib.argsEQ(0)
58def modlist(bot, user, chan, realtarget, *args):
59 mods = ctlmod.modules
60 for mod in mods.itervalues():
61 bot.msg(user, "- %s %r" % (mod.__name__, mod))
62 bot.msg(user, "Done.")
63
64@lib.hook(cmd='whoami', needchan=False)
65def whoami(bot, user, chan, realtarget, *args):
66 if not user.isauthed():
67 bot.msg(user, "You are not authed.")
68 return
69
70 fillers = {'auth': user.auth}
71 fmt = "You are %(auth)s"
72
73 if user.glevel >= 1:
74 fillers['glevel'] = user.glevel
75 fmt += " (global access: %(glevel)s)"
76 else:
77 fmt += " (not staff)"
78
79 if chan is not None and chan.levelof(user.auth) >= 1:
80 fillers['clevel'] = chan.levelof(user.auth)
81 fmt += " (channel access: %(clevel)s)"
82 else:
83 fmt += " (not a channel user)"
84 bot.msg(user, fmt % fillers)