From 73bdaff9772ee52f96d45503548356db473102b2 Mon Sep 17 00:00:00 2001 From: jesopo Date: Thu, 6 Sep 2018 17:25:38 +0100 Subject: [PATCH] Add !topic and !topicappend in channel_op.py --- IRCChannel.py | 2 ++ modules/channel_op.py | 54 +++++++++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/IRCChannel.py b/IRCChannel.py index 11a5bf9e..0dfd6884 100644 --- a/IRCChannel.py +++ b/IRCChannel.py @@ -113,6 +113,8 @@ class Channel(object): self.server.send_mode(self.name, "+b", hostmask) def send_unban(self, hostmask): self.server.send_mode(self.name, "-b", hostmask) + def send_topic(self, topic): + self.server.send_topic(self.name, topic) def mode_or_above(self, user, mode): mode_orders = list(self.server.mode_prefixes.values()) diff --git a/modules/channel_op.py b/modules/channel_op.py index 7f80d5b3..1cdc4e15 100644 --- a/modules/channel_op.py +++ b/modules/channel_op.py @@ -4,41 +4,44 @@ class Module(object): _name = "Channel Op" def __init__(self, bot, events, exports): self.bot = bot - events.on("received").on("command").on("kick", "k" - ).hook(self.kick, channel_only=True, require_mode="o", - min_args=1, help="Kick a user from the channel", - usage=" [reason]") - events.on("received").on("command").on("ban" - ).hook(self.ban, channel_only=True, require_mode="o", - min_args=1, help="Ban a user/hostmask from the channel", - usage="") - events.on("received").on("command").on("unban" - ).hook(self.unban, channel_only=True, require_mode="o", - min_args=1, help="Unban a user/hostmask from the channel", - usage="") + events.on("received.command").on("kick", "k").hook(self.kick, + channel_only=True, require_mode="o", usage=" [reason]", + min_args=1, help="Kick a user from the channel") + events.on("received.command.ban").hook(self.ban, channel_only=True, + require_mode="o", min_args=1, usage="", + help="Ban a user/hostmask from the channel") + events.on("received.command.unban").hook(self.unban, + channel_only=True, require_mode="o", usage="", + min_args=1, help="Unban a user/hostmask from the channel") - events.on("received").on("command").on("kickban", "kb" + events.on("received.command").on("kickban", "kb" ).hook(self.kickban, channel_only=True, require_mode="o", min_args=1, help="Kickban a user from the channel", usage=" [reason]") - events.on("received").on("command").on("op" + events.on("received.command.op" ).hook(self.op, channel_only=True, require_mode="o", help="Give +o to a user", usage="[nickname]") - events.on("received").on("command").on("deop" + events.on("received.command.deop" ).hook(self.deop, channel_only=True, require_mode="o", help="Take +o from a user", usage="[nickname]") - events.on("received").on("command").on("voice" - ).hook(self.voice, channel_only=True, require_mode="o", - help="Give +v to a user", usage="[nickname]") - events.on("received").on("command").on("devoice" - ).hook(self.devoice, channel_only=True, require_mode="o", - help="Take +v from a user", usage="[nickname]") + events.on("received.command.voice").hook(self.voice, + channel_only=True, require_mode="o", usage="[nickname]", + help="Give +v to a user") + events.on("received.command.devoice").hook(self.devoice, + channel_only=True, require_mode="o", usage="[nickname]", + help="Take +v from a user") - events.on("received").on("message").on("channel").hook( - self.highlight_spam) + events.on("received.command.topic").hook(self.topic, min_args=1, + require_mode="o", channel_only=True, usage="", + help="Set the topic of the current channel") + events.on("received.command").on("topicappend", "tappend").hook( + self.tappend, min_args=1, require_mode="o", channel_only=True, + usage="", help="Set the topic of the current channel") + + events.on("received.message.channel").hook(self.highlight_spam) exports.add("channelset", {"setting": "highlight-spam-threshold", "help": "Set the number of nicknames in a message that " @@ -118,6 +121,11 @@ class Module(object): "args_split"][0] event["target"].send_mode("-v", target) + def topic(self, event): + event["target"].send_topic(event["args"]) + def tappend(self, event): + event["target"].send_topic(event["target"].topic + event["args"]) + def highlight_spam(self, event): if event["channel"].get_setting("highlight-spam-protection", False): nicknames = list(map(lambda user: user.nickname,