Merge pull request 'refactor(telegram-bot): add /edit command and make bot.py minimal entrypoint' (#34) from fix/issue-14 into main
This commit was merged in pull request #34.
This commit is contained in:
@@ -4,15 +4,20 @@ import logging
|
|||||||
import os
|
import os
|
||||||
import sys
|
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(
|
logging.basicConfig(
|
||||||
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
|
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:
|
def build_app() -> Application:
|
||||||
app = Application.builder().token(BOT_TOKEN).build()
|
app = Application.builder().token(BOT_TOKEN).build()
|
||||||
|
|
||||||
app.add_handler(CommandHandler("start", commands.cmd_start))
|
app.add_handler(CommandHandler("start", cmd_start))
|
||||||
app.add_handler(CommandHandler("help", commands.cmd_help))
|
app.add_handler(CommandHandler("help", cmd_help))
|
||||||
app.add_handler(CommandHandler("bounty", commands.cmd_bounty))
|
app.add_handler(CommandHandler("bounty", cmd_bounty))
|
||||||
app.add_handler(CommandHandler("my", commands.cmd_my))
|
app.add_handler(CommandHandler("my", cmd_my))
|
||||||
app.add_handler(CommandHandler("add", commands.cmd_add))
|
app.add_handler(CommandHandler("add", cmd_add))
|
||||||
app.add_handler(CommandHandler("update", commands.cmd_update))
|
app.add_handler(CommandHandler("edit", cmd_edit))
|
||||||
app.add_handler(CommandHandler("delete", commands.cmd_delete))
|
app.add_handler(CommandHandler("update", cmd_update))
|
||||||
app.add_handler(CommandHandler("track", commands.cmd_track))
|
app.add_handler(CommandHandler("delete", cmd_delete))
|
||||||
app.add_handler(CommandHandler("untrack", commands.cmd_untrack))
|
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
|
return app
|
||||||
|
|
||||||
@@ -47,6 +53,7 @@ async def post_init(app: Application) -> None:
|
|||||||
("bounty", "List bounties"),
|
("bounty", "List bounties"),
|
||||||
("my", "Your tracked bounties"),
|
("my", "Your tracked bounties"),
|
||||||
("add", "Add a bounty"),
|
("add", "Add a bounty"),
|
||||||
|
("edit", "Edit a bounty"),
|
||||||
("track", "Track a bounty"),
|
("track", "Track a bounty"),
|
||||||
("untrack", "Stop tracking"),
|
("untrack", "Stop tracking"),
|
||||||
("help", "Show help"),
|
("help", "Show help"),
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ def get_user_id(update: Update) -> int:
|
|||||||
|
|
||||||
def get_room_id(update: Update) -> int:
|
def get_room_id(update: Update) -> int:
|
||||||
"""Get room_id for the current context.
|
"""Get room_id for the current context.
|
||||||
|
|
||||||
For groups: negative group_id
|
For groups: negative group_id
|
||||||
For DMs: positive user_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)
|
bounties = BOUNTY_SERVICE.list_bounties(room_id)
|
||||||
|
|
||||||
if not bounties:
|
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)
|
await update.message.reply_text(msg)
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -200,6 +204,9 @@ async def cmd_update(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
|||||||
await update.message.reply_text("Bounty not found.")
|
await update.message.reply_text("Bounty not found.")
|
||||||
|
|
||||||
|
|
||||||
|
cmd_edit = cmd_update
|
||||||
|
|
||||||
|
|
||||||
async def cmd_delete(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
async def cmd_delete(update: Update, ctx: ContextTypes.DEFAULT_TYPE) -> None:
|
||||||
args = extract_args(update.message.text)
|
args = extract_args(update.message.text)
|
||||||
if not args:
|
if not args:
|
||||||
|
|||||||
Reference in New Issue
Block a user