#!/usr/bin/env bash
set -euo pipefail

if [ "$#" -ne 2 ]; then
  echo "usage: $0 <ezra_bot_token> <bezalel_bot_token>" >&2
  exit 1
fi

EZRA_TOKEN="$1"
BEZALEL_TOKEN="$2"
GROUP_ID='-1003664764329'
GROUP_NAME='Timmy Time'
ALLOWED='7635059073'

ssh root@143.198.27.163 "python3 - <<'PY'
from pathlib import Path
p = Path('/root/wizards/ezra/home/.env')
text = p.read_text() if p.exists() else ''
lines = [line for line in text.splitlines() if not line.startswith('TELEGRAM_')]
lines += [
    'TELEGRAM_BOT_TOKEN=${EZRA_TOKEN}',
    'TELEGRAM_HOME_CHANNEL=${GROUP_ID}',
    'TELEGRAM_HOME_CHANNEL_NAME=${GROUP_NAME}',
    'TELEGRAM_ALLOWED_USERS=${ALLOWED}',
]
p.write_text('\n'.join(lines) + '\n')
PY
systemctl restart hermes-ezra.service openclaw-ezra.service"

ssh root@67.205.155.108 "python3 - <<'PY'
from pathlib import Path
p = Path('/root/wizards/bezalel/home/.env')
text = p.read_text() if p.exists() else ''
lines = [line for line in text.splitlines() if not line.startswith('TELEGRAM_')]
lines += [
    'TELEGRAM_BOT_TOKEN=${BEZALEL_TOKEN}',
    'TELEGRAM_HOME_CHANNEL=${GROUP_ID}',
    'TELEGRAM_HOME_CHANNEL_NAME=${GROUP_NAME}',
    'TELEGRAM_ALLOWED_USERS=${ALLOWED}',
]
p.write_text('\n'.join(lines) + '\n')
PY
systemctl restart hermes-bezalel.service"

echo 'Wizard Telegram bot tokens installed and services restarted.'
