]>
Commit | Line | Data |
---|---|---|
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/ | |
5 | ||
6 | # module info | |
7 | modinfo = { | |
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 | |
13 | } | |
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. | |
16 | # | |
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 | |
19 | ||
20 | # preamble | |
21 | import modlib | |
22 | lib = modlib.modlib(__name__) | |
23 | modstart = lib.modstart | |
24 | modstop = lib.modstop | |
25 | ||
26 | # module code | |
27 | ||
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 | bot.join(str(chan)) | |
32 | bot.msg(user, "Rejoined.") | |
33 | ||
34 | ||
35 | def _resolve_user(s): | |
36 | if s.startswith("#"): | |
37 | return lib.parent.User(s, s[1:]) | |
38 | else: | |
39 | return lib.parent.user(s, create=False) | |
40 | ||
41 | ||
42 | def _resolve_level(s): | |
43 | s = s.lower() | |
44 | levels = ['unknown'] + [x.lower() for x in lib.clevs if x is not None] | |
45 | if s in levels: | |
46 | return levels.index(s) | |
47 | try: | |
48 | return int(s) | |
49 | except: | |
50 | pass | |
51 | ||
52 | ||
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])) | |
55 | @lib.argsEQ(2) | |
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) | |
60 | ||
61 | if target is None: | |
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" | |
67 | ||
68 | target_clevel = chan.levelof(target.auth) | |
69 | ||
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." | |
77 | ||
78 | chan.setlevel(target.auth, level) | |
79 | return "Set #%s channel level to %s" % (target.auth, args[1]) | |
80 | ||
81 | ||
82 | @lib.hook(glevel=lib.OWNER) | |
83 | @lib.help('<level>', "sets your own clevel on a channel") | |
84 | @lib.argsEQ(1) | |
85 | def forceclevel(bot, user, chan, realtarget, *args): | |
86 | target = user.auth | |
87 | level = _resolve_level(args[0]) | |
88 | chan.setlevel(target, level) | |
89 | return 'Your level on %s has been set to %d' % (chan, level) |