From: John Runyon Date: Sat, 2 Mar 2024 16:58:23 +0000 (-0700) Subject: new admin_channel - add JOIN, PART, FPART commands X-Git-Url: https://jfr.im/git/erebus.git/commitdiff_plain/8c0d1364a4ca2c302817bbc734b82a2883c5ca2e new admin_channel - add JOIN, PART, FPART commands --- diff --git a/modules/admin_channel.py b/modules/admin_channel.py new file mode 100644 index 0000000..6d9eba8 --- /dev/null +++ b/modules/admin_channel.py @@ -0,0 +1,80 @@ +# Erebus IRC bot - Author: Erebus Team +# vim: fileencoding=utf-8 +# simple module example +# This file is released into the public domain; see http://unlicense.org/ + +# module info +modinfo = { + 'author': 'Erebus Team', + 'license': 'public domain', + 'compatible': [0], # compatible module API versions + 'depends': [], # other modules required to work properly? + 'softdeps': ['help'], # modules which are preferred but not required +} +# note: softdeps will be loaded before this module, IF not disabled in the configuration (autoload.module = 0) (and if it exists) +# 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. +# +# basically, softdeps are things this module will use if available, but does not require (no errors will occur if it's not loaded) +# for example, @lib.help() will attempt to use the help module, but swallow errors if it is not loaded + +# preamble +import modlib +lib = modlib.modlib(__name__) +modstart = lib.modstart +modstop = lib.modstop + +# module code + +def _resolve_user(s): + if s.startswith("#"): + return lib.parent.User(s, s[1:]) + else: + return lib.parent.user(s, create=False) + +@lib.hook(needchan=False, glevel=lib.STAFF) +@lib.help('<#channel> []', "adds a channel and makes the user (yourself by default) its owner") +@lib.argsGE(1) +def join(bot, user, chan, realtarget, *args): + chname = args[0] + target = user + if len(args) > 1: + target = _resolve_user(args[1]) + if target is None: + user.msg('User not found (try #auth)') + return + if chname[0] != "#": + user.msg('Channel must start with a #') + return + if bot.parent.channel(chname) is not None: + user.msg('Channel already exists, maybe you need to !REJOIN it?') + return + + bot.parent.query("INSERT INTO chans (bot, chname, active) VALUES (%s, %s, 1)", (bot.permnick, chname)) + + chan = bot.parent.newchannel(bot, chname) + bot.chans.append(chan) + bot.join(chan) + + chan.setlevel(target.auth, lib.COWNER) + user.msg('Added channel') + + +def _part(user, chan): + chan.bot.chans.remove(chan) + del lib.parent.chans[chan.name.lower()] + lib.parent.query("DELETE FROM chusers WHERE chan = %s", (chan,)) + lib.parent.query("DELETE FROM chans WHERE chname = %s", (chan,)) + chan.bot.part(chan) + user.msg('Removed channel') + +@lib.hook(clevel=lib.COWNER) +@lib.help(None, "removes the bot from a channel") +@lib.argsEQ(0) +def part(bot, user, chan, realtarget, *args): + return _part(user, chan) + +@lib.hook(glevel=lib.ADMIN) +@lib.help(None, "removes the bot from a channel") +@lib.argsEQ(0) +def fpart(bot, user, chan, realtarget, *args): + return _part(user, chan)