]>
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' , 'exit' ), 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
))
35 @lib.hook ( needchan
= False , glevel
= lib
. MANAGER
)
36 @lib.help ( "[-autoload] <mod>" , "loads a module, optionally marking it for autoloading" )
37 @lib.flags ( 'autoload' )
39 def modload ( bot
, user
, chan
, realtarget
, flags
, * args
):
40 autoload
= flags
[ 'autoload' ]
44 bot
. parent
. cfg
. set ( 'autoloads' , module
, 1 )
45 bot
. msg ( user
, "Marked %s for autoloading." % ( module
))
46 okay
= ctlmod
. load ( bot
. parent
, module
)
48 bot
. msg ( user
, "Loaded %s " % ( module
))
50 bot
. msg ( user
, "Error loading %s : %r " % ( module
, okay
))
52 @lib.hook ( needchan
= False , glevel
= lib
. MANAGER
)
53 @lib.help ( "[-force] [-autoload] <mod>" , "unloads a module" , "will refuse to unload a module which is depended on by others unless you specify FORCE." , "optionally removes from autoloads" )
54 @lib.flags ( 'force' , 'autoload' )
56 def modunload ( bot
, user
, chan
, realtarget
, flags
, * args
):
57 autoload
= flags
[ 'autoload' ]
58 force
= flags
[ 'force' ]
62 bot
. parent
. cfg
. delete ( 'autoloads' , module
)
63 bot
. msg ( user
, "Unmarked %s for autoloading." % ( module
))
64 if not ctlmod
. isloaded ( module
):
65 bot
. msg ( user
, " %s is not loaded" % ( module
))
67 if len ( ctlmod
. dependents
[ module
]) > 0 :
69 bot
. msg ( user
, "That module has dependents! Say MODUNLOAD -force %s to unload it and any dependents." % ( module
))
72 okay
= ctlmod
. unload ( bot
. parent
, module
)
74 bot
. msg ( user
, "Unloaded %s " % ( module
))
76 bot
. msg ( user
, "Error unloading %s : %r " % ( module
, okay
))
78 @lib.hook ( needchan
= False , glevel
= lib
. MANAGER
)
79 @lib.help ( "<mod>" , "reloads a module" )
81 def modreload ( bot
, user
, chan
, realtarget
, * args
):
82 if not ctlmod
. isloaded ( args
[ 0 ]):
83 bot
. msg ( user
, " %s is not loaded" % ( args
[ 0 ]))
86 okay
= ctlmod
. reloadmod ( bot
. parent
, args
[ 0 ])
88 bot
. msg ( user
, "Reloaded %s " % ( args
[ 0 ]))
90 bot
. msg ( user
, "Error occurred: %r " % ( okay
))
92 @lib.hook ( needchan
= False , glevel
= lib
. STAFF
)
93 @lib.help ( None , "list loaded modules" )
95 def modlist ( bot
, user
, chan
, realtarget
, * args
):
97 for modname
, mod
in sorted ( mods
. items ()):
98 bot
. msg ( user
, "- %s ( %s ) [ %s ]" % (( modname
, mod
.__ file
__ , ', ' . join ( ctlmod
. dependents
[ modname
]))))
99 bot
. msg ( user
, "Done." )
101 def _whois ( user
, chan
, showglevel
= True , showclevel
= True ):
102 if not user
. isauthed ():
105 fillers
= {'auth': user.auth}
108 if showglevel
and user
. glevel
>= 1 :
109 fillers
[ 'glevel' ] = user
. glevel
110 fmt
+= " (global access: %(glevel)s )"
111 elif user
. glevel
>= 1 :
113 elif user
. glevel
<= - 2 :
116 fmt
+= " (not staff)"
118 if ( showclevel
or showglevel
) and chan
is not None :
119 clev
= chan
. levelof ( user
. auth
)
121 fillers
[ 'clevel' ] = ( lib
. clevs
[ clev
] if clev
< len ( lib
. clevs
) else clev
)
122 fmt
+= " (channel access: %(clevel)s )"
124 fmt
+= " (not a channel user)"
127 @lib.hook ( needchan
= False , wantchan
= True )
128 @lib.help ( "<user|#auth>" , "shows who someone is" )
130 def whois ( bot
, user
, chan
, realtarget
, * args
):
132 if name
. startswith ( "#" ):
133 target
= bot
. parent
. User ( name
, name
[ 1 :])
135 target
= bot
. parent
. user ( name
, create
= False )
137 return "I don't know %s ." % ( args
[ 0 ])
139 return " %s is %s " % ( args
[ 0 ], _whois ( target
, chan
, ( user
. glevel
>= 1 ), ( chan
is not None and chan
. levelof ( user
. auth
) >= 1 )))
141 @lib.hook ( needchan
= False , wantchan
= True )
142 @lib.help ( None , "shows who you are" )
143 def whoami ( bot
, user
, chan
, realtarget
, * args
):
144 return "You are %s " % ( _whois ( user
, chan
))
146 @lib.hook ( needchan
= False )
147 @lib.help ( None , "tries to read your auth and access level again" )
148 def auth ( bot
, user
, chan
, realtarget
, * args
):
149 bot
. msg ( user
, "Okay, give me a second." )
150 bot
. conn
. send ( "WHO %s n %% ant,2" % ( user
))
152 @lib.hook ( needchan
= False , glevel
= 1 )
153 @lib.help ( None , "displays length of each msgqueue" )
154 def qstat ( bot
, user
, chan
, realtarget
, * args
):
155 bot
. fastmsg ( user
, "Regular: %d -- Slow: %d " % ( len ( bot
. msgqueue
), len ( bot
. slowmsgqueue
)))
157 @lib.hook (( 'qclear' , 'cq' , 'clearq' , 'clearqueue' ), needchan
= False , glevel
= lib
. ADMIN
)
158 @lib.help ( "[regular|slow]" , "clears both or a specific msgqueue" )
159 def qclear ( bot
, user
, chan
, realtarget
, * args
):
161 bot
. msgqueue
= deque ()
162 bot
. slowmsgqueue
= deque ()
163 bot
. fastmsg ( user
, "Cleared both msgqueues." )
165 if args
[ 0 ] == 'regular' :
166 bot
. msgqueue
= deque ()
167 elif args
[ 0 ] == 'slow' :
168 bot
. slowmsgqueue
= deque ()
170 bot
. fastmsg ( user
, "Syntax: QCLEAR [regular|slow]" )
171 return #short-circuit
172 bot
. fastmsg ( user
, "Cleared that msgqueue." )