]>
jfr.im git - erebus.git/blob - modules/admin_user.py
1 # Erebus IRC bot - Author: Erebus Team
2 # vim: fileencoding=utf-8
3 # simple module example
4 # This file is released into the public domain; see http://unlicense.org/
8 'author' : 'Erebus Team' ,
9 'license' : 'public domain' ,
10 'compatible' : [ 0 ], # compatible module API versions
11 'depends' : [], # other modules required to work properly?
12 'softdeps' : [ 'help' ], # modules which are preferred but not required
14 # note: softdeps will be loaded before this module, IF not disabled in the configuration (autoload.module = 0) (and if it exists)
15 # however, if it is disabled it will be silently ignored, and if it is unloaded at runtime it won't cause this one to unload.
17 # basically, softdeps are things this module will use if available, but does not require (no errors will occur if it's not loaded)
18 # for example, @lib.help() will attempt to use the help module, but swallow errors if it is not loaded
22 lib
= modlib
. modlib ( __name__
)
23 modstart
= lib
. modstart
30 return lib
. parent
. User ( s
, s
[ 1 :])
32 return lib
. parent
. user ( s
, create
= False )
34 def _resolve_level ( s
):
41 su
= "AUTHED" # resolve to 0 instead of -1
46 @lib.hook (( 'glevel' , 'glev' , 'adduser' , 'setuser' ), needchan
= False , glevel
= 1 )
47 @lib.help ( '<nick|#auth> <level>' , "adds or sets a user's global level" , "global level is any positive integer, 0 to delete a user, or -2 to ignore a user" , "-2: ignored; 0: no special access (anyone); 1: known; 50: staff; 75: admin; 100: owner" , "alternately you may use one of those keywords" , "non-admins may only change their own level, and only to 0" , "admins may only set lower access levels and may not set the access level of a user with higher access" )
49 def glevel ( bot
, user
, chan
, realtarget
, * args
):
52 target
= _resolve_user ( target_s
)
53 level
= _resolve_level ( level_s
)
56 user
. msg ( 'User not found (try #auth)' )
58 if target
. auth
is None :
59 user
. msg ( 'User is not authed' )
62 user
. msg ( "Level is unknown, must be an integer or one of %s " % ( ', ' . join ( lib
. glevs
. keys ())))
64 if level
!= - 2 and level
< 0 :
65 user
. msg ( "Level must -2, 0, or a positive integer" )
69 if not ( target
== user
and level
== 0 ) and user
. glevel
!= lib
. OWNER
:
70 if user
. glevel
<= target
. glevel
:
71 user
. msg ( "I'm afraid I can't let you do that. Your current access level is not higher than theirs." )
73 if user
. glevel
<= level
:
74 user
. msg ( "I'm afraid I can't let you do that. Your current access level is not higher than you are trying to set." )
77 if target
. setlevel ( level
):
78 user
. msg ( "The glevel of # %s has been updated successfully" % ( target
. auth
))
80 user
. msg ( "Failed to update the level" )