]>
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', | |
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 | |
d371d194 | 20 | import sys, os |
e2b30093 | 21 | import ctlmod |
32a54ded | 22 | from collections import deque |
e2b30093 | 23 | |
24 | ||
fb20be7c | 25 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
26 | def die(bot, user, chan, realtarget, *args): | |
574ce192 | 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.") | |
e2b30093 | 31 | sys.exit(0) |
32 | os._exit(0) | |
4df64299 | 33 | |
fb20be7c | 34 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
4df64299 | 35 | @lib.argsEQ(1) |
fb20be7c | 36 | def modload(bot, user, chan, realtarget, *args): |
4df64299 | 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 | ||
fb20be7c | 43 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
4df64299 | 44 | @lib.argsEQ(1) |
fb20be7c | 45 | def modunload(bot, user, chan, realtarget, *args): |
4df64299 | 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 | ||
fb20be7c | 52 | @lib.hook(needchan=False, glevel=lib.MANAGER) |
4df64299 | 53 | @lib.argsEQ(1) |
fb20be7c | 54 | def modreload(bot, user, chan, realtarget, *args): |
4df64299 | 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 | ||
fb20be7c | 61 | @lib.hook(needchan=False, glevel=lib.STAFF) |
4df64299 | 62 | @lib.argsEQ(0) |
fb20be7c | 63 | def modlist(bot, user, chan, realtarget, *args): |
4df64299 | 64 | mods = ctlmod.modules |
65 | for mod in mods.itervalues(): | |
66 | bot.msg(user, "- %s %r" % (mod.__name__, mod)) | |
67 | bot.msg(user, "Done.") | |
fb20be7c | 68 | |
72e5bb4e | 69 | def _whois(user, chan, showglevel=True, showclevel=True): |
fb20be7c | 70 | if not user.isauthed(): |
72e5bb4e | 71 | return "not authed." |
fb20be7c | 72 | |
73 | fillers = {'auth': user.auth} | |
72e5bb4e | 74 | fmt = "%(auth)s" |
fb20be7c | 75 | |
72e5bb4e | 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)" | |
fb20be7c | 81 | else: |
82 | fmt += " (not staff)" | |
83 | ||
72e5bb4e | 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])) | |
fb20be7c | 98 | else: |
72e5bb4e | 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))) | |
32a54ded | 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.") |