Skip to content

Commit

Permalink
Make callback handlers that are atomic async
Browse files Browse the repository at this point in the history
  • Loading branch information
moziliar committed Feb 18, 2020
1 parent c44fd7d commit c580105
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
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,4 +1,5 @@
import telegram
from telegram.ext import run_async

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

0 comments on commit c580105

Please sign in to comment.