aboutsummaryrefslogtreecommitdiff
blob: 7426901e12edc0081f8d59ec3ddeae6c343c6341 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from telegram import Update
from telegram.constants import ParseMode
from telegram.error import BadRequest
from telegram.ext import ContextTypes, ConversationHandler
from dbstore.peewee_store import get_user_access_key
from config import *


async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
    await update.message.reply_text(PROMPT_START, parse_mode=ParseMode.MARKDOWN)
    user_access_key = get_user_access_key(str(update.effective_user.id))
    # TODO
    # verify user access key still valid
    if len(user_access_key) == 0:
        await update.message.reply_text(PROMPT_FEDI_LOGIN_WHERE_IS_INSTANCE, parse_mode=ParseMode.MARKDOWN)
        return FEDI_LOGIN
    else:
        await update.message.reply_text(PROMPT_CHOOSE_ACTION, reply_markup=MAIN_MENU)
        return WAIT_LOCATION


async def fedi_login_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
    await update.message.reply_text(PROMPT_FEDI_LOGIN_WHERE_IS_INSTANCE, parse_mode=ParseMode.MARKDOWN)
    return FEDI_LOGIN


async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    await update.message.reply_text(PROMPT_HELP)


async def cancel_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
    for prompt in [PROMPT_LOCATION_KEYWORD, PROMPT_WAIT_LOCATION_CONFIRMATION, PROMPT_ADD_COMMENT, PROMPT_ADD_MEDIA]:
        try:
            if context.user_data.get(prompt):
                await context.bot.delete_message(chat_id=update.message.chat_id,
                                                 message_id=context.user_data[prompt])
        except BadRequest as e:
            if "not found" in str(e.message):
                pass
        except Exception as e:
            print(e)

    await update.message.reply_text(text=PROMPT_CANCELED, reply_markup=MAIN_MENU)
    context.user_data.clear()
    return ConversationHandler.END
Powered by cgit v1.2.3 (git 2.41.0)