Skip to content

Commit

Permalink
Merge pull request ATLBitLab#14 from ATLBitLab/3-server-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
bnonni authored Aug 23, 2023
2 parents 076599c + 50f2f1f commit bb610d7
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 50 deletions.
29 changes: 29 additions & 0 deletions abbot.service
Original file line number Diff line number Diff line change
@@ -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
29 changes: 0 additions & 29 deletions atlbitlab-bot.service

This file was deleted.

12 changes: 6 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
@@ -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
27 changes: 14 additions & 13 deletions src/atl_bitlab_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]
Expand Down Expand Up @@ -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:
Expand All @@ -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()
4 changes: 2 additions & 2 deletions start.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit bb610d7

Please sign in to comment.