]> jfr.im git - erebus.git/blob - modules/control.py
trivia - fix (bogus!) pylint errors
[erebus.git] / modules / control.py
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
6 modinfo = {
7 'author': 'Erebus Team',
8 'license': 'public domain',
9 'compatible': [1],
10 'depends': [],
11 }
12
13 # preamble
14 import modlib
15 lib = modlib.modlib(__name__)
16 modstart = lib.modstart
17 modstop = lib.modstop
18
19 # module code
20 import sys, os
21 import ctlmod
22 from collections import deque
23
24
25 @lib.hook(needchan=False, glevel=lib.MANAGER)
26 def die(bot, user, chan, realtarget, *args):
27 for botitem in bot.parent.bots.itervalues():
28 for chan in botitem.chans:
29 chan.fastmsg("Bot is restarting! %s" % ' '.join(args))
30 bot.conn.send("QUIT :Restarting.")
31 sys.exit(0)
32 os._exit(0)
33
34 @lib.hook(needchan=False, glevel=lib.MANAGER)
35 @lib.argsEQ(1)
36 def modload(bot, user, chan, realtarget, *args):
37 okay = ctlmod.load(bot.parent, args[0])
38 if okay:
39 bot.msg(user, "Loaded %s" % (args[0]))
40 else:
41 bot.msg(user, "Error loading %s: %r" % (args[0], okay))
42
43 @lib.hook(needchan=False, glevel=lib.MANAGER)
44 @lib.argsEQ(1)
45 def modunload(bot, user, chan, realtarget, *args):
46 okay = ctlmod.unload(bot.parent, args[0])
47 if okay:
48 bot.msg(user, "Unloaded %s" % (args[0]))
49 else:
50 bot.msg(user, "Error unloading %s: %r" % (args[0], okay))
51
52 @lib.hook(needchan=False, glevel=lib.MANAGER)
53 @lib.argsEQ(1)
54 def modreload(bot, user, chan, realtarget, *args):
55 okay = ctlmod.reloadmod(bot.parent, args[0])
56 if okay:
57 bot.msg(user, "Reloaded %s" % (args[0]))
58 else:
59 bot.msg(user, "Error occurred: %r" % (okay))
60
61 @lib.hook(needchan=False, glevel=lib.STAFF)
62 @lib.argsEQ(0)
63 def modlist(bot, user, chan, realtarget, *args):
64 mods = ctlmod.modules
65 for mod in mods.itervalues():
66 bot.msg(user, "- %s %r" % (mod.__name__, mod))
67 bot.msg(user, "Done.")
68
69 def _whois(user, chan, showglevel=True, showclevel=True):
70 if not user.isauthed():
71 return "not authed."
72
73 fillers = {'auth': user.auth}
74 fmt = "%(auth)s"
75
76 if showglevel and user.glevel >= 1:
77 fillers['glevel'] = user.glevel
78 fmt += " (global access: %(glevel)s)"
79 elif user.glevel >= 1:
80 fmt += " (staff)"
81 else:
82 fmt += " (not staff)"
83
84 if showclevel and chan is not None:
85 if chan.levelof(user.auth) >= 1:
86 fillers['clevel'] = chan.levelof(user.auth)
87 fmt += " (channel access: %(clevel)s)"
88 else:
89 fmt += " (not a channel user)"
90 return fmt % fillers
91
92 @lib.hook(needchan=False)
93 @lib.argsEQ(1)
94 def whois(bot, user, chan, realtarget, *args):
95 target = bot.parent.user(args[0], create=False)
96 if target is None:
97 bot.msg(user, "I don't know %s." % (args[0]))
98 else:
99 bot.msg(user, "%s is %s" % (args[0], _whois(target, chan, (user.glevel >= 1), (chan is not None and chan.levelof(user.auth) >= 1))))
100
101 @lib.hook(needchan=False)
102 def whoami(bot, user, chan, realtarget, *args):
103 bot.msg(user, "You are %s" % (_whois(user, chan)))
104
105 @lib.hook(needchan=False, glevel=1)
106 def qstat(bot, user, chan, realtarget, *args):
107 bot.fastmsg(user, "Regular: %d -- Slow: %d" % (len(bot.msgqueue), len(bot.slowmsgqueue)))
108
109 @lib.hook(needchan=False, glevel=lib.ADMIN)
110 def qclear(bot, user, chan, realtarget, *args):
111 if len(args) == 0:
112 bot.msgqueue = deque()
113 bot.slowmsgqueue = deque()
114 bot.fastmsg(user, "Cleared both msgqueues.")
115 else:
116 if args[0] == 'regular':
117 bot.msgqueue = deque()
118 elif args[0] == 'slow':
119 bot.slowmsgqueue = deque()
120 else:
121 bot.fastmsg(user, "Syntax: QCLEAR [regular|slow]")
122 return #short-circuit
123 bot.fastmsg(user, "Cleared that msgqueue.")