Security/quality

This commit is contained in:
HugeFrog24
2026-03-05 01:51:59 +01:00
parent 6e2d2fce2f
commit e1a9261699
30 changed files with 2823 additions and 295 deletions
Executable → Regular
+71 -34
View File
@@ -3,6 +3,7 @@
A scalable, multi-bot solution for Telegram using Go, GORM, and the Anthropic API.
## Design Considerations
- AI-powered
- Supports multiple bot profiles
- Uses SQLite for persistence
@@ -12,39 +13,40 @@ A scalable, multi-bot solution for Telegram using Go, GORM, and the Anthropic AP
## Usage
1. Clone the repository or install using `go get`:
- Option 1: Clone the repository
```bash
git clone https://github.com/HugeFrog24/go-telegram-bot.git
```
- Option 2: Install using go get
```bash
go get -u github.com/HugeFrog24/go-telegram-bot
```
### Docker Deployment (Recommended)
- Navigate to the project directory:
```bash
cd go-telegram-bot
```
1. Clone the repository:
```bash
git clone https://github.com/HugeFrog24/go-telegram-bot.git
cd go-telegram-bot
```
2. Copy the default config template and edit it:
```bash
cp config/default.json config/config-mybot.json
cp config/default.json config/mybot.json
nano config/mybot.json
```
Replace `config-mybot.json` with the name of your bot.
```bash
nano config/config-mybot.json
```
You can set up as many bots as you want. Just copy the template and edit the parameters.
> [!IMPORTANT]
> [!IMPORTANT]
> Keep your config files secret and do not commit them to version control.
3. Build the application:
3. Create data directory and run:
```bash
mkdir -p data
docker-compose up -d
```
### Native Deployment
1. Install using `go get`:
```bash
go get -u github.com/HugeFrog24/go-telegram-bot
cd go-telegram-bot
```
2. Configure as above, then build:
```bash
go build -o telegram-bot
```
@@ -60,30 +62,32 @@ To enable the bot to start automatically on system boot and run in the backgroun
```
Edit the service file:
```bash
sudo nano /etc/systemd/system/telegram-bot.service
```
Adjust the following parameters:
- WorkingDirectory
- ExecStart
- User
3. Enable and start the service:
2. Enable and start the service:
```bash
sudo systemctl daemon-reload
```
```bash
sudo systemctl enable telegram-bot.service
sudo systemctl enable telegram-bot
```
```bash
sudo systemctl start telegram-bot.service
sudo systemctl start telegram-bot
```
4. Check the status:
3. Check the status:
```bash
sudo systemctl status telegram-bot
@@ -93,18 +97,51 @@ For more details on the systemd setup, refer to the [demo service file](examples
## Logs
View logs using journalctl:
### Docker
```bash
journalctl -u telegram-bot
docker-compose logs -f telegram-bot
```
Follow logs:
### Systemd
```bash
journalctl -u telegram-bot -f
```
View errors:
## Commands
| Command | Access | Description |
| --------------------------------- | ----------- | ------------------------------------------------------------ |
| `/stats` | All users | Show global bot statistics (total users and messages) |
| `/stats user` | All users | Show your own message statistics |
| `/stats user <user_id>` | Admin/Owner | Show statistics for a specific user |
| `/whoami` | All users | Show your Telegram ID, username, and role |
| `/clear` | All users | Soft-delete your own chat history |
| `/clear <user_id>` | Admin/Owner | Soft-delete all messages for a user across every chat |
| `/clear <user_id> <chat_id>` | Admin/Owner | Soft-delete a user's messages in a specific chat |
| `/clear_hard` | All users | Permanently delete your own chat history |
| `/clear_hard <user_id>` | Admin/Owner | Permanently delete all messages for a user across every chat |
| `/clear_hard <user_id> <chat_id>` | Admin/Owner | Permanently delete a user's messages in a specific chat |
> **Note:** In private DMs each user's `chat_id` equals their `user_id`. The scoped `<chat_id>` form is mainly useful for group chat moderation.
## Testing
The GitHub actions workflow already runs tests on every commit:
> [![CI](https://github.com/HugeFrog24/go-telegram-bot/actions/workflows/go-ci.yaml/badge.svg?branch=main)](https://github.com/HugeFrog24/go-telegram-bot/actions/workflows/go-ci.yaml)
However, you can run the tests locally using:
```bash
journalctl -u telegram-bot -p err
go test -race -v ./...
```
## Storage
At the moment, a SQLite database (`./data/bot.db`) is used for persistent storage.
Remember to back it up regularly.
Future versions will support more robust storage backends.