]>
Commit | Line | Data |
---|---|---|
8c0d1364 JR |
1 | # Erebus IRC bot - Author: Erebus Team |
2 | # vim: fileencoding=utf-8 | |
bac69af4 | 3 | # Channel list management (add, remove channels) |
8c0d1364 JR |
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 | @lib.hook(needchan=False, glevel=lib.STAFF) | |
35 | @lib.help('<#channel> [<nick|#auth>]', "adds a channel and makes the user (yourself by default) its owner") | |
36 | @lib.argsGE(1) | |
37 | def join(bot, user, chan, realtarget, *args): | |
38 | chname = args[0] | |
39 | target = user | |
40 | if len(args) > 1: | |
41 | target = _resolve_user(args[1]) | |
42 | if target is None: | |
43 | user.msg('User not found (try #auth)') | |
44 | return | |
45 | if chname[0] != "#": | |
46 | user.msg('Channel must start with a #') | |
47 | return | |
48 | if bot.parent.channel(chname) is not None: | |
49 | user.msg('Channel already exists, maybe you need to !REJOIN it?') | |
50 | return | |
51 | ||
52 | bot.parent.query("INSERT INTO chans (bot, chname, active) VALUES (%s, %s, 1)", (bot.permnick, chname)) | |
53 | ||
54 | chan = bot.parent.newchannel(bot, chname) | |
55 | bot.chans.append(chan) | |
56 | bot.join(chan) | |
57 | ||
2c58b913 JR |
58 | if chan.setlevel(target.auth, lib.COWNER): |
59 | return 'Added channel' | |
60 | else: | |
61 | return "An error occurred!" | |
8c0d1364 JR |
62 | |
63 | ||
64 | def _part(user, chan): | |
65 | chan.bot.chans.remove(chan) | |
66 | del lib.parent.chans[chan.name.lower()] | |
67 | lib.parent.query("DELETE FROM chusers WHERE chan = %s", (chan,)) | |
68 | lib.parent.query("DELETE FROM chans WHERE chname = %s", (chan,)) | |
69 | chan.bot.part(chan) | |
70 | user.msg('Removed channel') | |
71 | ||
72 | @lib.hook(clevel=lib.COWNER) | |
73 | @lib.help(None, "removes the bot from a channel") | |
74 | @lib.argsEQ(0) | |
75 | def part(bot, user, chan, realtarget, *args): | |
76 | return _part(user, chan) | |
77 | ||
78 | @lib.hook(glevel=lib.ADMIN) | |
79 | @lib.help(None, "removes the bot from a channel") | |
80 | @lib.argsEQ(0) | |
81 | def fpart(bot, user, chan, realtarget, *args): | |
82 | return _part(user, chan) |