]>
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 | def _resolve_user(s): | |
29 | if s.startswith("#"): | |
30 | return lib.parent.User(s, s[1:]) | |
31 | else: | |
32 | return lib.parent.user(s, create=False) | |
33 | ||
34 | def _resolve_level(s): | |
35 | try: | |
36 | i = int(s) | |
37 | return i | |
38 | except ValueError: | |
39 | su = s.upper() | |
40 | if su == "ANYONE": | |
41 | su = "AUTHED" # resolve to 0 instead of -1 | |
42 | if su in lib.glevs: | |
43 | return lib.glevs[su] | |
44 | return None | |
45 | ||
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") | |
48 | @lib.argsEQ(2) | |
49 | def glevel(bot, user, chan, realtarget, *args): | |
50 | target_s = args[0] | |
51 | level_s = args[1] | |
52 | target = _resolve_user(target_s) | |
53 | level = _resolve_level(level_s) | |
54 | ||
55 | if target is None: | |
56 | user.msg('User not found (try #auth)') | |
57 | return | |
58 | if target.auth is None: | |
59 | user.msg('User is not authed') | |
60 | return | |
61 | if level is None: | |
62 | user.msg("Level is unknown, must be an integer or one of %s" % (', '.join(lib.glevs.keys()))) | |
63 | return | |
64 | if level != -2 and level < 0: | |
65 | user.msg("Level must -2, 0, or a positive integer") | |
66 | return | |
67 | ||
68 | ||
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.") | |
72 | return | |
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.") | |
75 | return | |
76 | ||
77 | if target.setlevel(level): | |
78 | user.msg("The glevel of #%s has been updated successfully" % (target.auth)) | |
79 | else: | |
80 | user.msg("Failed to update the level") |