Initial commit - refactored Discord bot with security fixes
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.env
|
||||||
61
README.md
Normal file
61
README.md
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
# Lotus Discord Bot
|
||||||
|
|
||||||
|
Discord bot for the Lotus Guild server with auto-deployment from Gitea.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Daily adjective posting
|
||||||
|
- Minecraft server whitelist management
|
||||||
|
- Custom LLM integration (Lotus LLM)
|
||||||
|
- Fun commands (8ball, fortune, dice, etc.)
|
||||||
|
- Game-specific commands (Valorant agents, LoL champions)
|
||||||
|
- Server audit logging
|
||||||
|
- Reaction roles
|
||||||
|
|
||||||
|
## Auto-Deployment Setup
|
||||||
|
|
||||||
|
The bot automatically deploys when code is pushed to Gitea.
|
||||||
|
|
||||||
|
### Deployment Components
|
||||||
|
|
||||||
|
1. **Webhook Listener**: Runs on port 9000 on the production server
|
||||||
|
2. **Deployment Script**: `/usr/local/bin/discord_bot_deploy.sh`
|
||||||
|
3. **Service**: `discord.service` runs the bot
|
||||||
|
|
||||||
|
### Webhook Configuration
|
||||||
|
|
||||||
|
- **Endpoint**: `http://10.10.10.6:9000/hooks/discord-bot-deploy`
|
||||||
|
- **Secret**: `discord-bot-secret`
|
||||||
|
- **Header**: `X-Gitea-Signature`
|
||||||
|
|
||||||
|
### Manual Deployment
|
||||||
|
|
||||||
|
If needed, you can manually trigger deployment:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ssh root@10.10.10.6
|
||||||
|
/usr/local/bin/discord_bot_deploy.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Production Server
|
||||||
|
|
||||||
|
- **Host**: 10.10.10.6
|
||||||
|
- **Bot Directory**: `/mnt/discordBot/`
|
||||||
|
- **Service**: `discord.service`
|
||||||
|
- **User**: jared
|
||||||
|
|
||||||
|
## Local Development
|
||||||
|
|
||||||
|
The bot requires:
|
||||||
|
- Python 3
|
||||||
|
- discord.py
|
||||||
|
- python-dotenv
|
||||||
|
- aiohttp
|
||||||
|
- mcrcon
|
||||||
|
|
||||||
|
Environment variables in `.env`:
|
||||||
|
- `DISCORD_TOKEN`
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
Run `/help` in Discord to see all available commands.
|
||||||
57
deployment/discord_bot_deploy.sh
Normal file
57
deployment/discord_bot_deploy.sh
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
BOTDIR="/root/code/discordBot"
|
||||||
|
SERVICE_NAME="discord-bot"
|
||||||
|
|
||||||
|
echo "[Discord Bot] Pulling latest code..."
|
||||||
|
|
||||||
|
# Backup .env if it exists
|
||||||
|
if [ -f "$BOTDIR/.env" ]; then
|
||||||
|
cp "$BOTDIR/.env" /tmp/.env.backup
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Backup media and logs folders
|
||||||
|
if [ -d "$BOTDIR/media" ]; then
|
||||||
|
cp -r "$BOTDIR/media" /tmp/media.backup
|
||||||
|
fi
|
||||||
|
if [ -d "$BOTDIR/logs" ]; then
|
||||||
|
cp -r "$BOTDIR/logs" /tmp/logs.backup
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -d "$BOTDIR/.git" ]; then
|
||||||
|
echo "Directory not a git repo — performing initial clone..."
|
||||||
|
rm -rf "$BOTDIR"
|
||||||
|
git clone https://code.lotusguild.org/LotusGuild/discordBot.git "$BOTDIR"
|
||||||
|
else
|
||||||
|
echo "Updating existing repo..."
|
||||||
|
cd "$BOTDIR"
|
||||||
|
git fetch --all
|
||||||
|
git reset --hard origin/main
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restore .env if it was backed up
|
||||||
|
if [ -f /tmp/.env.backup ]; then
|
||||||
|
mv /tmp/.env.backup "$BOTDIR/.env"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Restore media and logs folders
|
||||||
|
if [ -d /tmp/media.backup ]; then
|
||||||
|
rm -rf "$BOTDIR/media"
|
||||||
|
mv /tmp/media.backup "$BOTDIR/media"
|
||||||
|
fi
|
||||||
|
if [ -d /tmp/logs.backup ]; then
|
||||||
|
rm -rf "$BOTDIR/logs"
|
||||||
|
mv /tmp/logs.backup "$BOTDIR/logs"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[Discord Bot] Installing/updating dependencies..."
|
||||||
|
cd "$BOTDIR"
|
||||||
|
pip3 install -r requirements.txt 2>/dev/null || echo "No requirements.txt found, skipping..."
|
||||||
|
|
||||||
|
echo "[Discord Bot] Restarting service..."
|
||||||
|
systemctl restart "$SERVICE_NAME"
|
||||||
|
|
||||||
|
echo "[Discord Bot] Deployment complete!"
|
||||||
|
echo "[Discord Bot] Service status:"
|
||||||
|
systemctl status "$SERVICE_NAME" --no-pager
|
||||||
18
deployment/hooks.json
Normal file
18
deployment/hooks.json
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "discord-bot-deploy",
|
||||||
|
"execute-command": "/usr/local/bin/discord_bot_deploy.sh",
|
||||||
|
"command-working-directory": "/root/code/discordBot",
|
||||||
|
"response-message": "Deploying Discord bot...",
|
||||||
|
"trigger-rule": {
|
||||||
|
"match": {
|
||||||
|
"type": "payload-hash-sha256",
|
||||||
|
"secret": "CHANGE_THIS_SECRET_KEY",
|
||||||
|
"parameter": {
|
||||||
|
"source": "header",
|
||||||
|
"name": "X-Gitea-Signature"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
Reference in New Issue
Block a user