Files
jigaido/apps/telegram-bot/bot.py
shokollm 8bb964fdd0 feat: Replace SQLite with per-user JSON storage (fixes #2)
- Add storage.py with load_user(), save_user(), next_bounty_id()
- Rewrite commands.py to use JSON storage (simplified)
- Remove db.py, schema.sql, cron.py, test_db.py
- Update SPEC.md to reflect new architecture
- Admin model removed (anyone can add, creator only can edit/delete)
- No reminders in v1
2026-04-01 10:02:51 +00:00

73 lines
1.9 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(CommandHandler("admin_add", commands.cmd_admin_add))
app.add_handler(CommandHandler("admin_remove", commands.cmd_admin_remove))
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()