From 3ec521538a982b59009896e41edb34c3205c057c Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 29 Aug 2018 14:57:40 +0100 Subject: [PATCH] Print topics in print_activity.py --- IRCLineHandler.py | 23 +++++++++++++++++++---- modules/print_activity.py | 11 +++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/IRCLineHandler.py b/IRCLineHandler.py index 6ca846dc..b845691d 100644 --- a/IRCLineHandler.py +++ b/IRCLineHandler.py @@ -16,8 +16,7 @@ class LineHandler(object): bot.events.on("raw").on("005").hook(self.handle_005) bot.events.on("raw").on("311").hook(self.handle_311, default_event=True) - bot.events.on("raw").on("332").hook(self.handle_332, - default_event=True) + bot.events.on("raw").on("332").hook(self.handle_332) bot.events.on("raw").on("333").hook(self.handle_333, default_event=True) bot.events.on("raw").on("353").hook(self.handle_353, @@ -44,6 +43,7 @@ class LineHandler(object): bot.events.on("raw").on("MODE").hook(self.mode) bot.events.on("raw").on("KICK").hook(self.kick) bot.events.on("raw").on("INVITE").hook(self.invite) + bot.events.on("raw").on("TOPIC").hook(self.topic) bot.events.on("raw").on("PRIVMSG").hook(self.privmsg) bot.events.on("raw").on("NOTICE").hook(self.notice) @@ -132,8 +132,23 @@ class LineHandler(object): # on-join channel topic line def handle_332(self, event): - event["server"].get_channel(event["args"][1]).set_topic( - event["arbitrary"]) + channel = event["server"].get_channel(event["args"][1]) + + channel.set_topic(event["arbitrary"]) + self.bot.events.on("received").on("numeric").on("332" + ).call(channel=channel, server=event["server"], + topic=event["arbitrary"], setter=event["args"][0]) + + # channel topic changed + def topic(self, event): + nickname, username, hostname = Utils.seperate_hostmask( + event["prefix"]) + user = event["server"].get_user(nickname) + channel = event["server"].get_channel(event["args"][0]) + + channel.set_topic(event["arbitrary"]) + self.bot.events.on("received").on("topic").call(channel=channel, + server=event["server"], topic=event["arbitrary"], user=user) # on-join channel topic set by/at def handle_333(self, event): diff --git a/modules/print_activity.py b/modules/print_activity.py index 21ce9796..90e343ef 100644 --- a/modules/print_activity.py +++ b/modules/print_activity.py @@ -31,6 +31,9 @@ class Module(object): bot.events.on("received").on("kick").hook(self.kick) bot.events.on("self").on("kick").hook(self.self_kick) + bot.events.on("received").on("topic").hook(self.on_topic) + bot.events.on("received").on("numeric").on("332").hook(self.on_332) + def print_line(self, event, line, channel=None): timestamp = datetime.datetime.now().isoformat() target = str(event["server"]) @@ -101,3 +104,11 @@ class Module(object): self._on_kick(event, event["target_user"].nickname) def self_kick(self, event): self._on_kick(event, event["server"].nickname) + + def _on_topic(self, setter, event): + self.print_line(event, "topic set by %s: %s" % (setter, + event["topic"]), channel=event["channel"].name) + def on_topic(self, event): + self._on_topic(event["user"].nickname, event) + def on_332(self, event): + self._on_topic(event["setter"], event)