]>
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(('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.")
35 @lib.hook(needchan
=False, glevel
=lib
.MANAGER
)
36 @lib.help("<mod>", "loads a module")
38 def modload(bot
, user
, chan
, realtarget
, *args
):
39 okay
= ctlmod
.load(bot
.parent
, args
[0])
41 bot
.msg(user
, "Loaded %s" % (args
[0]))
43 bot
.msg(user
, "Error loading %s: %r" % (args
[0], okay
))
45 @lib.hook(needchan
=False, glevel
=lib
.MANAGER
)
46 @lib.help("<mod>", "unloads a module")
48 def modunload(bot
, user
, chan
, realtarget
, *args
):
49 okay
= ctlmod
.unload(bot
.parent
, args
[0])
51 bot
.msg(user
, "Unloaded %s" % (args
[0]))
53 bot
.msg(user
, "Error unloading %s: %r" % (args
[0], okay
))
55 @lib.hook(needchan
=False, glevel
=lib
.MANAGER
)
56 @lib.help("<mod>", "reloads a module")
58 def modreload(bot
, user
, chan
, realtarget
, *args
):
59 okay
= ctlmod
.reloadmod(bot
.parent
, args
[0])
61 bot
.msg(user
, "Reloaded %s" % (args
[0]))
63 bot
.msg(user
, "Error occurred: %r" % (okay
))
65 @lib.hook(needchan
=False, glevel
=lib
.STAFF
)
66 @lib.help(None, "list loaded modules")
68 def modlist(bot
, user
, chan
, realtarget
, *args
):
70 for mod
in mods
.itervalues():
71 bot
.msg(user
, "- %s (%s)" % ((mod
.__name
__.split(".", 1))[1], mod
.__file
__))
72 bot
.msg(user
, "Done.")
74 def _whois(user
, chan
, showglevel
=True, showclevel
=True):
75 if not user
.isauthed():
78 fillers
= {'auth': user.auth}
81 if showglevel
and user
.glevel
>= 1:
82 fillers
['glevel'] = user
.glevel
83 fmt
+= " (global access: %(glevel)s)"
84 elif user
.glevel
>= 1:
89 if showclevel
and chan
is not None:
90 if chan
.levelof(user
.auth
) >= 1:
91 fillers
['clevel'] = chan
.levelof(user
.auth
)
92 fmt
+= " (channel access: %(clevel)s)"
94 fmt
+= " (not a channel user)"
97 @lib.hook(needchan
=False)
98 @lib.help("<user>", "shows who someone is")
100 def whois(bot
, user
, chan
, realtarget
, *args
):
101 target
= bot
.parent
.user(args
[0], create
=False)
103 bot
.msg(user
, "I don't know %s." % (args
[0]))
105 bot
.msg(user
, "%s is %s" % (args
[0], _whois(target
, chan
, (user
.glevel
>= 1), (chan
is not None and chan
.levelof(user
.auth
) >= 1))))
107 @lib.hook(needchan
=False)
108 @lib.help(None, "shows who you are")
109 def whoami(bot
, user
, chan
, realtarget
, *args
):
110 bot
.msg(user
, "You are %s" % (_whois(user
, chan
)))
112 @lib.hook(needchan
=False)
113 @lib.help(None, "tries to read your auth and access level again")
114 def auth(bot
, user
, chan
, realtarget
, *args
):
115 bot
.msg(user
, "Okay, give me a second.")
116 bot
.conn
.send("WHO %s n%%ant,2" % (user
))
118 @lib.hook(needchan
=False, glevel
=1)
119 @lib.help(None, "displays length of each msgqueue")
120 def qstat(bot
, user
, chan
, realtarget
, *args
):
121 bot
.fastmsg(user
, "Regular: %d -- Slow: %d" % (len(bot
.msgqueue
), len(bot
.slowmsgqueue
)))
123 @lib.hook(needchan
=False, glevel
=lib
.ADMIN
)
124 @lib.help("[regular|slow]", "clears both or a specific msgqueue")
125 def qclear(bot
, user
, chan
, realtarget
, *args
):
127 bot
.msgqueue
= deque()
128 bot
.slowmsgqueue
= deque()
129 bot
.fastmsg(user
, "Cleared both msgqueues.")
131 if args
[0] == 'regular':
132 bot
.msgqueue
= deque()
133 elif args
[0] == 'slow':
134 bot
.slowmsgqueue
= deque()
136 bot
.fastmsg(user
, "Syntax: QCLEAR [regular|slow]")
137 return #short-circuit
138 bot
.fastmsg(user
, "Cleared that msgqueue.")