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: # generate fedi OAuth login url # mastodon_client = Mastodon(client_id=MASTODON_CLIENT_ID_FILE, api_base_url=TOOT_API_BASE_URL) # oauth_url = mastodon_client.auth_request_url(redirect_uris="{}/{}".format(BOT_DOMAIN, FEDI_LOGIN_CALLBACK_URL), # scopes=['write:media', 'write:statuses']) # # await update.message.reply_text(PROMPT_FEDI_LOGIN.format(oauth_url), parse_mode=ParseMode.MARKDOWN) 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