/tg-maid

Primary LanguageRust

TG Maid

My utility bot.

Run with docker-compose (Recommended)

curl -SL https://raw.githubusercontent.com/Avimitin/tg-butler/master/example.docker-compose.yml \
     -o docker-compose.yml
mkdir app
# Detail configuration see below
vim ./app/config.toml
docker-compose up -d

Configuration

The bot will try to read configuration from a config.toml file under directory $XDG_CONFIG_HOME/tg_maid or $HOME/.config/tg_maid. You can also manually specify the config file path by environment variable TG_MAID_CFG_PATH. The content of the file should followed the TOML spec.

The below table describe all the configuration:

  • Top Level
Key Value Type Docs
bot_token String Token for the Telegram Bot
redis_addr String An URL prefixed with redis:// that can be connect to a redis daemon
log_level String (Optional) Unused now
health_check_port int_u16 (Optional) Port number for docker to check the bot alive or not

Notice: if you are using docker-compose, set the redis_addr to redis://${service}:${port} where ${service} is your redis service name in docker-compose.yml. In my example.docker-compose.yml it is cache.

  • DeepL Translate: [deepl]
Key Value Type Docs
api_key String API Key for DeepL authenticate
  • Bilibili Live Room Event: [bili_live_room_event]
Key Value Type Docs
String (Telegram Chat ID) List[Number] (List of Streamer UID Not Room ID!!) Per chat configuration for notifying bilibili live stream status

Below is an example configuration:

bot_token = "abcde"
redis_addr = "redis://localhost"
log_level = "INFO"
health_check_port = 11451

[deepl]
api_key = "abcde"

[bili_live_room_event]
"-10012345" = [ 1000, 2000, 3000 ]
"-10054321" = [ 1000, 2000, 3000 ]

How to build

Docker

cd tg-maid
docker buildx build -t avimitin/tg-maid:latest .

Normal Build

Require dependency:

  • rust
  • pkg-config
  • openssl
  • noto-sans-cjk
  • openbsd-netcat
cargo build --release

Nix flake

If you don't know how to setup the build environment, you can follow the Nix installation guide, or install nix through your system package manager:

pacman -S nix

Then enable the flakes feature and run the following command to get the development shell:

nix develop

You can now use your favourite editor to start contributing to this project:

$EDITOR .

To build the bot executable:

nix build .#tg-maid.bot
./result/bin/tgbot

To build the docker image:

nix run .#tg-maid.docker-image | docker load

TODO

  • Read config from file
  • Implement the make quote functionality
  • Get random restaurant suggestion from DianPing
  • New command /roll [range]
  • Add Nix flake