diff --git a/abbot.service b/abbot.service new file mode 100644 index 00000000..8d1c17cc --- /dev/null +++ b/abbot.service @@ -0,0 +1,29 @@ +[Unit] +Description=ATL BitLab Bot +Documentation=https://github.com/ATLBitLab/abbot + +After=network-online.target +Wants=network-online.target + +[Service] +Environment=HOME=/home/abbot + +WorkingDir=/home/abbot/abbot +ExecStart=/home/abbot/abbot/start.sh + +Restart=always +RestartSec=10 + +StandardOutput=/home/abbot/abbot/src/data/runtime.log +StandardError=/home/abbot/abbot/src/data/debug.log + +SyslogIdentifier=abbot + +User=abbot +Group=abbot + +RuntimeDirectory=abbot +RuntimeDirectoryMode=0710 + +[Install] +WantedBy=multi-user.target diff --git a/atlbitlab-bot.service b/atlbitlab-bot.service deleted file mode 100644 index ff2c988b..00000000 --- a/atlbitlab-bot.service +++ /dev/null @@ -1,29 +0,0 @@ -[Unit] -Description=ATL BitLab Bot -Documentation=https://github.com/ATLBitLab/telegram-gpt-bot - -After=network-online.target -Wants=network-online.target - -[Service] -Environment=HOME=/home/bryan - -WorkingDir=/home/bryan/telegram-gpt-bot -ExecStart=/home/bryan/telegram-gpt-bot/start.sh - -Restart=always -RestartSec=10 - -StandardOutput=/home/bryan/telegram-gpt-bot/src/data/runtime.log -StandardError=/home/bryan/telegram-gpt-bot/src/data/debug.log - -SyslogIdentifier=atlbitlab-bot - -User=bryan -Group=bryan - -RuntimeDirectory=bitcoind -RuntimeDirectoryMode=0710 - -[Install] -WantedBy=multi-user.target diff --git a/install.sh b/install.sh index a683e9b4..0d8afae2 100644 --- a/install.sh +++ b/install.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash source .venv/bin/activate pip install -r requirements.txt -sudo cp atlbitlab-bot.service /etc/systemd/system +sudo cp abbot.service /etc/systemd/system sudo systemctl daemon-reload -sudo systemctl enable atlbitlab-bot -sudo systemctl start atlbitlab-bot -sudo systemctl status atlbitlab-bot -sudo systemctl start atlbitlab-bot -sudo journalctl -u atlbitlab-bot | tail +sudo systemctl enable abbot +sudo systemctl start abbot +sudo systemctl status abbot +sudo systemctl start abbot +sudo journalctl -u abbot | tail echo "Done!" exit 0 \ No newline at end of file diff --git a/src/atl_bitlab_bot.py b/src/atl_bitlab_bot.py index 6f2929b0..84d6ee1d 100644 --- a/src/atl_bitlab_bot.py +++ b/src/atl_bitlab_bot.py @@ -24,7 +24,7 @@ from lib.logger import debug from lib.utils import qr_code from lib.api.strike import Strike -from lib.env import TELEGRAM_BOT_TOKEN, OPENAI_API_KEY, BOT_HANDLE +from lib.env import TEST_TELEGRAM_BOT_TOKEN, TELEGRAM_BOT_TOKEN, OPENAI_API_KEY, BOT_HANDLE from help_menu import help_menu_message import openai @@ -40,7 +40,6 @@ MESSAGES_PY_FILE = os.path.abspath("data/backup/messages.py") PROMPTS_BY_DAY_FILE = os.path.abspath("data/backup/prompts_by_day.py") openai.api_key = OPENAI_API_KEY -application = ApplicationBuilder().token(TELEGRAM_BOT_TOKEN).build() now = datetime.now() now_iso = now.isoformat() now_iso_clean = now_iso.split("+")[0].split("T")[0] @@ -379,7 +378,7 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): if f"@{BOT_HANDLE}" not in message_text: return await context.bot.send_message( chat_id=update.effective_chat.id, - text=f"If you want to start @{BOT_HANDLE}, please tag the bot in the start command: e.g. `/start @{BOT_HANDLE}`", + text=f"If you want to start @{BOT_HANDLE}, please tag the bot in the start command: e.g. /start @{BOT_HANDLE}", ) debug(f"[{now}] {PROGRAM}: /start executed by {sender}") if sender not in WHITELIST: @@ -397,23 +396,25 @@ async def start(update: Update, context: ContextTypes.DEFAULT_TYPE): def bot_main(DEV_MODE): global BOT_HANDLE - BOT_HANDLE = f"Test{BOT_HANDLE}" if DEV_MODE else BOT_HANDLE + BOT_HANDLE = f"test_{BOT_HANDLE}" if DEV_MODE else BOT_HANDLE + BOT_TOKEN = TEST_TELEGRAM_BOT_TOKEN if DEV_MODE else TELEGRAM_BOT_TOKEN + APPLICATION = ApplicationBuilder().token(BOT_TOKEN).build() debug(f"[{now}] {PROGRAM}: @{BOT_HANDLE} Initialized") start_handler = CommandHandler("start", start) - application.add_handler(start_handler) + APPLICATION.add_handler(start_handler) help_handler = CommandHandler("help", help) - application.add_handler(help_handler) + APPLICATION.add_handler(help_handler) stop_handler = CommandHandler("stop", stop) - application.add_handler(stop_handler) + APPLICATION.add_handler(stop_handler) summary_handler = CommandHandler("summary", summary) - application.add_handler(summary_handler) + APPLICATION.add_handler(summary_handler) prompt_handler = CommandHandler("prompt", atl_bitlab_bot) - application.add_handler(prompt_handler) + APPLICATION.add_handler(prompt_handler) clean_handler = CommandHandler("clean", clean) - application.add_handler(clean_handler) + APPLICATION.add_handler(clean_handler) clean_summary_handler = CommandHandler("both", both) - application.add_handler(clean_summary_handler) + APPLICATION.add_handler(clean_summary_handler) message_handler = MessageHandler(BaseFilter(), handle_message) - application.add_handler(message_handler) + APPLICATION.add_handler(message_handler) debug(f"[{now}] {PROGRAM}: @{BOT_HANDLE} Polling") - application.run_polling() + APPLICATION.run_polling() diff --git a/start.sh b/start.sh index 99180cc9..b27c21a7 100755 --- a/start.sh +++ b/start.sh @@ -1,6 +1,6 @@ #!/usr/bin/bash -BASE_DIR="$HOME/telegram-gpt-bot" +BASE_DIR="$HOME/abbot" source "$BASE_DIR/.env/bin/activate" cd "$BASE_DIR/src" -python3 cli.py +python3 cli.py --dev