Skip to main content

zaun_bot/
lib.rs

1//! # zaun-bot
2//!
3//! The Rust SDK for **Zaun bots**: WebAssembly components that run *inside* a community's own
4//! `zaun-host`, in a sandbox, with only the permissions and capabilities the owner granted.
5//!
6//! ```ignore
7//! use zaun_bot::prelude::*;
8//!
9//! #[derive(Default)]
10//! struct Ping;
11//!
12//! impl Bot for Ping {
13//!     fn commands(&mut self, _: &Config) -> Vec<ApplicationCommand> {
14//!         vec![SlashCommand::new("ping", "Check that the bot is alive").build()]
15//!     }
16//!     fn on_command(&mut self, ctx: Context, cmd: CommandData) {
17//!         if cmd.name == "ping" {
18//!             let _ = ctx.reply("pong");
19//!         }
20//!     }
21//! }
22//!
23//! export_bot!(Ping);
24//! ```
25//!
26//! The data shapes follow the Zaun specification §8.13–§8.14, which follow Discord's
27//! interaction model. The WIT world in `wit/` is the source of truth.
28
29pub mod audio;
30mod body;
31mod body_mentions;
32mod bot;
33mod button;
34mod command;
35mod context;
36mod embed;
37mod events;
38mod export;
39mod host_error;
40mod layout;
41pub mod mention;
42mod modal;
43mod objects;
44mod options;
45pub mod presence;
46#[doc(hidden)]
47pub mod run;
48mod select;
49pub mod voice;
50
51/// Generated bindings for the `zaun:bot/bot` world.
52#[allow(missing_docs, clippy::all)]
53pub mod bindings {
54    wit_bindgen::generate!({
55        world: "bot",
56        path: "wit",
57        pub_export_macro: true,
58        default_bindings_module: "zaun_bot::bindings",
59    });
60}
61
62pub use bindings::zaun::bot::types;
63pub use bindings::zaun::bot::{
64    commands, community, dms, http, interactions, log, messages, storage, timers,
65};
66
67pub use audio::Audio;
68pub use body::Reply;
69pub use bot::{Bot, Config};
70pub use button::Button;
71pub use command::{SlashCommand, SubCommand, SubCommandGroup};
72pub use context::Context;
73pub use embed::EmbedBuilder;
74pub use events::{EventContext, dispatch};
75pub use layout::{Container, Section, TextDisplay};
76pub use modal::{Modal, TextInput};
77pub use options::{CommandOptionBuilder, Options, text_choice};
78pub use select::{ActionRow, Select};
79pub use voice::Voice;
80
81/// Everything a typical bot needs.
82pub mod prelude {
83    pub use crate::presence::{Activity, Status};
84    pub use crate::types::{
85        ApplicationCommand, Channel, Choice, ChoiceValue, CommandData, ComponentData, Event,
86        HostError, Member, Mentions, Message, ModalData, Reaction, Ready, Role,
87    };
88    pub use crate::{
89        ActionRow, Audio, Bot, Button, CommandOptionBuilder, Config, Container, Context,
90        EmbedBuilder, EventContext, Modal, Options, Reply, Section, Select, SlashCommand,
91        SubCommand, SubCommandGroup, TextDisplay, TextInput, Voice, export_bot, log_info, mention,
92        text_choice,
93    };
94}
95
96/// Writes an `info` line to the bot's log (`zaun-host bot logs`).
97#[macro_export]
98macro_rules! log_info {
99    ($($arg:tt)*) => {
100        $crate::log::write($crate::log::Level::Info, &::std::format!($($arg)*))
101    };
102}