bugfixes due to threading
This commit is contained in:
		| @@ -59,7 +59,7 @@ class Help(BotFunc): | |||||||
|         query.answer() |         query.answer() | ||||||
|         all_cmd = "" |         all_cmd = "" | ||||||
|         for h in self.available_commands: |         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) |         query.edit_message_text(text="List of all commands:\n" + all_cmd, parse_mode = ParseMode.MARKDOWN) | ||||||
|         return ConversationHandler.END |         return ConversationHandler.END | ||||||
| @@ -120,7 +120,7 @@ class Help(BotFunc): | |||||||
|  |  | ||||||
|         message = name + ": `" + self.available_commands[name] + "`" |         message = name + ": `" + self.available_commands[name] + "`" | ||||||
|         query.edit_message_text( |         query.edit_message_text( | ||||||
|             text= "EHHHHH", |             text= "Timed out...", | ||||||
|             parse_mode = ParseMode.MARKDOWN_V2 |             parse_mode = ParseMode.MARKDOWN_V2 | ||||||
|         ) |         ) | ||||||
|         return ConversationHandler.END |         return ConversationHandler.END | ||||||
| @@ -5,8 +5,8 @@ CHOOSE_NUM = 1 | |||||||
| class Joke(BotFunc): | class Joke(BotFunc): | ||||||
|     """Tells a joke from reddit.""" |     """Tells a joke from reddit.""" | ||||||
|      |      | ||||||
|     def __init__(self, api, prst): |     def __init__(self, api, db): | ||||||
|         super().__init__(prst) |         super().__init__(db) | ||||||
|         self.available_commands = {} |         self.available_commands = {} | ||||||
|         self.api = api |         self.api = api | ||||||
|  |  | ||||||
| @@ -53,8 +53,8 @@ CHOOSE_TOPIC = 0 | |||||||
| class Meme(BotFunc): | class Meme(BotFunc): | ||||||
|     """Gets the latest memes from reddit""" |     """Gets the latest memes from reddit""" | ||||||
|      |      | ||||||
|     def __init__(self, api, prst): |     def __init__(self, api, db): | ||||||
|         super().__init__(prst) |         super().__init__(db) | ||||||
|         self.available_commands = {} |         self.available_commands = {} | ||||||
|         self.api = api |         self.api = api | ||||||
|  |  | ||||||
| @@ -87,7 +87,6 @@ class Meme(BotFunc): | |||||||
|  |  | ||||||
|  |  | ||||||
|     def choose_topic(self, update: Update, context: CallbackContext) -> None: |     def choose_topic(self, update: Update, context: CallbackContext) -> None: | ||||||
|         super().entry_point() |  | ||||||
|         query = update.callback_query |         query = update.callback_query | ||||||
|         d = query.data |         d = query.data | ||||||
|         query.answer() |         query.answer() | ||||||
|   | |||||||
| @@ -38,9 +38,11 @@ class Search(BotFunc): | |||||||
|          |          | ||||||
|         # formating |         # formating | ||||||
|         self.results = results |         self.results = results | ||||||
|  |         if results: | ||||||
|             first = results[0] |             first = results[0] | ||||||
|             message = first["text"] + "\n(" + first["url"] + ")\n\n" |             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) |         update.message.reply_text(text = message, reply_markup=reply_markup) | ||||||
|         super().log_activity(read = True, execute = True, send = True) |         super().log_activity(read = True, execute = True, send = True) | ||||||
|         return MORE |         return MORE | ||||||
|   | |||||||
| @@ -50,7 +50,6 @@ class ChatBot(): | |||||||
|             # "news" : self.commands.reddit.News(self.api_reddit, db), |             # "news" : self.commands.reddit.News(self.api_reddit, db), | ||||||
|             "search" : self.commands.search.Search(self.api_search, 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 |             "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 |         # must be a class that has a method create_handler | ||||||
|   | |||||||
| @@ -4,6 +4,14 @@ import numpy as np | |||||||
| from threading import Thread | from threading import Thread | ||||||
|  |  | ||||||
|  |  | ||||||
|  | import logging | ||||||
|  | log = logging.getLogger('werkzeug') | ||||||
|  | log.setLevel(logging.ERROR) | ||||||
|  | # hide the info-messages of each GET-request | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class BroadcastUpdates: | class BroadcastUpdates: | ||||||
|     """Broadcasts (out) updates for the hw-handler to be fetched periodically""" |     """Broadcasts (out) updates for the hw-handler to be fetched periodically""" | ||||||
|      |      | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ class Launcher: | |||||||
|     def __init__(self, **modules): |     def __init__(self, **modules): | ||||||
|         """""" |         """""" | ||||||
|         self.persistence = p_io.PersistentDict("persistence/prst.json") |         self.persistence = p_io.PersistentDict("persistence/prst.json") | ||||||
|         self.db = p_out.DBLogging() |         self.db = p_out.DBLogging | ||||||
|  |  | ||||||
|         logger.info(self.__class__.__name__ + " initialized") |         logger.info(self.__class__.__name__ + " initialized") | ||||||
|  |  | ||||||
| @@ -31,7 +31,7 @@ class Launcher: | |||||||
|             logger.info("Starting module "+ module.__class__.__name__) |             logger.info("Starting module "+ module.__class__.__name__) | ||||||
|             module.modules = self.modules |             module.modules = self.modules | ||||||
|             module.persistence = self.persistence |             module.persistence = self.persistence | ||||||
|             module.db = self.db |             module.db = self.db() # newly initialized for every module | ||||||
|             module.start() |             module.start() | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Remy Moll
					Remy Moll