diff options
-rw-r--r-- | command.py | 13 | ||||
-rw-r--r-- | dbstore/peewee_store.py | 13 | ||||
-rw-r--r-- | prompt/string.py | 3 |
3 files changed, 26 insertions, 3 deletions
@@ -2,7 +2,7 @@ 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 | 5 | from dbstore.peewee_store import get_user_access_key, get_user_home_instance |
6 | from config import * | 6 | from config import * |
7 | 7 | ||
8 | 8 | ||
@@ -33,7 +33,16 @@ async def tos_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> Non | |||
33 | 33 | ||
34 | 34 | ||
35 | async def list_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | 35 | async def list_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: |
36 | await update.message.reply_text(PROMPT_LIST, parse_mode=ParseMode.HTML, reply_markup=MAIN_MENU) | 36 | result = get_user_home_instance(str(update.effective_user.id)) |
37 | if len(result) == 0: | ||
38 | await update.message.reply_text(PROMPT_LIST_NO_RESULT, parse_mode=ParseMode.HTML) | ||
39 | else: | ||
40 | await update.message.reply_text(f"You are linked with the following Fediverse accounts:\n\n" | ||
41 | f"<b>Instance</b>: {result['home_instance']}\n" | ||
42 | f"<b>Instance type</b>: {result['home_instance_type']}\n" | ||
43 | f"<b>Default visibility</b>: {result['default_visibility']}\n", | ||
44 | parse_mode=ParseMode.HTML, | ||
45 | reply_markup=MAIN_MENU) | ||
37 | 46 | ||
38 | 47 | ||
39 | async def logout_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: | 48 | async def logout_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: |
diff --git a/dbstore/peewee_store.py b/dbstore/peewee_store.py index ed52257..2f637bf 100644 --- a/dbstore/peewee_store.py +++ b/dbstore/peewee_store.py | |||
@@ -51,6 +51,19 @@ def get_user_access_key(telegram_user_id: str) -> str: | |||
51 | return "" | 51 | return "" |
52 | 52 | ||
53 | 53 | ||
54 | def get_user_home_instance(telegram_user_id: str) -> dict: | ||
55 | with db.connection_context(): | ||
56 | try: | ||
57 | user = User.get(User.telegram_user_id == telegram_user_id) | ||
58 | return { | ||
59 | "home_instance": user.home_instance, | ||
60 | "home_instance_type": user.home_instance_type, | ||
61 | "default_visibility": user.toot_visibility, | ||
62 | } | ||
63 | except DoesNotExist: | ||
64 | return {} | ||
65 | |||
66 | |||
54 | class Location(BaseModel): | 67 | class Location(BaseModel): |
55 | fsq_id = CharField(unique=True, primary_key=True) | 68 | fsq_id = CharField(unique=True, primary_key=True) |
56 | name = CharField(max_length=128) | 69 | name = CharField(max_length=128) |
diff --git a/prompt/string.py b/prompt/string.py index eda0df8..207713f 100644 --- a/prompt/string.py +++ b/prompt/string.py | |||
@@ -39,7 +39,8 @@ PROMPT_HELP = "Available commands:" \ | |||
39 | "\n`/tos` - show ToS message" \ | 39 | "\n`/tos` - show ToS message" \ |
40 | "\n`/cancel` - cancel current operation during checkins" | 40 | "\n`/cancel` - cancel current operation during checkins" |
41 | 41 | ||
42 | PROMPT_LIST = "List all linked Fediverse accounts" | 42 | PROMPT_LIST = "You are linked with the following Fediverse accounts:" |
43 | PROMPT_LIST_NO_RESULT = "You are not linked with any Fediverse account yet. \n\n Input <code>/login</code> to login." | ||
43 | PROMPT_LOGOUT = "Choose Fediverse account to logout" | 44 | PROMPT_LOGOUT = "Choose Fediverse account to logout" |
44 | PROMPT_TOGGLE_VIS = "Choose visibility of your checkins on Fediverse" | 45 | PROMPT_TOGGLE_VIS = "Choose visibility of your checkins on Fediverse" |
45 | 46 | ||