]> jfr.im git - erebus.git/blame - modules/admin_channel.py
new admin_channel - add JOIN, PART, FPART commands
[erebus.git] / modules / admin_channel.py
CommitLineData
8c0d1364
JR
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
7modinfo = {
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
21import modlib
22lib = modlib.modlib(__name__)
23modstart = lib.modstart
24modstop = lib.modstop
25
26# module code
27
28def _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)
37def 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
58 chan.setlevel(target.auth, lib.COWNER)
59 user.msg('Added channel')
60
61
62def _part(user, chan):
63 chan.bot.chans.remove(chan)
64 del lib.parent.chans[chan.name.lower()]
65 lib.parent.query("DELETE FROM chusers WHERE chan = %s", (chan,))
66 lib.parent.query("DELETE FROM chans WHERE chname = %s", (chan,))
67 chan.bot.part(chan)
68 user.msg('Removed channel')
69
70@lib.hook(clevel=lib.COWNER)
71@lib.help(None, "removes the bot from a channel")
72@lib.argsEQ(0)
73def part(bot, user, chan, realtarget, *args):
74 return _part(user, chan)
75
76@lib.hook(glevel=lib.ADMIN)
77@lib.help(None, "removes the bot from a channel")
78@lib.argsEQ(0)
79def fpart(bot, user, chan, realtarget, *args):
80 return _part(user, chan)