Files
jigaido/apps/telegram-bot
shokollm 5b1634ebca refactor(commands): use core services instead of storage module
Refactor commands.py to be thin Telegram wrappers around core services.

Changes:
- Replace 'import storage' with imports from core.services and adapters.storage
- Create module-level service instances (BountyService, TrackingService)
- Update format_bounty() to work with Bounty dataclass instead of dict
- Add get_room_id() helper for unified group/DM handling
- Each command handler is now a thin wrapper that:
  1. Extracts Telegram types (update, user_id, room_id)
  2. Calls appropriate core service
  3. Formats and sends response

Kept from original:
- parse_args()
- format_bounty()
- extract_args()

Commands now use services:
- cmd_bounty: BOUNTY_SERVICE.list_bounties()
- cmd_my: BOUNTY_SERVICE.list_bounties() or TRACKING_SERVICE.get_tracked_bounties()
- cmd_add: BOUNTY_SERVICE.add_bounty()
- cmd_update: BOUNTY_SERVICE.update_bounty()
- cmd_delete: BOUNTY_SERVICE.delete_bounty()
- cmd_track: TRACKING_SERVICE.track_bounty() (groups only)
- cmd_untrack: TRACKING_SERVICE.untrack_bounty() (groups only)

Fixes #13
2026-04-03 12:39:23 +00:00
..
2026-04-01 08:05:10 +00:00
2026-04-01 08:05:10 +00:00

Telegram Bot

A Telegram bot for managing and tracking bounties in groups and DMs.

Setup

cd apps/telegram-bot

# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Copy and edit environment
cp .env.example .env
# Add your bot token to .env: JIGAIDO_BOT_TOKEN="your:token"

# Install dependencies and run
uv sync          # creates .venv/, installs deps
uv run python bot.py   # runs the bot

Running in Background

Option 1: tmux (quick, survives SSH disconnect)

tmux new -s jigaido
uv run python bot.py
# Press Ctrl+B, then D to detach (bot keeps running)

// Later:
tmux attach -t jigaido

Option 2: systemd (production, auto-restart, boot on startup)

# Edit the service file paths first
nano deploy/jigaido-bot.service
# Change /home/shoko/repositories/jigaido to your actual path

# Install
sudo cp deploy/jigaido-bot.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable jigaido-bot
sudo systemctl start jigaido-bot

# Useful commands:
sudo systemctl status jigaido-bot
sudo systemctl restart jigaido-bot
sudo systemctl stop jigaido-bot
journalctl -u jigaido-bot -f    # tail logs

Or use the automated setup script:

export JIGAIDO_BOT_TOKEN="your:token"
bash deploy/setup.sh

Reminders

Schedule a daily cron job for due date notifications:

# crontab -e — run at 9am daily
0 9 * * * cd /path/to/jigaido/apps/telegram-bot && JIGAIDO_BOT_TOKEN="your:token" uv run python cron.py

Project Structure

apps/telegram-bot/
├── bot.py              # Bot entrypoint
├── commands.py         # Command handlers
├── cron.py            # Daily reminder job
├── db.py              # SQLite database wrapper
├── schema.sql         # Database schema
├── pyproject.toml     # uv project definition
├── .env.example        # Environment template
├── deploy/
│   ├── jigaido-bot.service  # systemd service
│   └── setup.sh             # Automated setup script
└── tests/
    ├── conftest.py     # Test fixtures
    ├── test_db.py      # Database tests
    └── test_commands.py # Command/parsing tests

Commands

Command Where Who Description
/bounty Group / DM Anyone List all bounties
/my Group / DM Anyone List your tracked bounties
/add <text> [link] [due> Group Admin Add bounty
/add <text> [link] [due> DM Anyone Add personal bounty
/update <id> [text] [link] [due> Group Admin Update bounty
/delete <id> Group Admin Delete bounty
/track <id> Group / DM Anyone Track a bounty
/untrack <id> Group / DM Anyone Stop tracking
/admin_add <user> Group Creator Promote to admin
/admin_remove <user> Group Creator Demote admin
/start Group / DM Anyone Re-initialize
/help Anywhere Anyone Show help