]> jfr.im git - erebus.git/blame - modules/control.py
trivia - fix (bogus!) pylint errors
[erebus.git] / modules / control.py
CommitLineData
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
6modinfo = {
7 'author': 'Erebus Team',
8 'license': 'public domain',
9 'compatible': [1],
10 'depends': [],
11}
12
13# preamble
14import modlib
15lib = modlib.modlib(__name__)
16modstart = lib.modstart
17modstop = lib.modstop
18
19# module code
d371d194 20import sys, os
e2b30093 21import ctlmod
32a54ded 22from collections import deque
e2b30093 23
24
fb20be7c 25@lib.hook(needchan=False, glevel=lib.MANAGER)
26def 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 36def 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 45def 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 54def 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 63def 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 69def _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)
94def 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)
102def 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)
106def 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)
110def 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.")