diff options
Diffstat (limited to 'command.py')
-rw-r--r-- | command.py | 32 |
1 files changed, 29 insertions, 3 deletions
@@ -2,7 +2,9 @@ from telegram import Update | |||
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 | 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 config import * | 8 | from config import * |
7 | 9 | ||
8 | 10 | ||
@@ -50,8 +52,32 @@ async def logout_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> | |||
50 | await update.message.reply_text(PROMPT_LOGOUT_SUCCESS, parse_mode=ParseMode.HTML, reply_markup=LOGIN_MENU) | 52 | await update.message.reply_text(PROMPT_LOGOUT_SUCCESS, parse_mode=ParseMode.HTML, reply_markup=LOGIN_MENU) |
51 | 53 | ||
52 | 54 | ||
53 | async def toggle_visibility_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | 55 | async def toggle_visibility_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |
54 | await update.message.reply_text(PROMPT_TOGGLE_VIS, parse_mode=ParseMode.HTML, reply_markup=MAIN_MENU) | 56 | visibility_menu = InlineKeyboardMarkup([ |
57 | [InlineKeyboardButton("Private", callback_data=TOOT_VISIBILITY_PRIVATE)], | ||
58 | [InlineKeyboardButton("Unlisted", callback_data=TOOT_VISIBILITY_UNLISTED)], | ||
59 | [InlineKeyboardButton("Public", callback_data=TOOT_VISIBILITY_PUBLIC)] | ||
60 | ]) | ||
61 | |||
62 | user = get_user_by_id(str(update.effective_user.id)) | ||
63 | await update.message.reply_text(PROMPT_TOGGLE_VIS.format(user["toot_visibility"]), | ||
64 | parse_mode=ParseMode.HTML, | ||
65 | reply_markup=visibility_menu) | ||
66 | return WAIT_VISIBILITY | ||
67 | |||
68 | |||
69 | async def callback_toggle_visibility(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | ||
70 | query = update.callback_query | ||
71 | await query.answer() | ||
72 | |||
73 | if query.data not in [TOOT_VISIBILITY_PRIVATE, TOOT_VISIBILITY_UNLISTED, TOOT_VISIBILITY_PUBLIC]: | ||
74 | await query.edit_message_text(text="Invalid visibility", | ||
75 | reply_markup=MAIN_MENU) | ||
76 | return ConversationHandler.END | ||
77 | |||
78 | update_user_visibility(str(update.effective_user.id), query.data) | ||
79 | await query.edit_message_text(text=f"Default visibility changed to {query.data}") | ||
80 | return ConversationHandler.END | ||
55 | 81 | ||
56 | 82 | ||
57 | async def cancel_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: | 83 | async def cancel_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: |