]>
jfr.im git - erebus.git/blob - modules/admin_channel.py
1 # Erebus IRC bot - Author: Erebus Team
2 # vim: fileencoding=utf-8
3 # Channel list management (add, remove channels)
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
30 return lib
.parent
.User(s
, s
[1:])
32 return lib
.parent
.user(s
, create
=False)
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")
37 def join(bot
, user
, chan
, realtarget
, *args
):
41 target
= _resolve_user(args
[1])
43 user
.msg('User not found (try #auth)')
46 user
.msg('Channel must start with a #')
48 if bot
.parent
.channel(chname
) is not None:
49 user
.msg('Channel already exists, maybe you need to !REJOIN it?')
52 bot
.parent
.query("INSERT INTO chans (bot, chname, active) VALUES (%s, %s, 1)", (bot
.permnick
, chname
))
54 chan
= bot
.parent
.newchannel(bot
, chname
)
55 bot
.chans
.append(chan
)
58 if chan
.setlevel(target
.auth
, lib
.COWNER
):
59 return 'Added channel'
61 return "An error occurred!"
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
,))
70 user
.msg('Removed channel')
72 @lib.hook(clevel
=lib
.COWNER
)
73 @lib.help(None, "removes the bot from a channel")
75 def part(bot
, user
, chan
, realtarget
, *args
):
76 return _part(user
, chan
)
78 @lib.hook(glevel
=lib
.ADMIN
)
79 @lib.help(None, "removes the bot from a channel")
81 def fpart(bot
, user
, chan
, realtarget
, *args
):
82 return _part(user
, chan
)