Skip to content

Commit

Permalink
Added message sending on subscription accept
Browse files Browse the repository at this point in the history
  • Loading branch information
revolter committed Feb 8, 2022
1 parent fd4db40 commit ccb2889
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def subscribe_command_handler(update: telegram.Update, context: telegram.ext.Cal
return

bot = context.bot

chat_id = message.chat_id
user = message.from_user

if user is None:
Expand All @@ -179,6 +181,12 @@ def subscribe_command_handler(update: telegram.Update, context: telegram.ext.Cal
text=subscription_update_message
)

utils.send_subscription_accepted_message_if_needed(
bot=bot,
user=user,
chat_id=chat_id
)


def restart_command_handler(update: telegram.Update, context: telegram.ext.CallbackContext) -> None:
message = update.message
Expand Down Expand Up @@ -529,6 +537,12 @@ def message_answer_handler(update: telegram.Update, context: telegram.ext.Callba
chat_id=ADMIN_USER_ID,
text=subscription_update_message
)

utils.send_subscription_accepted_message_if_needed(
bot=bot,
user=user,
chat_id=chat_id
)
else:
query: typing.Optional[str] = callback_data[constants.BUTTON_DATA_QUERY_KEY]
offset = callback_data[constants.BUTTON_DATA_OFFSET_KEY]
Expand Down
15 changes: 15 additions & 0 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,21 @@ def send_subscription_onboarding_message_if_needed(bot: telegram.Bot, user: tele
)


def send_subscription_accepted_message_if_needed(bot: telegram.Bot, user: telegram.User, chat_id: int) -> None:
db_user = database.User.get_or_none(database.User.telegram_id == user.id)

if db_user is None:
return

if db_user.subscription != database.User.Subscription.accepted.value:
return

bot.send_message(
chat_id=chat_id,
text='Te-ai abonat să primești cuvântul zilei!',
)


def get_subscription_onboarding_inline_keyboard_buttons() -> typing.List[typing.List[telegram.InlineKeyboardButton]]:
no_data = {
constants.BUTTON_DATA_IS_SUBSCRIPTION_ONBOARDING_KEY: True,
Expand Down

0 comments on commit ccb2889

Please sign in to comment.