Files

79 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
BOT_DIR="/root/telegram-agy-bot"
ENV_FILE="$BOT_DIR/.env"
SERVICE_NAME="agy-telegram-bot"
usage() {
echo "=========================================================="
echo " Antigravity (AGY) Telegram Bot Manager"
echo "=========================================================="
echo "Usage: ./manage.sh [command]"
echo ""
echo "Commands:"
echo " start Start the bot service"
echo " stop Stop the bot service"
echo " restart Restart the bot service"
echo " status View bot service status"
echo " logs View live systemd service logs"
echo " set-token <token> Set Telegram Bot Token in .env"
echo " add-user <user_id> Add authorized Telegram User ID"
echo " test Run bot directly in foreground for debugging"
echo "=========================================================="
}
case "$1" in
start)
echo "Starting $SERVICE_NAME..."
systemctl start $SERVICE_NAME
systemctl status $SERVICE_NAME --no-pager
;;
stop)
echo "Stopping $SERVICE_NAME..."
systemctl stop $SERVICE_NAME
;;
restart)
echo "Restarting $SERVICE_NAME..."
systemctl restart $SERVICE_NAME
systemctl status $SERVICE_NAME --no-pager
;;
status)
systemctl status $SERVICE_NAME --no-pager
;;
logs)
journalctl -u $SERVICE_NAME -f -n 50
;;
set-token)
if [ -z "$2" ]; then
echo "Error: Please provide a token. Example: ./manage.sh set-token 123456:ABC-DEF..."
exit 1
fi
sed -i "s|^TELEGRAM_BOT_TOKEN=.*|TELEGRAM_BOT_TOKEN=$2|" "$ENV_FILE"
echo "✅ Telegram Bot Token updated in $ENV_FILE"
echo "Run './manage.sh restart' to apply changes."
;;
add-user)
if [ -z "$2" ]; then
echo "Error: Please provide user ID. Example: ./manage.sh add-user 12345678"
exit 1
fi
CURRENT=$(grep "^ALLOWED_USER_IDS=" "$ENV_FILE" | cut -d'=' -f2)
if [ -z "$CURRENT" ]; then
NEW_VAL="$2"
else
NEW_VAL="$CURRENT,$2"
fi
sed -i "s|^ALLOWED_USER_IDS=.*|ALLOWED_USER_IDS=$NEW_VAL|" "$ENV_FILE"
echo "✅ Added User ID $2 to $ENV_FILE"
echo "Run './manage.sh restart' to apply changes."
;;
test)
echo "Starting bot in foreground..."
"$BOT_DIR/venv/bin/python" "$BOT_DIR/bot.py"
;;
*)
usage
;;
esac