]>
Commit | Line | Data |
---|---|---|
e2b30093 | 1 | # Erebus IRC bot - Author: Erebus Team |
4477123d | 2 | # vim: fileencoding=utf-8 |
4df64299 | 3 | # Various highly recommended "control" commands. |
e2b30093 | 4 | # This file is released into the public domain; see http://unlicense.org/ |
5 | ||
6 | # module info | |
7 | modinfo = { | |
8 | 'author': 'Erebus Team', | |
9 | 'license': 'public domain', | |
fa93b933 | 10 | 'compatible': [0], |
e2b30093 | 11 | 'depends': [], |
a62d0d18 | 12 | 'softdeps': ['help'], |
e2b30093 | 13 | } |
14 | ||
15 | # preamble | |
16 | import modlib | |
17 | lib = modlib.modlib(__name__) | |
18 | modstart = lib.modstart | |
19 | modstop = lib.modstop | |
20 | ||
21 | # module code | |
d371d194 | 22 | import sys, os |
e2b30093 | 23 | import ctlmod |
32a54ded | 24 | from collections import deque |
e2b30093 | 25 | |
26 | ||
a18867fd | 27 | @lib.hook(('die','restart','exit'), needchan=False, glevel=lib.MANAGER) |
5f03d045 | 28 | @lib.help(None, "stops the bot") |
fb20be7c | 29 | def die(bot, user, chan, realtarget, *args): |
889eeb24 | 30 | quitmsg = ' '.join(args) |
a28e2ae9 | 31 | for botitem in bot.parent.bots.values(): |
889eeb24 | 32 | bot.conn.send("QUIT :Restarting. %s" % (quitmsg)) |
e2b30093 | 33 | sys.exit(0) |
4df64299 | 34 | |
fb20be7c | 35 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
de66fe6d | 36 | @lib.help("[-autoload] <mod>", "loads a module, optionally marking it for autoloading") |
1a22718c JR |
37 | @lib.flags('autoload') |
38 | @lib.argsEQ(1) | |
39 | def modload(bot, user, chan, realtarget, flags, *args): | |
40 | autoload = flags['autoload'] | |
41 | module = args[0] | |
de66fe6d JR |
42 | |
43 | if autoload: | |
44 | bot.parent.cfg.set('autoloads', module, 1) | |
45 | bot.msg(user, "Marked %s for autoloading." % (module)) | |
46 | okay = ctlmod.load(bot.parent, module) | |
4df64299 | 47 | if okay: |
de66fe6d | 48 | bot.msg(user, "Loaded %s" % (module)) |
4df64299 | 49 | else: |
de66fe6d | 50 | bot.msg(user, "Error loading %s: %r" % (module, okay)) |
4df64299 | 51 | |
fb20be7c | 52 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
de66fe6d | 53 | @lib.help("[-force] [-autoload] <mod>", "unloads a module", "will refuse to unload a module which is depended on by others unless you specify FORCE.", "optionally removes from autoloads") |
1a22718c JR |
54 | @lib.flags('force','autoload') |
55 | @lib.argsEQ(1) | |
56 | def modunload(bot, user, chan, realtarget, flags, *args): | |
57 | autoload = flags['autoload'] | |
58 | force = flags['force'] | |
59 | module = args[0] | |
de66fe6d JR |
60 | |
61 | if autoload: | |
62 | bot.parent.cfg.delete('autoloads', module) | |
63 | bot.msg(user, "Unmarked %s for autoloading." % (module)) | |
64 | if not ctlmod.isloaded(module): | |
65 | bot.msg(user, "%s is not loaded" % (module)) | |
68dff4aa | 66 | return |
de66fe6d JR |
67 | if len(ctlmod.dependents[module]) > 0: |
68 | if not force: | |
c07e4b02 | 69 | bot.msg(user, "That module has dependents! Say MODUNLOAD -force %s to unload it and any dependents." % (module)) |
b0910717 | 70 | return |
68dff4aa | 71 | |
de66fe6d | 72 | okay = ctlmod.unload(bot.parent, module) |
4df64299 | 73 | if okay: |
de66fe6d | 74 | bot.msg(user, "Unloaded %s" % (module)) |
4df64299 | 75 | else: |
de66fe6d | 76 | bot.msg(user, "Error unloading %s: %r" % (module, okay)) |
4df64299 | 77 | |
fb20be7c | 78 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
5f03d045 | 79 | @lib.help("<mod>", "reloads a module") |
4df64299 | 80 | @lib.argsEQ(1) |
fb20be7c | 81 | def modreload(bot, user, chan, realtarget, *args): |
68dff4aa JR |
82 | if not ctlmod.isloaded(args[0]): |
83 | bot.msg(user, "%s is not loaded" % (args[0])) | |
84 | return | |
85 | ||
4df64299 | 86 | okay = ctlmod.reloadmod(bot.parent, args[0]) |
87 | if okay: | |
88 | bot.msg(user, "Reloaded %s" % (args[0])) | |
89 | else: | |
90 | bot.msg(user, "Error occurred: %r" % (okay)) | |
91 | ||
fb20be7c | 92 | @lib.hook(needchan=False, glevel=lib.STAFF) |
5f03d045 | 93 | @lib.help(None, "list loaded modules") |
4df64299 | 94 | @lib.argsEQ(0) |
fb20be7c | 95 | def modlist(bot, user, chan, realtarget, *args): |
4df64299 | 96 | mods = ctlmod.modules |
958b8081 | 97 | for modname, mod in sorted(mods.items()): |
53fff692 | 98 | bot.msg(user, "- %s (%s) [%s]" % ((modname, mod.__file__, ', '.join(ctlmod.dependents[modname])))) |
4df64299 | 99 | bot.msg(user, "Done.") |
fb20be7c | 100 | |
72e5bb4e | 101 | def _whois(user, chan, showglevel=True, showclevel=True): |
fb20be7c | 102 | if not user.isauthed(): |
72e5bb4e | 103 | return "not authed." |
fb20be7c | 104 | |
105 | fillers = {'auth': user.auth} | |
72e5bb4e | 106 | fmt = "%(auth)s" |
fb20be7c | 107 | |
72e5bb4e | 108 | if showglevel and user.glevel >= 1: |
44aea37b JR |
109 | fillers['glevel'] = user.glevel |
110 | fmt += " (global access: %(glevel)s)" | |
72e5bb4e | 111 | elif user.glevel >= 1: |
112 | fmt += " (staff)" | |
44aea37b JR |
113 | elif user.glevel <= -2: |
114 | fmt += " (ignored)" | |
fb20be7c | 115 | else: |
116 | fmt += " (not staff)" | |
117 | ||
905f5930 | 118 | if (showclevel or showglevel) and chan is not None: |
68dff4aa JR |
119 | clev = chan.levelof(user.auth) |
120 | if clev >= 1: | |
121 | fillers['clevel'] = (lib.clevs[clev] if clev < len(lib.clevs) else clev) | |
72e5bb4e | 122 | fmt += " (channel access: %(clevel)s)" |
123 | else: | |
124 | fmt += " (not a channel user)" | |
125 | return fmt % fillers | |
126 | ||
827ec8f0 | 127 | @lib.hook(needchan=False, wantchan=True) |
b4e3e62e | 128 | @lib.help("<user|#auth>", "shows who someone is") |
72e5bb4e | 129 | @lib.argsEQ(1) |
130 | def whois(bot, user, chan, realtarget, *args): | |
3fb492b9 | 131 | name = args[0] |
132 | if name.startswith("#"): | |
133 | target = bot.parent.User(name, name[1:]) | |
134 | else: | |
135 | target = bot.parent.user(name, create=False) | |
72e5bb4e | 136 | if target is None: |
a5e7905a | 137 | return "I don't know %s." % (args[0]) |
fb20be7c | 138 | else: |
a5e7905a | 139 | return "%s is %s" % (args[0], _whois(target, chan, (user.glevel >= 1), (chan is not None and chan.levelof(user.auth) >= 1))) |
72e5bb4e | 140 | |
363febf1 | 141 | @lib.hook(needchan=False, wantchan=True) |
5f03d045 | 142 | @lib.help(None, "shows who you are") |
72e5bb4e | 143 | def whoami(bot, user, chan, realtarget, *args): |
a5e7905a | 144 | return "You are %s" % (_whois(user, chan)) |
32a54ded | 145 | |
b319b837 | 146 | @lib.hook(needchan=False) |
147 | @lib.help(None, "tries to read your auth and access level again") | |
148 | def auth(bot, user, chan, realtarget, *args): | |
149 | bot.msg(user, "Okay, give me a second.") | |
150 | bot.conn.send("WHO %s n%%ant,2" % (user)) | |
151 | ||
32a54ded | 152 | @lib.hook(needchan=False, glevel=1) |
5f03d045 | 153 | @lib.help(None, "displays length of each msgqueue") |
32a54ded | 154 | def qstat(bot, user, chan, realtarget, *args): |
155 | bot.fastmsg(user, "Regular: %d -- Slow: %d" % (len(bot.msgqueue), len(bot.slowmsgqueue))) | |
156 | ||
74feb80e | 157 | @lib.hook(('qclear','cq','clearq','clearqueue'), needchan=False, glevel=lib.ADMIN) |
e6b60193 | 158 | @lib.help("[regular|slow]", "clears both or a specific msgqueue") |
32a54ded | 159 | def qclear(bot, user, chan, realtarget, *args): |
160 | if len(args) == 0: | |
161 | bot.msgqueue = deque() | |
162 | bot.slowmsgqueue = deque() | |
163 | bot.fastmsg(user, "Cleared both msgqueues.") | |
164 | else: | |
165 | if args[0] == 'regular': | |
166 | bot.msgqueue = deque() | |
167 | elif args[0] == 'slow': | |
168 | bot.slowmsgqueue = deque() | |
169 | else: | |
170 | bot.fastmsg(user, "Syntax: QCLEAR [regular|slow]") | |
171 | return #short-circuit | |
172 | bot.fastmsg(user, "Cleared that msgqueue.") |