From 67d801d9decf8fd6272f82108ed998164b98cc18 Mon Sep 17 00:00:00 2001 From: shokollm <270575765+shokollm@users.noreply.github.com> Date: Fri, 3 Apr 2026 14:27:01 +0000 Subject: [PATCH] refactor(telegram-bot): add /edit command and make bot.py minimal entrypoint - Add cmd_edit as alias for cmd_update - Update bot.py to import commands directly instead of via module - Register /edit command in bot and post_init commands list - Clean up unused imports in bot.py Fixes #14 --- apps/telegram-bot/bot.py | 43 ++++++++++++++++++++--------------- apps/telegram-bot/commands.py | 11 +++++++-- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/apps/telegram-bot/bot.py b/apps/telegram-bot/bot.py index 4df2600..c72df9c 100644 --- a/apps/telegram-bot/bot.py +++ b/apps/telegram-bot/bot.py @@ -4,15 +4,20 @@ import logging import os import sys -from telegram import Update -from telegram.ext import ( - Application, - CommandHandler, - MessageHandler, - filters, -) +from telegram.ext import Application, CommandHandler, MessageHandler, filters -import commands +from commands import ( + cmd_add, + cmd_bounty, + cmd_delete, + cmd_edit, + cmd_help, + cmd_my, + cmd_start, + cmd_track, + cmd_untrack, + cmd_update, +) logging.basicConfig( format="%(asctime)s %(levelname)s %(name)s: %(message)s", @@ -26,17 +31,18 @@ BOT_TOKEN = os.environ.get("JIGAIDO_BOT_TOKEN", "") def build_app() -> Application: app = Application.builder().token(BOT_TOKEN).build() - app.add_handler(CommandHandler("start", commands.cmd_start)) - app.add_handler(CommandHandler("help", commands.cmd_help)) - app.add_handler(CommandHandler("bounty", commands.cmd_bounty)) - app.add_handler(CommandHandler("my", commands.cmd_my)) - app.add_handler(CommandHandler("add", commands.cmd_add)) - app.add_handler(CommandHandler("update", commands.cmd_update)) - app.add_handler(CommandHandler("delete", commands.cmd_delete)) - app.add_handler(CommandHandler("track", commands.cmd_track)) - app.add_handler(CommandHandler("untrack", commands.cmd_untrack)) + app.add_handler(CommandHandler("start", cmd_start)) + app.add_handler(CommandHandler("help", cmd_help)) + app.add_handler(CommandHandler("bounty", cmd_bounty)) + app.add_handler(CommandHandler("my", cmd_my)) + app.add_handler(CommandHandler("add", cmd_add)) + app.add_handler(CommandHandler("edit", cmd_edit)) + app.add_handler(CommandHandler("update", cmd_update)) + app.add_handler(CommandHandler("delete", cmd_delete)) + app.add_handler(CommandHandler("track", cmd_track)) + app.add_handler(CommandHandler("untrack", cmd_untrack)) - app.add_handler(MessageHandler(filters.COMMAND, commands.cmd_help)) + app.add_handler(MessageHandler(filters.COMMAND, cmd_help)) return app @@ -47,6 +53,7 @@ async def post_init(app: Application) -> None: ("bounty", "List bounties"), ("my", "Your tracked bounties"), ("add", "Add a bounty"), + ("edit", "Edit a bounty"), ("track", "Track a bounty"), ("untrack", "Stop tracking"), ("help", "Show help"), diff --git a/apps/telegram-bot/commands.py b/apps/telegram-bot/commands.py index f08a04b..b0ae05e 100644 --- a/apps/telegram-bot/commands.py +++ b/apps/telegram-bot/commands.py @@ -84,7 +84,7 @@ def get_user_id(update: Update) -> int: def get_room_id(update: Update) -> int: """Get room_id for the current context. - + For groups: negative group_id For DMs: positive user_id """ @@ -116,7 +116,11 @@ async def cmd_my(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: bounties = BOUNTY_SERVICE.list_bounties(room_id) if not bounties: - msg = "You are not tracking any bounties." if is_group(update) else "No personal bounties." + msg = ( + "You are not tracking any bounties." + if is_group(update) + else "No personal bounties." + ) await update.message.reply_text(msg) return @@ -200,6 +204,9 @@ async def cmd_update(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: await update.message.reply_text("Bounty not found.") +cmd_edit = cmd_update + + async def cmd_delete(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None: args = extract_args(update.message.text) if not args: -- 2.49.1