From a86ac99f7deeb5dfb814141a47c029d2a83104d9 Mon Sep 17 00:00:00 2001 From: Remy Moll Date: Sun, 22 Aug 2021 13:43:13 +0200 Subject: [PATCH] bugfixes due to threading --- bot/commands/help.py | 4 ++-- bot/commands/reddit.py | 9 ++++----- bot/commands/search.py | 8 +++++--- bot/main.py | 1 - broadcast/b_out.py | 8 ++++++++ launcher.py | 4 ++-- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/bot/commands/help.py b/bot/commands/help.py index 71d3869..d96949c 100644 --- a/bot/commands/help.py +++ b/bot/commands/help.py @@ -59,7 +59,7 @@ class Help(BotFunc): query.answer() all_cmd = "" for h in self.available_commands: - all_cmd += h + " - `" + self.available_commands[h] + "`\n" + all_cmd += "{} - `{}`\n".format(h, self.available_commands[h]) query.edit_message_text(text="List of all commands:\n" + all_cmd, parse_mode = ParseMode.MARKDOWN) return ConversationHandler.END @@ -120,7 +120,7 @@ class Help(BotFunc): message = name + ": `" + self.available_commands[name] + "`" query.edit_message_text( - text= "EHHHHH", + text= "Timed out...", parse_mode = ParseMode.MARKDOWN_V2 ) return ConversationHandler.END \ No newline at end of file diff --git a/bot/commands/reddit.py b/bot/commands/reddit.py index a0f66f0..88c10e0 100644 --- a/bot/commands/reddit.py +++ b/bot/commands/reddit.py @@ -5,8 +5,8 @@ CHOOSE_NUM = 1 class Joke(BotFunc): """Tells a joke from reddit.""" - def __init__(self, api, prst): - super().__init__(prst) + def __init__(self, api, db): + super().__init__(db) self.available_commands = {} self.api = api @@ -53,8 +53,8 @@ CHOOSE_TOPIC = 0 class Meme(BotFunc): """Gets the latest memes from reddit""" - def __init__(self, api, prst): - super().__init__(prst) + def __init__(self, api, db): + super().__init__(db) self.available_commands = {} self.api = api @@ -87,7 +87,6 @@ class Meme(BotFunc): def choose_topic(self, update: Update, context: CallbackContext) -> None: - super().entry_point() query = update.callback_query d = query.data query.answer() diff --git a/bot/commands/search.py b/bot/commands/search.py index 2038f24..ac3ab66 100644 --- a/bot/commands/search.py +++ b/bot/commands/search.py @@ -38,9 +38,11 @@ class Search(BotFunc): # formating self.results = results - first = results[0] - message = first["text"] + "\n(" + first["url"] + ")\n\n" - + if results: + first = results[0] + message = first["text"] + "\n(" + first["url"] + ")\n\n" + else: + message = "No results for search query." update.message.reply_text(text = message, reply_markup=reply_markup) super().log_activity(read = True, execute = True, send = True) return MORE diff --git a/bot/main.py b/bot/main.py index 721c50a..ee39145 100644 --- a/bot/main.py +++ b/bot/main.py @@ -50,7 +50,6 @@ class ChatBot(): # "news" : self.commands.reddit.News(self.api_reddit, db), "search" : self.commands.search.Search(self.api_search, db), # ... - "plaintext" : self.commands.plaintext.Plain(db) # for handling non-command messages that should simply contribute to statistics } # must be a class that has a method create_handler diff --git a/broadcast/b_out.py b/broadcast/b_out.py index 79fe36e..229778c 100644 --- a/broadcast/b_out.py +++ b/broadcast/b_out.py @@ -4,6 +4,14 @@ import numpy as np from threading import Thread +import logging +log = logging.getLogger('werkzeug') +log.setLevel(logging.ERROR) +# hide the info-messages of each GET-request + + + + class BroadcastUpdates: """Broadcasts (out) updates for the hw-handler to be fetched periodically""" diff --git a/launcher.py b/launcher.py index b58771f..30af97c 100644 --- a/launcher.py +++ b/launcher.py @@ -12,7 +12,7 @@ class Launcher: def __init__(self, **modules): """""" self.persistence = p_io.PersistentDict("persistence/prst.json") - self.db = p_out.DBLogging() + self.db = p_out.DBLogging logger.info(self.__class__.__name__ + " initialized") @@ -31,7 +31,7 @@ class Launcher: logger.info("Starting module "+ module.__class__.__name__) module.modules = self.modules module.persistence = self.persistence - module.db = self.db + module.db = self.db() # newly initialized for every module module.start()