aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'command.py')
-rw-r--r--command.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/command.py b/command.py
index b12483a..f124e2a 100644
--- a/command.py
+++ b/command.py
@@ -2,7 +2,9 @@ from telegram import Update
2from telegram.constants import ParseMode 2from telegram.constants import ParseMode
3from telegram.error import BadRequest 3from telegram.error import BadRequest
4from telegram.ext import ContextTypes, ConversationHandler 4from telegram.ext import ContextTypes, ConversationHandler
5from dbstore.peewee_store import get_user_access_key, get_user_home_instance, delete_user_by_id 5from dbstore.peewee_store import get_user_access_key, get_user_home_instance, delete_user_by_id, update_user_visibility
6from dbstore.peewee_store import get_user_by_id
7from dbstore.peewee_store import TOOT_VISIBILITY_PRIVATE, TOOT_VISIBILITY_UNLISTED, TOOT_VISIBILITY_PUBLIC
6from config import * 8from 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
53async def toggle_visibility_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: 55async 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
69async 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
57async def cancel_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: 83async def cancel_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
Powered by cgit v1.2.3 (git 2.41.0)