]>
jfr.im git - erebus.git/blob - modules/channel_admin.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
28 @lib.hook(clevel
=lib
.FRIEND
)
29 @lib.help(None, "rejoin a channel (if the bot has been kicked)")
30 def rejoin(bot
, user
, chan
, realtarget
, *args
):
31 chan
.bot
.join(str(chan
))
32 bot
.msg(user
, "Rejoined %s." % (chan
))
37 return lib
.parent
.User(s
, s
[1:])
39 return lib
.parent
.user(s
, create
=False)
42 def _resolve_level(s
):
44 levels
= ['unknown'] + [x
.lower() for x
in lib
.clevs
if x
is not None]
46 return levels
.index(s
)
53 @lib.hook(('clevel','setlevel','chanlev'), clevel
=lib
.FRIEND
)
54 @lib.help('<nick|#auth> <level>', "adds or sets a user's channel access level", "Levels: Unknown, " + ', '.join([x
for x
in lib
.clevs
if x
]))
56 def clevel(bot
, user
, chan
, realtarget
, *args
):
57 target
= _resolve_user(args
[0])
58 level
= _resolve_level(args
[1])
59 user_clevel
= chan
.levelof(user
.auth
)
62 return "User not found (try #auth)"
63 if target
.auth
is None:
64 return "User is not authed"
65 if level
is None or level
< 0 or level
> lib
.COWNER
:
66 return "Level is unknown"
68 target_clevel
= chan
.levelof(target
.auth
)
70 if not (target
== user
and level
== 0) and user_clevel
!= lib
.COWNER
:
71 if user_clevel
< lib
.MASTER
:
72 return "I'm afraid I can't let you do that. You can only reset your own level to 0."
73 if user_clevel
<= target_clevel
:
74 return "I'm afraid I can't let you do that. Your current access level is not higher than theirs."
75 if user_clevel
<= level
:
76 return "I'm afraid I can't let you do that. Your current access level is not higher than you are trying to set."
78 chan
.setlevel(target
.auth
, level
)
79 return "Set #%s channel level to %s" % (target
.auth
, args
[1])
82 @lib.hook(('forceclevel','fclevel'), glevel
=lib
.MANAGER
)
83 @lib.help('<level>', "sets your own clevel on a channel")
85 def forceclevel(bot
, user
, chan
, realtarget
, *args
):
87 level
= _resolve_level(args
[0])
88 chan
.setlevel(target
, level
)
89 return 'Your level on %s has been set to %d' % (chan
, level
)