blob: e45a2e2666c8355da4efe55ed2d19b6f1b630804 (
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
|
from telegram import Update
from telegram.constants import ParseMode
from telegram.error import BadRequest
from telegram.ext import ContextTypes, ConversationHandler
from config import *
from mastodon import Mastodon
async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> int:
await update.message.reply_text(PROMPT_START, parse_mode=ParseMode.MARKDOWN)
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
|