]> jfr.im git - erebus.git/blame_incremental - modules/control.py
userinfo - create json file if it doesnt exist
[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 for botitem in bot.parent.bots.itervalues():
27 for chan in botitem.chans:
28 chan.fastmsg("Bot is restarting! %s" % ' '.join(args))
29 bot.conn.send("QUIT :Restarting.")
30 sys.exit(0)
31 os._exit(0)
32
33@lib.hook(needchan=False, glevel=lib.MANAGER)
34@lib.argsEQ(1)
35def modload(bot, user, chan, realtarget, *args):
36 okay = ctlmod.load(bot.parent, args[0])
37 if okay:
38 bot.msg(user, "Loaded %s" % (args[0]))
39 else:
40 bot.msg(user, "Error loading %s: %r" % (args[0], okay))
41
42@lib.hook(needchan=False, glevel=lib.MANAGER)
43@lib.argsEQ(1)
44def modunload(bot, user, chan, realtarget, *args):
45 okay = ctlmod.unload(bot.parent, args[0])
46 if okay:
47 bot.msg(user, "Unloaded %s" % (args[0]))
48 else:
49 bot.msg(user, "Error unloading %s: %r" % (args[0], okay))
50
51@lib.hook(needchan=False, glevel=lib.MANAGER)
52@lib.argsEQ(1)
53def modreload(bot, user, chan, realtarget, *args):
54 okay = ctlmod.reloadmod(bot.parent, args[0])
55 if okay:
56 bot.msg(user, "Reloaded %s" % (args[0]))
57 else:
58 bot.msg(user, "Error occurred: %r" % (okay))
59
60@lib.hook(needchan=False, glevel=lib.STAFF)
61@lib.argsEQ(0)
62def modlist(bot, user, chan, realtarget, *args):
63 mods = ctlmod.modules
64 for mod in mods.itervalues():
65 bot.msg(user, "- %s %r" % (mod.__name__, mod))
66 bot.msg(user, "Done.")
67
68@lib.hook(cmd='whoami', needchan=False)
69def whoami(bot, user, chan, realtarget, *args):
70 if not user.isauthed():
71 bot.msg(user, "You are not authed.")
72 return
73
74 fillers = {'auth': user.auth}
75 fmt = "You are %(auth)s"
76
77 if user.glevel >= 1:
78 fillers['glevel'] = user.glevel
79 fmt += " (global access: %(glevel)s)"
80 else:
81 fmt += " (not staff)"
82
83 if chan is not None and chan.levelof(user.auth) >= 1:
84 fillers['clevel'] = chan.levelof(user.auth)
85 fmt += " (channel access: %(clevel)s)"
86 else:
87 fmt += " (not a channel user)"
88 bot.msg(user, fmt % fillers)