]> jfr.im git - erebus.git/blame - modules/control.py
control - msgqueue control
[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
20import sys
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
69@lib.hook(cmd='whoami', needchan=False)
70def whoami(bot, user, chan, realtarget, *args):
71 if not user.isauthed():
72 bot.msg(user, "You are not authed.")
73 return
74
75 fillers = {'auth': user.auth}
76 fmt = "You are %(auth)s"
77
78 if user.glevel >= 1:
79 fillers['glevel'] = user.glevel
80 fmt += " (global access: %(glevel)s)"
81 else:
82 fmt += " (not staff)"
83
84 if chan is not None and chan.levelof(user.auth) >= 1:
85 fillers['clevel'] = chan.levelof(user.auth)
86 fmt += " (channel access: %(clevel)s)"
87 else:
88 fmt += " (not a channel user)"
89 bot.msg(user, fmt % fillers)
32a54ded 90
91@lib.hook(needchan=False, glevel=1)
92def qstat(bot, user, chan, realtarget, *args):
93 bot.fastmsg(user, "Regular: %d -- Slow: %d" % (len(bot.msgqueue), len(bot.slowmsgqueue)))
94
95@lib.hook(needchan=False, glevel=lib.ADMIN)
96def qclear(bot, user, chan, realtarget, *args):
97 if len(args) == 0:
98 bot.msgqueue = deque()
99 bot.slowmsgqueue = deque()
100 bot.fastmsg(user, "Cleared both msgqueues.")
101 else:
102 if args[0] == 'regular':
103 bot.msgqueue = deque()
104 elif args[0] == 'slow':
105 bot.slowmsgqueue = deque()
106 else:
107 bot.fastmsg(user, "Syntax: QCLEAR [regular|slow]")
108 return #short-circuit
109 bot.fastmsg(user, "Cleared that msgqueue.")