aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclarkzjw <[email protected]>2023-02-27 15:48:09 -0800
committerclarkzjw <[email protected]>2023-02-27 15:59:37 -0800
commita1c7c5a223d22017508998599388c5adf9a90713 (patch)
tree9d917eeb71166cb85758ff119f33a89f0fa80ec2 /command.py
parent3bf39b0d32d0e0580457d0f85aef90a9c449a6ad (diff)
downloadswarm2fediverse-a1c7c5a223d22017508998599388c5adf9a90713.tar.gz
bot: add check_user decorator to check user login statusfeature/user_permission
Diffstat (limited to 'command.py')
-rw-r--r--command.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/command.py b/command.py
index f124e2a..db85538 100644
--- a/command.py
+++ b/command.py
@@ -1,11 +1,11 @@
1from telegram import Update 1from telegram import Update, User
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, update_user_visibility 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 dbstore.peewee_store import TOOT_VISIBILITY_PRIVATE, TOOT_VISIBILITY_UNLISTED, TOOT_VISIBILITY_PUBLIC
8from config import * 7from config import *
8from util import check_user
9 9
10 10
11async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: 11async 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
37async def list_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: 38async 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
50async def logout_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: 52async 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
55async def toggle_visibility_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: 57@check_user
58async 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
69async def callback_toggle_visibility(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int: 71@check_user
72async 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
Powered by cgit v1.2.3 (git 2.41.0)