2017-12-26 11:50:18 +00:00
|
|
|
import Utils
|
2016-04-18 15:50:19 +00:00
|
|
|
|
|
|
|
class Module(object):
|
|
|
|
_name = "Channel Op"
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
bot.events.on("received").on("command").on("kick", "k"
|
2018-08-31 09:51:47 +00:00
|
|
|
).hook(self.kick, channel_only=True, require_mode="o",
|
|
|
|
min_args=1, help="Kick a user from the channel",
|
|
|
|
usage="<nickname> [reason]")
|
2018-07-19 13:39:10 +00:00
|
|
|
|
2016-04-18 15:50:19 +00:00
|
|
|
bot.events.on("received").on("command").on("ban"
|
2018-08-31 09:51:47 +00:00
|
|
|
).hook(self.ban, channel_only=True, require_mode="o",
|
|
|
|
min_args=1, help="Ban a user/hostmask from the channel",
|
|
|
|
usage="<nickname/hostmask>")
|
2018-07-19 13:39:10 +00:00
|
|
|
bot.events.on("received").on("command").on("unban"
|
2018-08-31 09:51:47 +00:00
|
|
|
).hook(self.unban, channel_only=True, require_mode="o",
|
|
|
|
min_args=1, help="Unban a user/hostmask from the channel",
|
|
|
|
usage="<nickname/hostmask>")
|
2018-07-19 13:39:10 +00:00
|
|
|
|
2016-04-18 15:50:19 +00:00
|
|
|
bot.events.on("received").on("command").on("kickban", "kb"
|
2018-08-31 09:51:47 +00:00
|
|
|
).hook(self.kickban, channel_only=True, require_mode="o",
|
|
|
|
min_args=1, help="Kickban a user from the channel",
|
|
|
|
usage="<nickanme> [reason]")
|
2018-07-19 13:39:10 +00:00
|
|
|
|
2016-04-22 10:48:28 +00:00
|
|
|
bot.events.on("received").on("command").on("op"
|
2018-08-31 09:51:47 +00:00
|
|
|
).hook(self.op, channel_only=True, require_mode="o",
|
|
|
|
help="Give +o to a user", usage="[nickname]")
|
2016-05-17 13:51:47 +00:00
|
|
|
bot.events.on("received").on("command").on("deop"
|
2018-08-31 09:51:47 +00:00
|
|
|
).hook(self.deop, channel_only=True, require_mode="o",
|
|
|
|
help="Take +o from a user", usage="[nickname]")
|
2018-07-19 13:39:10 +00:00
|
|
|
|
2016-05-17 13:51:47 +00:00
|
|
|
bot.events.on("received").on("command").on("voice"
|
2018-08-31 09:51:47 +00:00
|
|
|
).hook(self.voice, channel_only=True, require_mode="o",
|
|
|
|
help="Give +v to a user", usage="[nickname]")
|
2016-05-17 13:51:47 +00:00
|
|
|
bot.events.on("received").on("command").on("devoice"
|
2018-08-31 09:51:47 +00:00
|
|
|
).hook(self.devoice, channel_only=True, require_mode="o",
|
|
|
|
help="Take +v from a user", usage="[nickname]")
|
2018-07-19 13:39:10 +00:00
|
|
|
|
2018-08-30 10:13:26 +00:00
|
|
|
bot.events.on("received").on("message").on("channel").hook(
|
|
|
|
self.highlight_spam)
|
2017-12-26 11:50:18 +00:00
|
|
|
|
|
|
|
bot.events.on("postboot").on("configure").on(
|
2018-08-28 13:55:08 +00:00
|
|
|
"channelset").assure_call(setting="highlight-spam-threshold",
|
2018-08-31 09:51:47 +00:00
|
|
|
help="Set the number of nicknames in a message that "
|
|
|
|
"qualifies as spam", validate=Utils.int_or_none)
|
2017-12-26 11:50:18 +00:00
|
|
|
bot.events.on("postboot").on("configure").on(
|
2018-08-28 13:55:08 +00:00
|
|
|
"channelset").assure_call(setting="highlight-spam-protection",
|
2018-08-31 09:51:47 +00:00
|
|
|
help="Enable/Disable highlight spam protection",
|
|
|
|
validate=Utils.bool_or_none)
|
2017-12-26 13:51:10 +00:00
|
|
|
bot.events.on("postboot").on("configure").on(
|
2018-08-28 13:55:08 +00:00
|
|
|
"channelset").assure_call(setting="highlight-spam-ban",
|
2018-08-31 09:51:47 +00:00
|
|
|
help="Enable/Disable banning highlight spammers "
|
|
|
|
"instead of just kicking", validate=Utils.bool_or_none)
|
2018-07-19 13:39:10 +00:00
|
|
|
bot.events.on("postboot").on("configure").on(
|
2018-08-28 13:55:08 +00:00
|
|
|
"channelset").assure_call(setting="ban-format",
|
2018-08-31 09:51:47 +00:00
|
|
|
help="Set ban format ($n = nick, $u = username, $h = hostname)")
|
2016-04-18 15:50:19 +00:00
|
|
|
|
|
|
|
def kick(self, event):
|
|
|
|
target = event["args_split"][0]
|
|
|
|
target_user = event["server"].get_user(target)
|
|
|
|
if event["args_split"][1:]:
|
|
|
|
reason = " ".join(event["args_split"][1:])
|
|
|
|
else:
|
|
|
|
reason = None
|
|
|
|
event["stderr"].set_prefix("Kick")
|
|
|
|
if event["target"].has_user(target_user):
|
|
|
|
if not event["server"].is_own_nickname(target):
|
|
|
|
event["target"].send_kick(target, reason)
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Nope.")
|
|
|
|
else:
|
|
|
|
event["stderr"].write("That user is not in this channel")
|
|
|
|
|
2018-07-19 13:39:10 +00:00
|
|
|
def _ban_format(self, user, s):
|
|
|
|
return s.replace("$n", user.nickname).replace("$u", user.username
|
2018-08-31 09:51:47 +00:00
|
|
|
).replace("$h", user.hostname)
|
2018-07-19 13:39:10 +00:00
|
|
|
def _ban(self, channel, ban, user):
|
|
|
|
format = channel.get_setting("ban-format", "*!$u@$h")
|
|
|
|
hostmask_split = format.split("$$")
|
|
|
|
hostmask_split = [self._ban_format(user, s) for s in hostmask_split]
|
|
|
|
hostmask = "".join(hostmask_split)
|
|
|
|
if ban:
|
|
|
|
channel.send_ban(hostmask)
|
|
|
|
else:
|
|
|
|
channel.send_unban(hostmask)
|
2016-04-18 15:50:19 +00:00
|
|
|
def ban(self, event):
|
|
|
|
target_user = event["server"].get_user(event["args_split"][0])
|
|
|
|
if event["target"].has_user(target_user):
|
2018-07-19 13:39:10 +00:00
|
|
|
self._ban(event["target"], True, target_user)
|
2016-04-18 15:50:19 +00:00
|
|
|
else:
|
|
|
|
event["target"].send_ban(event["args_split"][0])
|
2018-07-19 13:39:10 +00:00
|
|
|
def unban(self, event):
|
|
|
|
target_user = event["server"].get_user(event["args_split"][0])
|
|
|
|
if event["target"].has_user(target_user):
|
|
|
|
self._ban(event["target"], False, target_user)
|
|
|
|
else:
|
|
|
|
event["target"].send_unban(event["args_split"][0])
|
2016-04-18 15:50:19 +00:00
|
|
|
|
|
|
|
def kickban(self, event):
|
|
|
|
if event["server"].has_user(event["args_split"][0]):
|
|
|
|
self.ban(event)
|
|
|
|
self.kick(event)
|
2016-04-24 02:01:44 +00:00
|
|
|
else:
|
|
|
|
event["stderr"].write("That user is not in this channel")
|
2016-04-22 10:48:28 +00:00
|
|
|
|
|
|
|
def op(self, event):
|
2016-07-05 11:17:22 +00:00
|
|
|
target = event["user"].nickname if not event["args_split"] else event[
|
|
|
|
"args_split"][0]
|
|
|
|
event["target"].send_mode("+o", target)
|
2016-05-17 13:51:47 +00:00
|
|
|
def deop(self, event):
|
2016-07-05 11:17:22 +00:00
|
|
|
target = event["user"].nickname if not event["args_split"] else event[
|
|
|
|
"args_split"][0]
|
|
|
|
event["target"].send_mode("-o", target)
|
2016-05-17 13:51:47 +00:00
|
|
|
def voice(self, event):
|
2016-07-05 11:17:22 +00:00
|
|
|
target = event["user"].nickname if not event["args_split"] else event[
|
|
|
|
"args_split"][0]
|
|
|
|
event["target"].send_mode("+v", target)
|
2016-05-17 13:51:47 +00:00
|
|
|
def devoice(self, event):
|
2016-07-05 11:17:22 +00:00
|
|
|
target = event["user"].nickname if not event["args_split"] else event[
|
|
|
|
"args_split"][0]
|
|
|
|
event["target"].send_mode("-v", target)
|
2017-12-26 11:50:18 +00:00
|
|
|
|
|
|
|
def highlight_spam(self, event):
|
2018-08-06 13:27:49 +00:00
|
|
|
if event["channel"].get_setting("highlight-spam-protection", False):
|
|
|
|
nicknames = list(map(lambda user: user.nickname,
|
2018-08-31 09:51:47 +00:00
|
|
|
event["channel"].users)) + [event["server"].nickname]
|
2018-08-06 13:27:49 +00:00
|
|
|
|
2018-08-30 10:14:19 +00:00
|
|
|
highlights = set(nicknames) & set(event["message_split"])
|
|
|
|
if len(highlights) > 1 and len(highlights) >= event["channel"
|
2018-08-31 09:51:47 +00:00
|
|
|
].get_setting("highlight-spam-threshold", 10):
|
2018-08-06 13:27:49 +00:00
|
|
|
has_mode = event["channel"].mode_or_above(event["user"], "v")
|
|
|
|
should_ban = event["channel"].get_setting("highlight-spam-ban",
|
2018-08-31 09:51:47 +00:00
|
|
|
False)
|
2018-08-06 13:27:49 +00:00
|
|
|
if not has_mode:
|
|
|
|
if should_ban:
|
|
|
|
event["channel"].send_ban("*!%s@%s" % (
|
|
|
|
event["user"].username, event["user"].hostname))
|
|
|
|
event["channel"].send_kick(event["user"].nickname,
|
2018-08-31 09:51:47 +00:00
|
|
|
"highlight spam detected")
|