]> jfr.im git - erebus.git/blob - modules/chanops.py
userinfo - use return-to-reply shortcut
[erebus.git] / modules / chanops.py
1 # Erebus IRC bot - Author: Erebus Team
2 # vim: fileencoding=utf-8
3 # chanop commands
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],
11 'depends': [],
12 'softdeps': ['help'],
13 }
14
15 # preamble
16 import modlib
17 lib = modlib.modlib(__name__)
18 modstart = lib.modstart
19 modstop = lib.modstop
20
21 # module code
22 import sys
23 import ctlmod
24
25
26 def module(name):
27 return lib.mod(name)
28
29 def _kick(bot, user, chan, realtarget, *args):
30 people = []
31 if args[0].startswith("#"):
32 people = bot.parent.getuserbyauth(args[0][1:])
33 else:
34 people = [args[0]]
35
36 if len(args) > 1:
37 reason = ' '.join(args[1:])
38 else:
39 reason = "Commanded"
40
41 for person in people:
42 bot.conn.send("KICK %s %s :%s" % (chan, person, reason))
43 return len(people)
44
45 @lib.hook(None, clevel=lib.OP)
46 @lib.help("<nick|#auth> [<reason>]", "kick <nick>, or all using <#auth>")
47 @lib.argsGE(1)
48 def kick(bot, user, chan, realtarget, *args):
49 number = _kick(bot, user, chan, realtarget, *args)
50 bot.msg(user, "Done. Kicked %d people." % (number))
51
52 @lib.hook(None, clevel=lib.OP)
53 @lib.help("<nick> [<reason>]", "kick all using the auth of <nick>")
54 @lib.argsGE(1)
55 def kickall(bot, user, chan, realtarget, *args):
56 auth = bot.parent.user(args[0]).auth
57 if auth is not None:
58 number = _kick(bot, user, chan, realtarget, "#"+bot.parent.user(args[0]).auth, *args[1:])
59 bot.msg(user, "Done. Kicked %d people." % (number))
60 else:
61 bot.msg(user, "I don't know that person's auth.")
62
63 @lib.hook(None, clevel=lib.OP)
64 @lib.help("<nick> [...]", "kicks multiple nicks.")
65 def kickeach(bot, user, chan, realtarget, *args):
66 number = 0
67 for person in args:
68 number += _kick(bot, user, chan, realtarget, person)
69 bot.msg(user, "Done. Kicked %d people." % (number))
70
71
72
73 def _mode(bot, chan, flag, letter, nicks):
74 bot.conn.send("MODE %s %s%s %s" % (chan, flag, letter*len(nicks), ' '.join(nicks)))
75
76 @lib.hook(None, clevel=lib.OP)
77 @lib.help("[<nick>] [...]", "ops yourself or <nick>s")
78 def op(bot, user, chan, realtarget, *args):
79 if len(args) == 0: args = (user.nick,)
80 _mode(bot, chan, "+", "o", args)
81 bot.msg(user, "Opped.")
82
83 @lib.hook(None, clevel=lib.OP)
84 @lib.help("[<nick>] [...]", "deops yourself or <nick>s")
85 def deop(bot, user, chan, realtarget, *args):
86 if len(args) == 0: args = (user.nick,)
87 _mode(bot, chan, "-", "o", args)
88 bot.msg(user, "Deopped.")
89
90 @lib.hook(None, clevel=lib.OP)
91 @lib.help("[<nick>] [...]", "voices yourself or <nick>s")
92 def voice(bot, user, chan, realtarget, *args):
93 if len(args) == 0: args = (user.nick,)
94 _mode(bot, chan, "+", "v", args)
95 bot.msg(user, "Voiced.")
96
97 @lib.hook(None, clevel=lib.OP)
98 @lib.help("[<nick>] [...]", "devoices yourself or <nick>s")
99 def devoice(bot, user, chan, realtarget, *args):
100 if len(args) == 0: args = (user.nick,)
101 _mode(bot, chan, "-", "v", args)
102 bot.msg(user, "Devoiced.")
103