diff --git a/src/bot.py b/src/bot.py index b52e3da..6b122ee 100644 --- a/src/bot.py +++ b/src/bot.py @@ -42,7 +42,7 @@ def main(): """Start the bot.""" # Set use_context=True to use the new context based callbacks - updater = Updater(token=os.getenv('RC_DINING_BOT_TOKEN'), use_context=True) + updater = Updater(token=os.getenv('RC_DINING_BOT_TOKEN'), use_context=True, workers=32) # Get the dispatcher to dispatcher = updater.dispatcher diff --git a/src/commands/general.py b/src/commands/general.py index cfae1f2..2e430fd 100644 --- a/src/commands/general.py +++ b/src/commands/general.py @@ -1,10 +1,12 @@ import telegram +from telegram.ext import run_async from util.kb_mark_up import start_kb, start_button_kb from util.messages import welcome_msg, help_msg import logging +@run_async def handle_start(update, context): if update.callback_query is not None: context.bot.answer_callback_query(update.callback_query.id) @@ -14,6 +16,7 @@ def handle_start(update, context): parse_mode=telegram.ParseMode.HTML) +@run_async def handle_help(update, context): if update.callback_query is not None: context.bot.answer_callback_query(update.callback_query.id) diff --git a/src/commands/meal.py b/src/commands/meal.py index 6319125..f5de830 100644 --- a/src/commands/meal.py +++ b/src/commands/meal.py @@ -1,6 +1,7 @@ import logging import telegram +from telegram.ext import run_async from util.const import ( BREAKFAST, @@ -10,7 +11,6 @@ from util.util import parse_menu, localized_date_today from database.database import get_raw_menu, get_hidden_cuisines from util.kb_mark_up import start_button_kb -from datetime import date from dateparser import parse @@ -18,6 +18,7 @@ def handle_menu(meal): assert meal == BREAKFAST or meal == DINNER, "Meal input is incorrect." # in this function, parsed_date returns date in Singapore time. As such, no conversion is required. + @run_async def get_breakfast_or_dinner_menu(update, context): if update.callback_query is not None: context.bot.answer_callback_query(update.callback_query.id) diff --git a/src/commands/settings.py b/src/commands/settings.py index 1d5467a..ac66c88 100644 --- a/src/commands/settings.py +++ b/src/commands/settings.py @@ -1,4 +1,5 @@ import telegram +from telegram.ext import run_async from util.const import ( BREAKFAST, @@ -20,6 +21,7 @@ # settings menu +@run_async def handle_settings(update, context): if update.callback_query is not None: context.bot.answer_callback_query(update.callback_query.id) @@ -30,6 +32,7 @@ def handle_settings(update, context): # hidden cuisine panel +@run_async def handle_hidden_cuisine(update, context): if update.callback_query is not None: context.bot.answer_callback_query(update.callback_query.id) @@ -52,6 +55,7 @@ def handle_hide_cuisine(update, context): update.callback_query.edit_message_reply_markup(reply_markup=hidden_cuisine_kb(updated_hidden_cuisine)) +@run_async def handle_notification(update, context): if update.callback_query is not None: context.bot.answer_callback_query(update.callback_query.id)