Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make atomic callback handlers async #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/commands/general.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/commands/meal.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

import telegram
from telegram.ext import run_async

from util.const import (
BREAKFAST,
Expand All @@ -10,14 +11,14 @@
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


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)
Expand Down
4 changes: 4 additions & 0 deletions src/commands/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import telegram
from telegram.ext import run_async

from util.const import (
BREAKFAST,
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down