From c2423ba21484aa86a8c4c13dbaf131209fcdbfb3 Mon Sep 17 00:00:00 2001 From: Thorsten Date: Wed, 17 Jan 2024 08:17:34 +0100 Subject: [PATCH] filter whitespace from wp responses --- distbot/bot/bot.py | 4 ++-- distbot/plugins/lookup.py | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/distbot/bot/bot.py b/distbot/bot/bot.py index 51590ab..e337e13 100644 --- a/distbot/bot/bot.py +++ b/distbot/bot/bot.py @@ -128,7 +128,7 @@ class Bot(slixmpp.ClientXMPP): key.insert(0, "nick") offset = msg["body"].find(nick) + len(nick) + 1 routing_key = '.'.join(key).encode("UTF-8")[:255] - + logging.debug(f"Routing key for message {msg['body']} -> {routing_key}") return offset, routing_key def message(self, msg): @@ -177,7 +177,7 @@ class Bot(slixmpp.ClientXMPP): }) ) - def echo(self, body, recipient=None): + def echo(self, body: str, recipient: str = None): logger.debug("echo: %s", body) if not recipient: rooms = self.rooms diff --git a/distbot/plugins/lookup.py b/distbot/plugins/lookup.py index 0baa538..547b762 100644 --- a/distbot/plugins/lookup.py +++ b/distbot/plugins/lookup.py @@ -4,6 +4,7 @@ Plugins related to looking things up """ import logging +import re import traceback import unicodedata @@ -11,7 +12,6 @@ import requests from distbot.bot.worker import Worker from distbot.common.action import Action -from distbot.common.config import conf_get from distbot.common.message import get_nick_from_message, get_words @@ -145,9 +145,8 @@ class Wikipedia(Worker): return Action(msg='{}: something failed: {}'.format(sender, e)) if short: - return Action(msg=sender + ': %s (<%s>)' % ( - short if short.strip() else '(nix)', link - )) + text = re.sub(r"(\\n|\s)+", " ", short) if short.strip() else '(nix)' + return Action(msg=sender + ': %s (<%s>)' % (text, link)) elif 'missing' in page: return Action(msg='Article "%s" not found' % page.get('title', query)) else: -- 2.39.2