From 7987a261d444b151e53177beffbb8abd16db141b Mon Sep 17 00:00:00 2001 From: clarkzjw Date: Tue, 28 Mar 2023 13:25:07 -0700 Subject: add rebuild command --- bot/bot.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'bot/bot.py') diff --git a/bot/bot.py b/bot/bot.py index 307f18f..63a15a8 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -181,21 +181,27 @@ async def process(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: output.seek(0) upload_to_s3(photo.fileId, output.read()) - write_json() - response = httpx.post(cloudflare_pages_deploy_hook_url) - if response.status_code == 200: - await update.message.reply_markdown_v2(text="trigger deploy succeed") - else: - await update.message.reply_markdown_v2("trigger deploy failed, status: {}".format(response.status_code)) + await rebuild(update) + except Exception: await update.message.reply_markdown_v2(text="Error:\n```{}```".format(traceback.format_exc())) +async def rebuild(update: Update) -> None: + write_json() + response = httpx.post(cloudflare_pages_deploy_hook_url) + if response.status_code == 200: + await update.message.reply_markdown_v2(text="trigger deploy succeed") + else: + await update.message.reply_markdown_v2("trigger deploy failed, status: {}".format(response.status_code)) + + def main() -> None: tg_token = os.getenv("TG_TOKEN") application = Application.builder().token(tg_token).build() application.add_handler(CommandHandler("start", start)) + application.add_handler(CommandHandler("rebuild", rebuild)) application.add_handler(MessageHandler(filters.ATTACHMENT & ~filters.COMMAND, process)) application.run_polling() -- cgit v1.2.3