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
This commit is contained in:
@@ -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"),
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user