]>
Commit | Line | Data |
---|---|---|
e2b30093 | 1 | # Erebus IRC bot - Author: Erebus Team |
4df64299 | 2 | # Various highly recommended "control" commands. |
e2b30093 | 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', | |
a62d0d18 | 9 | 'compatible': [1,2], |
e2b30093 | 10 | 'depends': [], |
a62d0d18 | 11 | 'softdeps': ['help'], |
e2b30093 | 12 | } |
13 | ||
14 | # preamble | |
15 | import modlib | |
16 | lib = modlib.modlib(__name__) | |
17 | modstart = lib.modstart | |
18 | modstop = lib.modstop | |
19 | ||
20 | # module code | |
d371d194 | 21 | import sys, os |
e2b30093 | 22 | import ctlmod |
32a54ded | 23 | from collections import deque |
e2b30093 | 24 | |
25 | ||
f7725bee | 26 | @lib.hook(('die','restart'), needchan=False, glevel=lib.MANAGER) |
5f03d045 | 27 | @lib.help(None, "stops the bot") |
fb20be7c | 28 | def die(bot, user, chan, realtarget, *args): |
574ce192 | 29 | for botitem in bot.parent.bots.itervalues(): |
30 | for chan in botitem.chans: | |
31 | chan.fastmsg("Bot is restarting! %s" % ' '.join(args)) | |
32 | bot.conn.send("QUIT :Restarting.") | |
e2b30093 | 33 | sys.exit(0) |
34 | os._exit(0) | |
4df64299 | 35 | |
fb20be7c | 36 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
5f03d045 | 37 | @lib.help("<mod>", "loads a module") |
4df64299 | 38 | @lib.argsEQ(1) |
fb20be7c | 39 | def modload(bot, user, chan, realtarget, *args): |
4df64299 | 40 | okay = ctlmod.load(bot.parent, args[0]) |
41 | if okay: | |
42 | bot.msg(user, "Loaded %s" % (args[0])) | |
43 | else: | |
44 | bot.msg(user, "Error loading %s: %r" % (args[0], okay)) | |
45 | ||
fb20be7c | 46 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
d3417a2c | 47 | @lib.help("<mod> [FORCE]", "unloads a module", "will refuse to unload a module which is depended on by others", "unless you specify FORCE.") |
b0910717 | 48 | @lib.argsGE(1) |
fb20be7c | 49 | def modunload(bot, user, chan, realtarget, *args): |
b0910717 | 50 | if len(ctlmod.dependents[args[0]]) > 0: |
51 | if len(args) == 1 or args[1].lower() != "force": | |
52 | bot.msg(user, "That module has dependents! Say MODUNLOAD %s FORCE to unload it and any dependents." % (args[0])) | |
53 | return | |
4df64299 | 54 | okay = ctlmod.unload(bot.parent, args[0]) |
55 | if okay: | |
56 | bot.msg(user, "Unloaded %s" % (args[0])) | |
57 | else: | |
58 | bot.msg(user, "Error unloading %s: %r" % (args[0], okay)) | |
59 | ||
fb20be7c | 60 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
5f03d045 | 61 | @lib.help("<mod>", "reloads a module") |
4df64299 | 62 | @lib.argsEQ(1) |
fb20be7c | 63 | def modreload(bot, user, chan, realtarget, *args): |
4df64299 | 64 | okay = ctlmod.reloadmod(bot.parent, args[0]) |
65 | if okay: | |
66 | bot.msg(user, "Reloaded %s" % (args[0])) | |
67 | else: | |
68 | bot.msg(user, "Error occurred: %r" % (okay)) | |
69 | ||
fb20be7c | 70 | @lib.hook(needchan=False, glevel=lib.STAFF) |
5f03d045 | 71 | @lib.help(None, "list loaded modules") |
4df64299 | 72 | @lib.argsEQ(0) |
fb20be7c | 73 | def modlist(bot, user, chan, realtarget, *args): |
4df64299 | 74 | mods = ctlmod.modules |
b0910717 | 75 | for modname, mod in mods.iteritems(): |
53fff692 | 76 | bot.msg(user, "- %s (%s) [%s]" % ((modname, mod.__file__, ', '.join(ctlmod.dependents[modname])))) |
4df64299 | 77 | bot.msg(user, "Done.") |
fb20be7c | 78 | |
72e5bb4e | 79 | def _whois(user, chan, showglevel=True, showclevel=True): |
fb20be7c | 80 | if not user.isauthed(): |
72e5bb4e | 81 | return "not authed." |
fb20be7c | 82 | |
83 | fillers = {'auth': user.auth} | |
72e5bb4e | 84 | fmt = "%(auth)s" |
fb20be7c | 85 | |
72e5bb4e | 86 | if showglevel and user.glevel >= 1: |
87 | fillers['glevel'] = user.glevel | |
88 | fmt += " (global access: %(glevel)s)" | |
89 | elif user.glevel >= 1: | |
90 | fmt += " (staff)" | |
fb20be7c | 91 | else: |
92 | fmt += " (not staff)" | |
93 | ||
72e5bb4e | 94 | if showclevel and chan is not None: |
95 | if chan.levelof(user.auth) >= 1: | |
96 | fillers['clevel'] = chan.levelof(user.auth) | |
97 | fmt += " (channel access: %(clevel)s)" | |
98 | else: | |
99 | fmt += " (not a channel user)" | |
100 | return fmt % fillers | |
101 | ||
102 | @lib.hook(needchan=False) | |
5f03d045 | 103 | @lib.help("<user>", "shows who someone is") |
72e5bb4e | 104 | @lib.argsEQ(1) |
105 | def whois(bot, user, chan, realtarget, *args): | |
106 | target = bot.parent.user(args[0], create=False) | |
107 | if target is None: | |
108 | bot.msg(user, "I don't know %s." % (args[0])) | |
fb20be7c | 109 | else: |
72e5bb4e | 110 | bot.msg(user, "%s is %s" % (args[0], _whois(target, chan, (user.glevel >= 1), (chan is not None and chan.levelof(user.auth) >= 1)))) |
111 | ||
112 | @lib.hook(needchan=False) | |
5f03d045 | 113 | @lib.help(None, "shows who you are") |
72e5bb4e | 114 | def whoami(bot, user, chan, realtarget, *args): |
115 | bot.msg(user, "You are %s" % (_whois(user, chan))) | |
32a54ded | 116 | |
b319b837 | 117 | @lib.hook(needchan=False) |
118 | @lib.help(None, "tries to read your auth and access level again") | |
119 | def auth(bot, user, chan, realtarget, *args): | |
120 | bot.msg(user, "Okay, give me a second.") | |
121 | bot.conn.send("WHO %s n%%ant,2" % (user)) | |
122 | ||
32a54ded | 123 | @lib.hook(needchan=False, glevel=1) |
5f03d045 | 124 | @lib.help(None, "displays length of each msgqueue") |
32a54ded | 125 | def qstat(bot, user, chan, realtarget, *args): |
126 | bot.fastmsg(user, "Regular: %d -- Slow: %d" % (len(bot.msgqueue), len(bot.slowmsgqueue))) | |
127 | ||
128 | @lib.hook(needchan=False, glevel=lib.ADMIN) | |
5f03d045 | 129 | @lib.help("[regular|slow]", "clears both or a specific msgqueue") |
32a54ded | 130 | def qclear(bot, user, chan, realtarget, *args): |
131 | if len(args) == 0: | |
132 | bot.msgqueue = deque() | |
133 | bot.slowmsgqueue = deque() | |
134 | bot.fastmsg(user, "Cleared both msgqueues.") | |
135 | else: | |
136 | if args[0] == 'regular': | |
137 | bot.msgqueue = deque() | |
138 | elif args[0] == 'slow': | |
139 | bot.slowmsgqueue = deque() | |
140 | else: | |
141 | bot.fastmsg(user, "Syntax: QCLEAR [regular|slow]") | |
142 | return #short-circuit | |
143 | bot.fastmsg(user, "Cleared that msgqueue.") |