From 807dee5af18ae578ec27e61c34af06773940c9b3 Mon Sep 17 00:00:00 2001 From: dymik739 Date: Wed, 27 Sep 2023 08:27:38 +0300 Subject: [PATCH] core: prioritize processing commands over processing all other messages --- main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index ec6ccda..de63159 100644 --- a/main.py +++ b/main.py @@ -15,6 +15,8 @@ DELAY_AFTER_RESPONSE = 3 DELAY_AFTER_MESSAGE = 0.1 DELAY_AFTER_IDLE = 1.0 +lock = threading.Lock() + # some functions that increase readability of the code def readfile(filename): try: @@ -272,8 +274,14 @@ def queue_processor(): # telegram bot processor def message_handler(update, context): - print("[DEBUG] Received new message") # just for testing - message_queue.append(update.message) + global lock + with lock: + if update.message.text.__class__ == str and update.message.text.startswith("$"): + print("[DEBUG] Received new message with high priority") # just for testing + message_queue.insert(0, update.message) + else: + print("[DEBUG] Received new message") # just for testing + message_queue.append(update.message) # --- Final stage ---