]>
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', | |
fa93b933 | 9 | 'compatible': [0], |
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): |
889eeb24 | 29 | quitmsg = ' '.join(args) |
a28e2ae9 | 30 | for botitem in bot.parent.bots.values(): |
889eeb24 | 31 | bot.conn.send("QUIT :Restarting. %s" % (quitmsg)) |
e2b30093 | 32 | sys.exit(0) |
33 | os._exit(0) | |
4df64299 | 34 | |
fb20be7c | 35 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
5f03d045 | 36 | @lib.help("<mod>", "loads a module") |
4df64299 | 37 | @lib.argsEQ(1) |
fb20be7c | 38 | def modload(bot, user, chan, realtarget, *args): |
4df64299 | 39 | okay = ctlmod.load(bot.parent, args[0]) |
40 | if okay: | |
41 | bot.msg(user, "Loaded %s" % (args[0])) | |
42 | else: | |
43 | bot.msg(user, "Error loading %s: %r" % (args[0], okay)) | |
44 | ||
fb20be7c | 45 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
d3417a2c | 46 | @lib.help("<mod> [FORCE]", "unloads a module", "will refuse to unload a module which is depended on by others", "unless you specify FORCE.") |
b0910717 | 47 | @lib.argsGE(1) |
fb20be7c | 48 | def modunload(bot, user, chan, realtarget, *args): |
b0910717 | 49 | if len(ctlmod.dependents[args[0]]) > 0: |
50 | if len(args) == 1 or args[1].lower() != "force": | |
51 | bot.msg(user, "That module has dependents! Say MODUNLOAD %s FORCE to unload it and any dependents." % (args[0])) | |
52 | return | |
4df64299 | 53 | okay = ctlmod.unload(bot.parent, args[0]) |
54 | if okay: | |
55 | bot.msg(user, "Unloaded %s" % (args[0])) | |
56 | else: | |
57 | bot.msg(user, "Error unloading %s: %r" % (args[0], okay)) | |
58 | ||
fb20be7c | 59 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
5f03d045 | 60 | @lib.help("<mod>", "reloads a module") |
4df64299 | 61 | @lib.argsEQ(1) |
fb20be7c | 62 | def modreload(bot, user, chan, realtarget, *args): |
4df64299 | 63 | okay = ctlmod.reloadmod(bot.parent, args[0]) |
64 | if okay: | |
65 | bot.msg(user, "Reloaded %s" % (args[0])) | |
66 | else: | |
67 | bot.msg(user, "Error occurred: %r" % (okay)) | |
68 | ||
fb20be7c | 69 | @lib.hook(needchan=False, glevel=lib.STAFF) |
5f03d045 | 70 | @lib.help(None, "list loaded modules") |
4df64299 | 71 | @lib.argsEQ(0) |
fb20be7c | 72 | def modlist(bot, user, chan, realtarget, *args): |
4df64299 | 73 | mods = ctlmod.modules |
a28e2ae9 | 74 | for modname, mod in mods.items(): |
53fff692 | 75 | bot.msg(user, "- %s (%s) [%s]" % ((modname, mod.__file__, ', '.join(ctlmod.dependents[modname])))) |
4df64299 | 76 | bot.msg(user, "Done.") |
fb20be7c | 77 | |
72e5bb4e | 78 | def _whois(user, chan, showglevel=True, showclevel=True): |
fb20be7c | 79 | if not user.isauthed(): |
72e5bb4e | 80 | return "not authed." |
fb20be7c | 81 | |
82 | fillers = {'auth': user.auth} | |
72e5bb4e | 83 | fmt = "%(auth)s" |
fb20be7c | 84 | |
72e5bb4e | 85 | if showglevel and user.glevel >= 1: |
86 | fillers['glevel'] = user.glevel | |
87 | fmt += " (global access: %(glevel)s)" | |
88 | elif user.glevel >= 1: | |
89 | fmt += " (staff)" | |
fb20be7c | 90 | else: |
91 | fmt += " (not staff)" | |
92 | ||
72e5bb4e | 93 | if showclevel and chan is not None: |
94 | if chan.levelof(user.auth) >= 1: | |
95 | fillers['clevel'] = chan.levelof(user.auth) | |
96 | fmt += " (channel access: %(clevel)s)" | |
97 | else: | |
98 | fmt += " (not a channel user)" | |
99 | return fmt % fillers | |
100 | ||
827ec8f0 | 101 | @lib.hook(needchan=False, wantchan=True) |
b4e3e62e | 102 | @lib.help("<user|#auth>", "shows who someone is") |
72e5bb4e | 103 | @lib.argsEQ(1) |
104 | def whois(bot, user, chan, realtarget, *args): | |
3fb492b9 | 105 | name = args[0] |
106 | if name.startswith("#"): | |
107 | target = bot.parent.User(name, name[1:]) | |
108 | else: | |
109 | target = bot.parent.user(name, create=False) | |
72e5bb4e | 110 | if target is None: |
111 | bot.msg(user, "I don't know %s." % (args[0])) | |
fb20be7c | 112 | else: |
72e5bb4e | 113 | bot.msg(user, "%s is %s" % (args[0], _whois(target, chan, (user.glevel >= 1), (chan is not None and chan.levelof(user.auth) >= 1)))) |
114 | ||
363febf1 | 115 | @lib.hook(needchan=False, wantchan=True) |
5f03d045 | 116 | @lib.help(None, "shows who you are") |
72e5bb4e | 117 | def whoami(bot, user, chan, realtarget, *args): |
118 | bot.msg(user, "You are %s" % (_whois(user, chan))) | |
32a54ded | 119 | |
b319b837 | 120 | @lib.hook(needchan=False) |
121 | @lib.help(None, "tries to read your auth and access level again") | |
122 | def auth(bot, user, chan, realtarget, *args): | |
123 | bot.msg(user, "Okay, give me a second.") | |
124 | bot.conn.send("WHO %s n%%ant,2" % (user)) | |
125 | ||
32a54ded | 126 | @lib.hook(needchan=False, glevel=1) |
5f03d045 | 127 | @lib.help(None, "displays length of each msgqueue") |
32a54ded | 128 | def qstat(bot, user, chan, realtarget, *args): |
129 | bot.fastmsg(user, "Regular: %d -- Slow: %d" % (len(bot.msgqueue), len(bot.slowmsgqueue))) | |
130 | ||
e6b60193 | 131 | @lib.hook(('qclear','clearq','clearqueue'), needchan=False, glevel=lib.ADMIN) |
132 | @lib.help("[regular|slow]", "clears both or a specific msgqueue") | |
32a54ded | 133 | def qclear(bot, user, chan, realtarget, *args): |
134 | if len(args) == 0: | |
135 | bot.msgqueue = deque() | |
136 | bot.slowmsgqueue = deque() | |
137 | bot.fastmsg(user, "Cleared both msgqueues.") | |
138 | else: | |
139 | if args[0] == 'regular': | |
140 | bot.msgqueue = deque() | |
141 | elif args[0] == 'slow': | |
142 | bot.slowmsgqueue = deque() | |
143 | else: | |
144 | bot.fastmsg(user, "Syntax: QCLEAR [regular|slow]") | |
145 | return #short-circuit | |
146 | bot.fastmsg(user, "Cleared that msgqueue.") | |
193806d5 | 147 | |
148 | @lib.hook(needchan=False, wantchan=True, glevel=lib.ADMIN) | |
149 | @lib.help("<nick> <message>", "inject a line as though it came from <nick>", "note that this injects lines, not commands", "ex: INJECT DimeCadmium !WHOAMI") | |
150 | def inject(bot, user, chan, realtarget, *args): | |
151 | targetuser = bot.parent.user(args[0], create=False) | |
152 | if targetuser is None: | |
153 | bot.msg(user, "User is unknown.") | |
154 | return | |
155 | if targetuser.glevel > user.glevel: | |
156 | bot.msg(user, "That user has a higher access level than you.") | |
157 | return | |
158 | ||
159 | if chan is not None: | |
160 | bot.parsemsg(bot.parent.user(args[0], create=False), str(chan), ' '.join(args[1:])) | |
161 | else: | |
162 | bot.parsemsg(bot.parent.user(args[0], create=False), str(bot), ' '.join(args[1:])) |