diff options
author | clarkzjw <[email protected]> | 2023-02-24 21:08:59 -0800 |
---|---|---|
committer | clarkzjw <[email protected]> | 2023-02-28 15:58:02 -0800 |
commit | 353b83d415061bff2881cbe324273409740be64c (patch) | |
tree | 420fa402e7eda3425fd69b24959cffb0b2cc5039 /command.py | |
parent | 0041eb4f9893687565e444be9d50648f49aa4d91 (diff) | |
download | swarm2fediverse-feature/delayed_checkin.tar.gz |
bot: implement delayed checkin, (kind of), some TODO leftfeature/delayed_checkin
Diffstat (limited to 'command.py')
-rw-r--r-- | command.py | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -3,6 +3,7 @@ from telegram.constants import ParseMode | |||
3 | from telegram.error import BadRequest | 3 | from telegram.error import BadRequest |
4 | from telegram.ext import ContextTypes, ConversationHandler | 4 | from telegram.ext import ContextTypes, ConversationHandler |
5 | from dbstore.peewee_store import get_user_access_key, get_user_home_instance, delete_user_by_id, update_user_visibility | 5 | from dbstore.peewee_store import get_user_access_key, get_user_home_instance, delete_user_by_id, update_user_visibility |
6 | from dbstore.peewee_store import get_user_by_id, update_delayed_checkin | ||
6 | from dbstore.peewee_store import TOOT_VISIBILITY_PRIVATE, TOOT_VISIBILITY_UNLISTED, TOOT_VISIBILITY_PUBLIC | 7 | from dbstore.peewee_store import TOOT_VISIBILITY_PRIVATE, TOOT_VISIBILITY_UNLISTED, TOOT_VISIBILITY_PUBLIC |
7 | from config import * | 8 | from config import * |
8 | from util import check_user | 9 | from util import check_user |
@@ -54,7 +55,27 @@ async def logout_command(update: Update, context: ContextTypes.DEFAULT_TYPE, use | |||
54 | await update.message.reply_text(PROMPT_LOGOUT_SUCCESS, parse_mode=ParseMode.HTML, reply_markup=LOGIN_MENU) | 55 | await update.message.reply_text(PROMPT_LOGOUT_SUCCESS, parse_mode=ParseMode.HTML, reply_markup=LOGIN_MENU) |
55 | 56 | ||
56 | 57 | ||
57 | @check_user | 58 | async def delayed_checkin_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |
59 | await update.message.reply_text(PROMPT_DELAYED_CHECKIN, parse_mode=ParseMode.HTML) | ||
60 | return DELAYED_CHECKIN | ||
61 | |||
62 | |||
63 | async def callback_delayed_checkin(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | ||
64 | try: | ||
65 | delayed_minutes = int(update.effective_message.text) | ||
66 | except ValueError: | ||
67 | await update.message.edit_text(text="Integer expected, try again") | ||
68 | return DELAYED_CHECKIN | ||
69 | |||
70 | if delayed_minutes < 5: | ||
71 | delayed_minutes = 0 | ||
72 | |||
73 | update_delayed_checkin(str(update.effective_user.id), delayed_minutes) | ||
74 | u = get_user_by_id(str(update.effective_user.id)) | ||
75 | await update.message.reply_text(text=f"Delayed check-in set to {u['delayed_checkin']} minutes") | ||
76 | return ConversationHandler.END | ||
77 | |||
78 | |||
58 | async def toggle_visibility_command(update: Update, context: ContextTypes.DEFAULT_TYPE, user: User) -> int: | 79 | async def toggle_visibility_command(update: Update, context: ContextTypes.DEFAULT_TYPE, user: User) -> int: |
59 | visibility_menu = InlineKeyboardMarkup([ | 80 | visibility_menu = InlineKeyboardMarkup([ |
60 | [InlineKeyboardButton("Private", callback_data=TOOT_VISIBILITY_PRIVATE)], | 81 | [InlineKeyboardButton("Private", callback_data=TOOT_VISIBILITY_PRIVATE)], |