- Replace SQLite db module with file-based JSON storage in ~/.jigaido/
- Group bounties: ~/.jigaido/{group_id}/group.json
- User tracking: ~/.jigaido/{group_id}/user_{id}.json
- Personal bounties: ~/.jigaido/user_{id}/user.json
- Anyone can add bounties to groups; only creator can edit/delete
- Bounty IDs are sequential per group, not global
- Fix test mock compatibility issues in format_bounty function
71 lines
1.8 KiB
Python
71 lines
1.8 KiB
Python
"""JIGAIDO Telegram bot entrypoint."""
|
|
|
|
import logging
|
|
import os
|
|
import sys
|
|
|
|
from telegram import Update
|
|
from telegram.ext import (
|
|
Application,
|
|
CommandHandler,
|
|
MessageHandler,
|
|
filters,
|
|
)
|
|
|
|
import commands
|
|
|
|
logging.basicConfig(
|
|
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
|
|
level=logging.INFO,
|
|
)
|
|
log = logging.getLogger(__name__)
|
|
|
|
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(MessageHandler(filters.COMMAND, commands.cmd_help))
|
|
|
|
return app
|
|
|
|
|
|
async def post_init(app: Application) -> None:
|
|
await app.bot.set_my_commands(
|
|
[
|
|
("bounty", "List bounties"),
|
|
("my", "Your tracked bounties"),
|
|
("add", "Add a bounty"),
|
|
("track", "Track a bounty"),
|
|
("untrack", "Stop tracking"),
|
|
("help", "Show help"),
|
|
]
|
|
)
|
|
|
|
|
|
def main() -> None:
|
|
if not BOT_TOKEN:
|
|
log.error("JIGAIDO_BOT_TOKEN environment variable not set.")
|
|
sys.exit(1)
|
|
|
|
app = build_app()
|
|
app.post_init = post_init
|
|
|
|
log.info("JIGAIDO starting...")
|
|
app.run_polling(drop_pending_updates=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|