From feeb18906f264bb5076b2e6da9c9578960fe9de0 Mon Sep 17 00:00:00 2001 From: vevv <68520787+vevv@users.noreply.github.com> Date: Tue, 6 Sep 2022 16:01:16 +0200 Subject: [PATCH] Support for decrypting channel topics --- hexfish/plugin.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/hexfish/plugin.py b/hexfish/plugin.py index 4ae2b27..cd56972 100644 --- a/hexfish/plugin.py +++ b/hexfish/plugin.py @@ -257,6 +257,8 @@ def __init__(self): xchat.hook_command('ME', self.on_send_me), xchat.hook_command('MSG', self.on_send_msg), xchat.hook_command('NOTICE', self.on_send_notice), + xchat.hook_server('332', self.on_recv_332, priority=xchat.PRI_HIGHEST), + xchat.hook_server('TOPIC', self.on_recv_topic, priority=xchat.PRI_HIGHEST), xchat.hook_server('notice', self.on_recv_notice, priority=xchat.PRI_HIGHEST), xchat.hook_print('Change Nick', self.on_change_nick), xchat.hook_unload(self.unload), @@ -444,6 +446,50 @@ def on_recv_notice(self, word, word_eol, userdata): return xchat.EAT_XCHAT return xchat.EAT_NONE + # noinspection PyUnreachableCode + def on_recv_topic(self, word, word_eol, userdata): + server, cmd, nick = word[0], word[1], word[2] + key_nick = self.get_nick() + topic = word_eol[3][1:].strip() + + key = None + try: + key = config['id_key', config['nick_id', key_nick]] + except Exception: + return xchat.EAT_NONE + + if not key or not topic.startswith('+OK'): + return xchat.EAT_NONE + + with suppress(ValueError, KeyError): + topic = self.decrypt(key_nick, topic) + xchat.command('RECV %s %s %s :%s' % (server, cmd, nick, topic)) + return xchat.EAT_ALL + + return xchat.EAT_NONE + + # noinspection PyUnreachableCode + def on_recv_332(self, word, word_eol, userdata): + server, cmd, nick, channel, topic = word[0], word[1], word[2], word[3], word_eol[4] + topic = topic[1:] + key_nick = self.get_nick() + + key = None + try: + key = config['id_key', config['nick_id', key_nick]] + except Exception: + return xchat.EAT_NONE + + if not key or not topic.startswith('+OK'): + return xchat.EAT_NONE + + with suppress(ValueError, KeyError): + topic = self.decrypt(key_nick, topic) + xchat.command('RECV %s %s %s %s :%s' % (server, cmd, nick, channel, topic)) + return xchat.EAT_ALL + + return xchat.EAT_NONE + # noinspection PyUnreachableCode def on_send_message(self, word, word_eol, userdata): nick = self.get_nick()