From a26db931b1dabb44ef4c6ed754a846ee5196d91f Mon Sep 17 00:00:00 2001 From: Thorsten S Date: Wed, 25 Mar 2020 21:50:10 +0100 Subject: [PATCH] move topic code to own function, fix off by one --- distbot/bot/bot.py | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/distbot/bot/bot.py b/distbot/bot/bot.py index 0bd6094..52ba923 100644 --- a/distbot/bot/bot.py +++ b/distbot/bot/bot.py @@ -107,6 +107,24 @@ class Bot(sleekxmpp.ClientXMPP): }) ) + def get_amqp_routing_key(self, msg): + # simplify the key significantly + key = shlex.split(re.sub(r'[^a-zäöüß0-9 "\']', '', msg["body"].lower())) + if not key: + # simple dots, smilies, emoji shit, pass through + key = shlex.split(msg["body"].lower()) + + # cut the nick from the message + if self.nick.lower() in key[0].lower(): + if msg["body"][0] == '>': + key.pop(0) + key.insert(0, "quoted_nick") + else: + key.pop(0) + key.insert(0, "nick") + routing_key = '.'.join(key)[:254] + return routing_key + def message(self, msg): logger.debug("msg is " + str(msg)) logger.debug("from: " + str(msg['from'])) @@ -123,30 +141,16 @@ class Bot(sleekxmpp.ClientXMPP): self.initialize_actionthreads() self.echo("Worker One available for master.") - # simplify the key significantly - key = shlex.split(re.sub(r'[^a-zäöüß0-9 "\']', '', msg["body"].lower())) - if not key: - # simple dots, smilies, emoji shit, pass through - key = shlex.split(msg["body"].lower()) - - # cut the nick from the message - offset = 0 - if self.nick.lower() in key[0].lower(): - if message[0] == '>': - key.pop(0) - key.insert(0, "quoted_nick") - else: - key.pop(0) - key.insert(0, "nick") - offset = message.find(self.nick) + len(self.nick) + 1 + routing_key = self.get_amqp_routing_key(msg) if msg["type"] == "groupchat": recipient = msg["mucroom"] else: recipient = msg["from"].jid + offset = msg["body"].find(self.nick) + len(self.nick) + 1 process_message( - routing_key='.'.join(key)[:255], + routing_key=routing_key, body=json.dumps({ "from": msg["from"].jid, "to": recipient, -- 2.39.2