From 353b83d415061bff2881cbe324273409740be64c Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Fri, 24 Feb 2023 21:08:59 -0800 Subject: bot: implement delayed checkin, (kind of), some TODO left --- command.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'command.py') diff --git a/command.py b/command.py index e92dc1c..5ae99f6 100644 --- a/command.py +++ b/command.py @@ -3,6 +3,7 @@ from telegram.constants import ParseMode from telegram.error import BadRequest from telegram.ext import ContextTypes, ConversationHandler from dbstore.peewee_store import get_user_access_key, get_user_home_instance, delete_user_by_id, update_user_visibility +from dbstore.peewee_store import get_user_by_id, update_delayed_checkin from dbstore.peewee_store import TOOT_VISIBILITY_PRIVATE, TOOT_VISIBILITY_UNLISTED, TOOT_VISIBILITY_PUBLIC from config import * from util import check_user @@ -54,7 +55,27 @@ async def logout_command(update: Update, context: ContextTypes.DEFAULT_TYPE, use await update.message.reply_text(PROMPT_LOGOUT_SUCCESS, parse_mode=ParseMode.HTML, reply_markup=LOGIN_MENU) -@check_user +async def delayed_checkin_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: + await update.message.reply_text(PROMPT_DELAYED_CHECKIN, parse_mode=ParseMode.HTML) + return DELAYED_CHECKIN + + +async def callback_delayed_checkin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: + try: + delayed_minutes = int(update.effective_message.text) + except ValueError: + await update.message.edit_text(text="Integer expected, try again") + return DELAYED_CHECKIN + + if delayed_minutes < 5: + delayed_minutes = 0 + + update_delayed_checkin(str(update.effective_user.id), delayed_minutes) + u = get_user_by_id(str(update.effective_user.id)) + await update.message.reply_text(text=f"Delayed check-in set to {u['delayed_checkin']} minutes") + return ConversationHandler.END + + async def toggle_visibility_command(update: Update, context: ContextTypes.DEFAULT_TYPE, user: User) -> int: visibility_menu = InlineKeyboardMarkup([ [InlineKeyboardButton("Private", callback_data=TOOT_VISIBILITY_PRIVATE)], -- cgit v1.2.3