]>
Commit | Line | Data |
---|---|---|
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(('die','restart'), needchan=False, glevel=lib.MANAGER) | |
26 | @lib.help(None, "stops the bot") | |
27 | def die(bot, user, chan, realtarget, *args): | |
28 | for botitem in bot.parent.bots.itervalues(): | |
29 | for chan in botitem.chans: | |
30 | chan.fastmsg("Bot is restarting! %s" % ' '.join(args)) | |
31 | bot.conn.send("QUIT :Restarting.") | |
32 | sys.exit(0) | |
33 | os._exit(0) | |
34 | ||
35 | @lib.hook(needchan=False, glevel=lib.MANAGER) | |
36 | @lib.help("<mod>", "loads a module") | |
37 | @lib.argsEQ(1) | |
38 | def modload(bot, user, chan, realtarget, *args): | |
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 | ||
45 | @lib.hook(needchan=False, glevel=lib.MANAGER) | |
46 | @lib.help("<mod>", "unloads a module") | |
47 | @lib.argsGE(1) | |
48 | def modunload(bot, user, chan, realtarget, *args): | |
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 | |
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 | ||
59 | @lib.hook(needchan=False, glevel=lib.MANAGER) | |
60 | @lib.help("<mod>", "reloads a module") | |
61 | @lib.argsEQ(1) | |
62 | def modreload(bot, user, chan, realtarget, *args): | |
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 | ||
69 | @lib.hook(needchan=False, glevel=lib.STAFF) | |
70 | @lib.help(None, "list loaded modules") | |
71 | @lib.argsEQ(0) | |
72 | def modlist(bot, user, chan, realtarget, *args): | |
73 | mods = ctlmod.modules | |
74 | for modname, mod in mods.iteritems(): | |
75 | bot.msg(user, "- %s (%s) [%s]" % ((modname, mod.__file__, ', '.join(ctlmod.dependents[modname])))) | |
76 | bot.msg(user, "Done.") | |
77 | ||
78 | def _whois(user, chan, showglevel=True, showclevel=True): | |
79 | if not user.isauthed(): | |
80 | return "not authed." | |
81 | ||
82 | fillers = {'auth': user.auth} | |
83 | fmt = "%(auth)s" | |
84 | ||
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)" | |
90 | else: | |
91 | fmt += " (not staff)" | |
92 | ||
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 | ||
101 | @lib.hook(needchan=False) | |
102 | @lib.help("<user>", "shows who someone is") | |
103 | @lib.argsEQ(1) | |
104 | def whois(bot, user, chan, realtarget, *args): | |
105 | target = bot.parent.user(args[0], create=False) | |
106 | if target is None: | |
107 | bot.msg(user, "I don't know %s." % (args[0])) | |
108 | else: | |
109 | bot.msg(user, "%s is %s" % (args[0], _whois(target, chan, (user.glevel >= 1), (chan is not None and chan.levelof(user.auth) >= 1)))) | |
110 | ||
111 | @lib.hook(needchan=False) | |
112 | @lib.help(None, "shows who you are") | |
113 | def whoami(bot, user, chan, realtarget, *args): | |
114 | bot.msg(user, "You are %s" % (_whois(user, chan))) | |
115 | ||
116 | @lib.hook(needchan=False) | |
117 | @lib.help(None, "tries to read your auth and access level again") | |
118 | def auth(bot, user, chan, realtarget, *args): | |
119 | bot.msg(user, "Okay, give me a second.") | |
120 | bot.conn.send("WHO %s n%%ant,2" % (user)) | |
121 | ||
122 | @lib.hook(needchan=False, glevel=1) | |
123 | @lib.help(None, "displays length of each msgqueue") | |
124 | def qstat(bot, user, chan, realtarget, *args): | |
125 | bot.fastmsg(user, "Regular: %d -- Slow: %d" % (len(bot.msgqueue), len(bot.slowmsgqueue))) | |
126 | ||
127 | @lib.hook(needchan=False, glevel=lib.ADMIN) | |
128 | @lib.help("[regular|slow]", "clears both or a specific msgqueue") | |
129 | def qclear(bot, user, chan, realtarget, *args): | |
130 | if len(args) == 0: | |
131 | bot.msgqueue = deque() | |
132 | bot.slowmsgqueue = deque() | |
133 | bot.fastmsg(user, "Cleared both msgqueues.") | |
134 | else: | |
135 | if args[0] == 'regular': | |
136 | bot.msgqueue = deque() | |
137 | elif args[0] == 'slow': | |
138 | bot.slowmsgqueue = deque() | |
139 | else: | |
140 | bot.fastmsg(user, "Syntax: QCLEAR [regular|slow]") | |
141 | return #short-circuit | |
142 | bot.fastmsg(user, "Cleared that msgqueue.") |