rustic-economy is a Rust example plugin for Dragonfly that demonstrates:
- A simple SQLite-backed economy using
sqlx. - The Rust SDK macros
#[derive(Plugin)]and#[derive(Command)]. - The generated command system (
Ecoenum +EcoHandlertrait). - Using
Ctxto reply to the invoking player.
It is meant as a learning/reference plugin, not a production-ready economy.
- Stores each player’s balance in a local
economy.dbSQLite database. - Exposes one command,
/eco(with aliases/economyand/rustic_eco):/eco pay <amount>(/eco donate <amount>): add money to your own balance./eco bal(aliases/eco balance,/eco money): show your current balance.
Balances are stored as REAL/f64 for simplicity. For real money, you should use
an integer representation (e.g. cents as i64) to avoid floating‑point issues.
Cargo.toml: Rust crate metadata for the example plugin.src/main.rs: The entire plugin implementation:RusticEconomystruct holding aSqlitePool.impl RusticEconomy { new, get_balance, add_money }– DB helpers.Ecocommand enum +EcoHandlerimpl withpayandbalhandlers.mainfunction that initialises the DB and runsPluginRunner.
- Rust (stable) and
cargo. - A Dragonfly host that has the Rust SDK wired in (this repo’s Go host).
- SQLite available on the host machine (the plugin writes
economy.dbnext to where it is run).
From the repo root:
cd examples/plugins/rust
cargo build --releaseThe compiled binary will be in target/release/rustic-economy (or .exe on Windows).
Point your Dragonfly plugins.yaml at that binary.
plugins:
- id: rustic-economy
name: Rustic Economy
command: "./examples/plugins/rust/target/release/rustic-economy"
address: "tcp://127.0.0.1:50050"Ensure the id matches the #[plugin(id = "rustic-economy", ...)] attribute in
src/main.rs.
- Start Dragonfly with the plugin enabled via
plugins.yaml. - Join the server as a player.
- Run economy commands in chat:
/eco pay 10– adds 10 to your balance and shows the new total./eco bal– prints your current balance.
- Check that
economy.dbis created and populated in the working directory.
If any DB or send‑chat errors occur, the plugin logs them to stderr and replies with a generic error message so players aren’t exposed to internals.
#[derive(Plugin)]+#[plugin(...)]describe plugin metadata and register theEcocommand with the host.#[derive(Command)]generates aEcoHandlertrait and argument parsing fromtypes::CommandEventinto theEcoenum.Ctx<'_>is used to send replies:ctx.reply("...".to_string()).await.PluginRunner::run(plugin, "tcp://127.0.0.1:50050")connects the plugin process to the Dragonfly host and runs the event loop.
Use this example as a starting point when building stateful Rust plugins that compose the SDK’s command and event systems with your own storage layer.