From: Thorsten Date: Wed, 17 Jan 2024 07:17:34 +0000 (+0100) Subject: filter whitespace from wp responses X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=c2423ba21484aa86a8c4c13dbaf131209fcdbfb3;p=urlbot-v3.git filter whitespace from wp responses --- 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: