]> jfr.im git - erebus.git/commitdiff
chanops module - kick/op/voice
authorzonidjan <redacted>
Fri, 8 Sep 2017 22:18:01 +0000 (17:18 -0500)
committerzonidjan <redacted>
Fri, 8 Sep 2017 22:18:01 +0000 (17:18 -0500)
TODO
modules/chanops.py [new file with mode: 0644]

diff --git a/TODO b/TODO
index 189785b4729cfe5b268e475cc456671db6572322..40f356eeec0fb5de224cd64cf923adbdba48b492 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,7 +1,6 @@
 == other ==
 module: user (global access) management
 module: channel access management (addchanuser/delchanuser)
-module: chanop (kick/ban/etc)
 module: autoop (op/voice/etc on join)
 channel management bans,kicks,voices,ops,bot-ignores...
 
diff --git a/modules/chanops.py b/modules/chanops.py
new file mode 100644 (file)
index 0000000..984815c
--- /dev/null
@@ -0,0 +1,105 @@
+# Erebus IRC bot - Author: Erebus Team
+# !EVAL and !EXEC commands
+# This file is released into the public domain; see http://unlicense.org/
+
+# module info
+modinfo = {
+       'author': 'Erebus Team',
+       'license': 'public domain',
+       'compatible': [1,2],
+       'depends': [],
+       'softdeps': ['help'],
+}
+
+# preamble
+import modlib
+lib = modlib.modlib(__name__)
+modstart = lib.modstart
+modstop = lib.modstop
+
+# module code
+import sys
+import ctlmod
+
+
+def module(name):
+       return lib.mod(name)
+
+@lib.hook(None, clevel=lib.OP)
+@lib.help("<nick|#auth> [<reason>]", "kick <nick>, or all using <#auth>")
+@lib.argsGE(1)
+def _kick(bot, user, chan, realtarget, *args):
+       people = []
+       if args[0][0] == "#":
+               people = bot.parent.getuserbyauth(args[0][1:])
+       else:
+               people = [args[0]]
+
+       if len(args) > 1:
+               reason = ' '.join(args[1:])
+       else:
+               reason = "Commanded"
+
+       for person in people:
+               bot.conn.send("KICK %s %s :%s" % (chan, person, reason))
+       return len(people)
+
+@lib.hook(None, clevel=lib.OP)
+@lib.help("<nick|#auth> [<reason>]", "kick <nick>, or all using <#auth>")
+@lib.argsGE(1)
+def kick(bot, user, chan, realtarget, *args):
+       number = _kick(bot, user, chan, realtarget, *args)
+       bot.msg(user, "Done. Kicked %d people." % (number))
+
+@lib.hook(None, clevel=lib.OP)
+@lib.help("<nick> [<reason>]", "kick all using the auth of <nick>")
+@lib.argsGE(1)
+def kickall(bot, user, chan, realtarget, *args):
+       auth = bot.parent.user(args[0]).auth
+       if auth is not None:
+               number = _kick(bot, user, chan, realtarget, "#"+bot.parent.user(args[0]).auth, *args[1:])
+               bot.msg(user, "Done. Kicked %d people." % (number))
+       else:
+               bot.msg(user, "I don't know that person's auth.")
+
+@lib.hook(None, clevel=lib.OP)
+@lib.help("<nick> [...]", "kicks multiple nicks.")
+def kickeach(bot, user, chan, realtarget, *args):
+       number = 0
+       for person in args:
+               number += _kick(bot, user, chan, realtarget, person)
+       bot.msg(user, "Done. Kicked %d people." % (number))
+
+
+
+def _mode(bot, chan, flag, letter, nicks):
+       bot.conn.send("MODE %s %s%s %s" % (chan, flag, letter*len(nicks), ' '.join(nicks)))
+
+@lib.hook(None, clevel=lib.OP)
+@lib.help("[<nick>] [...]", "ops yourself or <nick>s")
+def op(bot, user, chan, realtarget, *args):
+       if len(args) == 0: args = (user.nick,)
+       _mode(bot, chan, "+", "o", args)
+       bot.msg(user, "Opped.")
+
+@lib.hook(None, clevel=lib.OP)
+@lib.help("[<nick>] [...]", "deops yourself or <nick>s")
+def deop(bot, user, chan, realtarget, *args):
+       if len(args) == 0: args = (user.nick,)
+       _mode(bot, chan, "-", "o", args)
+       bot.msg(user, "Deopped.")
+
+@lib.hook(None, clevel=lib.OP)
+@lib.help("[<nick>] [...]", "")
+def voice(bot, user, chan, realtarget, *args):
+       if len(args) == 0: args = (user.nick,)
+       _mode(bot, chan, "+", "v", args)
+       bot.msg(user, "Voiced.")
+
+@lib.hook(None, clevel=lib.OP)
+@lib.help("[<nick>] [...]", "")
+def devoice(bot, user, chan, realtarget, *args):
+       if len(args) == 0: args = (user.nick,)
+       _mode(bot, chan, "-", "v", args)
+       bot.msg(user, "Devoiced.")
+