diff options
Diffstat (limited to 'command.py')
-rw-r--r-- | command.py | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -1,11 +1,11 @@ | |||
1 | from telegram import Update | 1 | from telegram import Update, User |
2 | from telegram.constants import ParseMode | 2 | 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 | ||
7 | from dbstore.peewee_store import TOOT_VISIBILITY_PRIVATE, TOOT_VISIBILITY_UNLISTED, TOOT_VISIBILITY_PUBLIC | 6 | from dbstore.peewee_store import TOOT_VISIBILITY_PRIVATE, TOOT_VISIBILITY_UNLISTED, TOOT_VISIBILITY_PUBLIC |
8 | from config import * | 7 | from config import * |
8 | from util import check_user | ||
9 | 9 | ||
10 | 10 | ||
11 | async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 11 | async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |
@@ -34,10 +34,11 @@ async def tos_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> Non | |||
34 | await update.message.reply_text(PROMPT_TOS, parse_mode=ParseMode.HTML, reply_markup=MAIN_MENU) | 34 | await update.message.reply_text(PROMPT_TOS, parse_mode=ParseMode.HTML, reply_markup=MAIN_MENU) |
35 | 35 | ||
36 | 36 | ||
37 | @check_user | ||
37 | async def list_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | 38 | async def list_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: |
38 | result = get_user_home_instance(str(update.effective_user.id)) | 39 | result = get_user_home_instance(str(update.effective_user.id)) |
39 | if len(result) == 0: | 40 | if len(result) == 0: |
40 | await update.message.reply_text(PROMPT_LIST_NO_RESULT, parse_mode=ParseMode.HTML) | 41 | pass |
41 | else: | 42 | else: |
42 | await update.message.reply_text(f"You are linked with the following Fediverse accounts:\n\n" | 43 | await update.message.reply_text(f"You are linked with the following Fediverse accounts:\n\n" |
43 | f"<b>Instance</b>: {result['home_instance']}\n" | 44 | f"<b>Instance</b>: {result['home_instance']}\n" |
@@ -47,26 +48,28 @@ async def list_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> No | |||
47 | reply_markup=MAIN_MENU) | 48 | reply_markup=MAIN_MENU) |
48 | 49 | ||
49 | 50 | ||
51 | @check_user | ||
50 | async def logout_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | 52 | async def logout_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: |
51 | if delete_user_by_id(str(update.effective_user.id)): | 53 | if delete_user_by_id(str(update.effective_user.id)): |
52 | await update.message.reply_text(PROMPT_LOGOUT_SUCCESS, parse_mode=ParseMode.HTML, reply_markup=LOGIN_MENU) | 54 | await update.message.reply_text(PROMPT_LOGOUT_SUCCESS, parse_mode=ParseMode.HTML, reply_markup=LOGIN_MENU) |
53 | 55 | ||
54 | 56 | ||
55 | async def toggle_visibility_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 57 | @check_user |
58 | async def toggle_visibility_command(update: Update, context: ContextTypes.DEFAULT_TYPE, user: User) -> int: | ||
56 | visibility_menu = InlineKeyboardMarkup([ | 59 | visibility_menu = InlineKeyboardMarkup([ |
57 | [InlineKeyboardButton("Private", callback_data=TOOT_VISIBILITY_PRIVATE)], | 60 | [InlineKeyboardButton("Private", callback_data=TOOT_VISIBILITY_PRIVATE)], |
58 | [InlineKeyboardButton("Unlisted", callback_data=TOOT_VISIBILITY_UNLISTED)], | 61 | [InlineKeyboardButton("Unlisted", callback_data=TOOT_VISIBILITY_UNLISTED)], |
59 | [InlineKeyboardButton("Public", callback_data=TOOT_VISIBILITY_PUBLIC)] | 62 | [InlineKeyboardButton("Public", callback_data=TOOT_VISIBILITY_PUBLIC)] |
60 | ]) | 63 | ]) |
61 | 64 | ||
62 | user = get_user_by_id(str(update.effective_user.id)) | ||
63 | await update.message.reply_text(PROMPT_TOGGLE_VIS.format(user["toot_visibility"]), | 65 | await update.message.reply_text(PROMPT_TOGGLE_VIS.format(user["toot_visibility"]), |
64 | parse_mode=ParseMode.HTML, | 66 | parse_mode=ParseMode.HTML, |
65 | reply_markup=visibility_menu) | 67 | reply_markup=visibility_menu) |
66 | return WAIT_VISIBILITY | 68 | return WAIT_VISIBILITY |
67 | 69 | ||
68 | 70 | ||
69 | async def callback_toggle_visibility(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 71 | @check_user |
72 | async def callback_toggle_visibility(update: Update, context: ContextTypes.DEFAULT_TYPE, user: User) -> int: | ||
70 | query = update.callback_query | 73 | query = update.callback_query |
71 | await query.answer() | 74 | await query.answer() |
72 | 75 | ||