]>
jfr.im git - erebus.git/blob - modules/control.py
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/
7 'author': 'Erebus Team',
8 'license': 'public domain',
15 lib
= modlib
.modlib(__name__
)
16 modstart
= lib
.modstart
22 from collections
import deque
25 @lib.hook(needchan
=False, glevel
=lib
.MANAGER
)
26 def die(bot
, user
, chan
, realtarget
, *args
):
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.")
34 @lib.hook(needchan
=False, glevel
=lib
.MANAGER
)
36 def modload(bot
, user
, chan
, realtarget
, *args
):
37 okay
= ctlmod
.load(bot
.parent
, args
[0])
39 bot
.msg(user
, "Loaded %s" % (args
[0]))
41 bot
.msg(user
, "Error loading %s: %r" % (args
[0], okay
))
43 @lib.hook(needchan
=False, glevel
=lib
.MANAGER
)
45 def modunload(bot
, user
, chan
, realtarget
, *args
):
46 okay
= ctlmod
.unload(bot
.parent
, args
[0])
48 bot
.msg(user
, "Unloaded %s" % (args
[0]))
50 bot
.msg(user
, "Error unloading %s: %r" % (args
[0], okay
))
52 @lib.hook(needchan
=False, glevel
=lib
.MANAGER
)
54 def modreload(bot
, user
, chan
, realtarget
, *args
):
55 okay
= ctlmod
.reloadmod(bot
.parent
, args
[0])
57 bot
.msg(user
, "Reloaded %s" % (args
[0]))
59 bot
.msg(user
, "Error occurred: %r" % (okay
))
61 @lib.hook(needchan
=False, glevel
=lib
.STAFF
)
63 def modlist(bot
, user
, chan
, realtarget
, *args
):
65 for mod
in mods
.itervalues():
66 bot
.msg(user
, "- %s %r" % (mod
.__name
__, mod
))
67 bot
.msg(user
, "Done.")
69 def _whois(user
, chan
, showglevel
=True, showclevel
=True):
70 if not user
.isauthed():
73 fillers
= {'auth': user.auth}
76 if showglevel
and user
.glevel
>= 1:
77 fillers
['glevel'] = user
.glevel
78 fmt
+= " (global access: %(glevel)s)"
79 elif user
.glevel
>= 1:
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)"
89 fmt
+= " (not a channel user)"
92 @lib.hook(needchan
=False)
94 def whois(bot
, user
, chan
, realtarget
, *args
):
95 target
= bot
.parent
.user(args
[0], create
=False)
97 bot
.msg(user
, "I don't know %s." % (args
[0]))
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))))
101 @lib.hook(needchan
=False)
102 def whoami(bot
, user
, chan
, realtarget
, *args
):
103 bot
.msg(user
, "You are %s" % (_whois(user
, chan
)))
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
)))
109 @lib.hook(needchan
=False, glevel
=lib
.ADMIN
)
110 def qclear(bot
, user
, chan
, realtarget
, *args
):
112 bot
.msgqueue
= deque()
113 bot
.slowmsgqueue
= deque()
114 bot
.fastmsg(user
, "Cleared both msgqueues.")
116 if args
[0] == 'regular':
117 bot
.msgqueue
= deque()
118 elif args
[0] == 'slow':
119 bot
.slowmsgqueue
= deque()
121 bot
.fastmsg(user
, "Syntax: QCLEAR [regular|slow]")
122 return #short-circuit
123 bot
.fastmsg(user
, "Cleared that msgqueue.")