This project uses Nix flakes to manage dependencies, ensuring a reliable and reproducible build environment. To get started:
- Install Nix or NixOS by following instructions at nixos.org/download.
- Enable Nix flakes as per the guide on NixOS Wiki.
Alternatively, install Cargo and Rust using the instructions found at Rust's official site.
To build the project:
- For a release build, run
nix build. The resulting binary can be found at./result/bin/f0bot. - For setting up a development environment with necessary dependencies, run
nix develop. Inside this environment, you can compile the project withcargo build.
-
Install diesel_cli with SQLite support:
cargo install diesel_cli --no-default-features --features sqlite
-
Create local directory and configuration:
mkdir local cp config.example.yaml local/config.yaml -
Set up the database:
cd local diesel migration run --database-url db.sqlite3 --migration-dir ../migrations
- Use @BotFather to create a new Telegram bot, create a test chat with topics, and add the bot as an administrator.
- Edit
local/config.yamland adjust it as needed, particularly thetelegram.token.
To start the bot, run from the local directory:
cd local
cargo run bot ./config.yamlAlternatively, you can build and run the release version:
cargo build --release
cd local
../target/release/f0bot bot ./config.yamlOr using the Nix build:
nix build
cd local
../result/bin/f0bot bot ./config.yaml/help- Display all available commands/status- Show bot status/version- Show bot version/topics- Show topic list (private chat only)/count- Count devices online (via Mikrotik)
These commands are available only to residents:
/residents- List current residents/residents_admin_table- Show residents admin table/residents_timeline- Show residents timeline
/needs- Show shopping list/need <item>- Add an item to the shopping list
/userctl- Control personal configuration--add-mac XX:XX:XX:XX:XX:XX- Add MAC address for presence detection--remove-mac XX:XX:XX:XX:XX:XX- Remove MAC address--help- Show userctl command help
/add_ssh <public_key>- Add an SSH public key for yourself/get_ssh <username>- Get SSH public keys of a user by username
/ldap_register <args>- Register in LDAP system/ldap_reset_password- Reset your LDAP password/ldap_update <args>- Update LDAP settings
/tldr- Summarize long discussion (TL;DR)/racovina- Show racovina camera image (in resident chat)/hlam- Show hlam camera image (in resident chat)/open- Open the door/temp_open- Generate a temporary guest door access link
These commands are available only to bot technicians/admins:
/add_resident <username|ID>- Add a user as a resident/remove_resident <username|ID>- Remove a user from residents/broadcast- Broadcast a message to all residents (use as a reply to the message you want to send)/debug_update_dashboard <args>- Debug dashboard update
- Commands marked with * are available only to residents
- Commands marked with ** are available only to bot technicians/admins
- The bot supports various internal features like MAC address monitoring for presence detection
- For more details on specific commands, use the command with
--helpflag where available
This project uses several tools to maintain code quality and consistency. Run the following command to check all linting rules and run tests:
just checkThis command performs:
- Nix linting:
deadnixandstatixfor Nix expressions - Python linting:
mypytype checking andrufflinting - Rust linting:
cargo clippywith strict warnings enabled - Tests: Full Rust test suite
To format all code in the project:
just fmtThis formats Rust, Nix, Python, YAML, JSON, Markdown, and TypeScript files.
To regenerate the database schema after migrations:
just schemaThis project follows these conventions:
- Code Style and Lints: Refer to the
./Justfile. - Commit Messages: Conventional Commits.
- Metric Naming: Prometheus metric and label naming guidelines.