From 9f8a6254f9233bcc1fa0d6f85d60f3478cdad019 Mon Sep 17 00:00:00 2001 From: Merdal Kaymaz Date: Wed, 4 Feb 2015 21:11:04 +0100 Subject: [PATCH] Add topic sync. --- relaybot.config_sample | 1 + relaybot.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/relaybot.config_sample b/relaybot.config_sample index 37de2f4..212ed19 100644 --- a/relaybot.config_sample +++ b/relaybot.config_sample @@ -11,6 +11,7 @@ username=unit22 realname=Bender Bending Rodríguez heartbeat=90 nickcolor=True +synctopic=True [Freenode] host=irc.freenode.net diff --git a/relaybot.py b/relaybot.py index a90e387..7a2df86 100644 --- a/relaybot.py +++ b/relaybot.py @@ -38,7 +38,7 @@ def main(): return None options = {} - for option in [ "timeout", "host", "port", "nick", "channel", "heartbeat", "password", "username", "realname", "mode", "ssl", "fingerprint", "nickcolor" ]: + for option in [ "timeout", "host", "port", "nick", "channel", "heartbeat", "password", "username", "realname", "mode", "ssl", "fingerprint", "nickcolor", "synctopic" ]: options[option] = get(option) mode = get("mode") @@ -208,6 +208,7 @@ class IRCRelayer(irc.IRCClient): self.realname = config['realname'] self.mode = config['mode'] self.nickcolor = config['nickcolor'] + self.synctopic = config['synctopic'] log.msg("IRC Relay created. Name: %s | Host: %s | Channel: %s"%(self.nickname, self.network, self.channel)) # IRC RFC: https://tools.ietf.org/html/rfc2812#page-4 if len(self.nickname) > 9: @@ -251,10 +252,19 @@ class IRCRelayer(irc.IRCClient): log.msg("Kicked by %s. Message \"%s\""%(kicker, message)) communicator.unregister(self) - def action(self, user, channel, data): + def action(self, user, channel, message): if self.mode != "RelayByCommand": self.relay(":%s PRIVMSG %s :%s %s"%(user, channel, self.formatNick(user), message)) + def topicUpdated(self, user, channel, newTopic): + if self.mode != "RelayByCommand": + self.topic(user, channel, newTopic) + + def topic(self, user, channel, newTopic): + if self.synctopic != "True": + if self.mode != "RelayByCommand": + self.relay(":%s TOPIC %s :%s" %(user, channel, newTopic)) + class RelayFactory(ReconnectingClientFactory): protocol = IRCRelayer #Log information which includes reconnection status.