]>
jfr.im git - erebus.git/blob - modules/control.py
1 # Erebus IRC bot - Author: Erebus Team
2 # vim: fileencoding=utf-8
3 # Various highly recommended "control" commands.
4 # This file is released into the public domain; see http://unlicense.org/
8 'author' : 'Erebus Team' ,
9 'license' : 'public domain' ,
17 lib
= modlib
. modlib ( __name__
)
18 modstart
= lib
. modstart
24 from collections
import deque
27 @lib.hook (( 'die' , 'restart' ), needchan
= False , glevel
= lib
. MANAGER
)
28 @lib.help ( None , "stops the bot" )
29 def die ( bot
, user
, chan
, realtarget
, * args
):
30 quitmsg
= ' ' . join ( args
)
31 for botitem
in bot
. parent
. bots
. values ():
32 bot
. conn
. send ( "QUIT :Restarting. %s " % ( quitmsg
))
36 @lib.hook ( needchan
= False , glevel
= lib
. MANAGER
)
37 @lib.help ( "<mod>" , "loads a module" )
39 def modload ( bot
, user
, chan
, realtarget
, * args
):
40 okay
= ctlmod
. load ( bot
. parent
, args
[ 0 ])
42 bot
. msg ( user
, "Loaded %s " % ( args
[ 0 ]))
44 bot
. msg ( user
, "Error loading %s : %r " % ( args
[ 0 ], okay
))
46 @lib.hook ( needchan
= False , glevel
= lib
. MANAGER
)
47 @lib.help ( "<mod> [FORCE]" , "unloads a module" , "will refuse to unload a module which is depended on by others" , "unless you specify FORCE." )
49 def modunload ( bot
, user
, chan
, realtarget
, * args
):
50 if len ( ctlmod
. dependents
[ args
[ 0 ]]) > 0 :
51 if len ( args
) == 1 or args
[ 1 ]. lower () != "force" :
52 bot
. msg ( user
, "That module has dependents! Say MODUNLOAD %s FORCE to unload it and any dependents." % ( args
[ 0 ]))
54 okay
= ctlmod
. unload ( bot
. parent
, args
[ 0 ])
56 bot
. msg ( user
, "Unloaded %s " % ( args
[ 0 ]))
58 bot
. msg ( user
, "Error unloading %s : %r " % ( args
[ 0 ], okay
))
60 @lib.hook ( needchan
= False , glevel
= lib
. MANAGER
)
61 @lib.help ( "<mod>" , "reloads a module" )
63 def modreload ( bot
, user
, chan
, realtarget
, * args
):
64 okay
= ctlmod
. reloadmod ( bot
. parent
, args
[ 0 ])
66 bot
. msg ( user
, "Reloaded %s " % ( args
[ 0 ]))
68 bot
. msg ( user
, "Error occurred: %r " % ( okay
))
70 @lib.hook ( needchan
= False , glevel
= lib
. STAFF
)
71 @lib.help ( None , "list loaded modules" )
73 def modlist ( bot
, user
, chan
, realtarget
, * args
):
75 for modname
, mod
in mods
. items ():
76 bot
. msg ( user
, "- %s ( %s ) [ %s ]" % (( modname
, mod
.__ file
__ , ', ' . join ( ctlmod
. dependents
[ modname
]))))
77 bot
. msg ( user
, "Done." )
79 def _whois ( user
, chan
, showglevel
= True , showclevel
= True ):
80 if not user
. isauthed ():
83 fillers
= {'auth': user.auth}
86 if showglevel
and user
. glevel
>= 1 :
87 fillers
[ 'glevel' ] = user
. glevel
88 fmt
+= " (global access: %(glevel)s )"
89 elif user
. glevel
>= 1 :
94 if showclevel
and chan
is not None :
95 if chan
. levelof ( user
. auth
) >= 1 :
96 fillers
[ 'clevel' ] = chan
. levelof ( user
. auth
)
97 fmt
+= " (channel access: %(clevel)s )"
99 fmt
+= " (not a channel user)"
102 @lib.hook ( needchan
= False , wantchan
= True )
103 @lib.help ( "<user|#auth>" , "shows who someone is" )
105 def whois ( bot
, user
, chan
, realtarget
, * args
):
107 if name
. startswith ( "#" ):
108 target
= bot
. parent
. User ( name
, name
[ 1 :])
110 target
= bot
. parent
. user ( name
, create
= False )
112 return "I don't know %s ." % ( args
[ 0 ])
114 return " %s is %s " % ( args
[ 0 ], _whois ( target
, chan
, ( user
. glevel
>= 1 ), ( chan
is not None and chan
. levelof ( user
. auth
) >= 1 )))
116 @lib.hook ( needchan
= False , wantchan
= True )
117 @lib.help ( None , "shows who you are" )
118 def whoami ( bot
, user
, chan
, realtarget
, * args
):
119 return "You are %s " % ( _whois ( user
, chan
))
121 @lib.hook ( needchan
= False )
122 @lib.help ( None , "tries to read your auth and access level again" )
123 def auth ( bot
, user
, chan
, realtarget
, * args
):
124 bot
. msg ( user
, "Okay, give me a second." )
125 bot
. conn
. send ( "WHO %s n %% ant,2" % ( user
))
127 @lib.hook ( needchan
= False , glevel
= 1 )
128 @lib.help ( None , "displays length of each msgqueue" )
129 def qstat ( bot
, user
, chan
, realtarget
, * args
):
130 bot
. fastmsg ( user
, "Regular: %d -- Slow: %d " % ( len ( bot
. msgqueue
), len ( bot
. slowmsgqueue
)))
132 @lib.hook (( 'qclear' , 'cq' , 'clearq' , 'clearqueue' ), needchan
= False , glevel
= lib
. ADMIN
)
133 @lib.help ( "[regular|slow]" , "clears both or a specific msgqueue" )
134 def qclear ( bot
, user
, chan
, realtarget
, * args
):
136 bot
. msgqueue
= deque ()
137 bot
. slowmsgqueue
= deque ()
138 bot
. fastmsg ( user
, "Cleared both msgqueues." )
140 if args
[ 0 ] == 'regular' :
141 bot
. msgqueue
= deque ()
142 elif args
[ 0 ] == 'slow' :
143 bot
. slowmsgqueue
= deque ()
145 bot
. fastmsg ( user
, "Syntax: QCLEAR [regular|slow]" )
146 return #short-circuit
147 bot
. fastmsg ( user
, "Cleared that msgqueue." )
149 @lib.hook ( needchan
= False , wantchan
= True , glevel
= lib
. ADMIN
)
150 @lib.help ( "<nick> <message>" , "inject a line as though it came from <nick>" , "note that this injects lines, not commands" , "ex: INJECT DimeCadmium !WHOAMI" )
151 def inject ( bot
, user
, chan
, realtarget
, * args
):
152 targetuser
= bot
. parent
. user ( args
[ 0 ], create
= False )
153 if targetuser
is None :
154 bot
. msg ( user
, "User is unknown." )
156 if targetuser
. glevel
> user
. glevel
:
157 bot
. msg ( user
, "That user has a higher access level than you." )
161 bot
. parsemsg ( bot
. parent
. user ( args
[ 0 ], create
= False ), str ( chan
), ' ' . join ( args
[ 1 :]))
163 bot
. parsemsg ( bot
. parent
. user ( args
[ 0 ], create
= False ), str ( bot
), ' ' . join ( args
[ 1 :]))