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