Expand description
A Zaun community client over SimpleX: join, post, moderate and cache communities.
Client runs one SimpleX client and keeps a post-quantum connection per community to the
community’s host (zaun-host). It verifies the host, registers a member key, and keeps a
local cache of each community (channels, roles, members) up to date from the host’s events.
In the spirit of discord.js, what it reports are objects that act for themselves:
Community, Channel, Message, Member, Role, Attachment.
Client::command sends any command the objects do not wrap.
use zaun_client::{Client, Event};
let client = Client::builder("./bot").name("Ping bot").key("store passphrase").start()?;
let community = client.join("zaun://join/…", "Ping bot")?;
let general = community.channel_by_name("general").expect("a general channel");
general.send("hello")?;
for event in client.events() {
match event {
Event::MessageCreate(message) if message.content() == "!ping" => {
message.reply("pong")?;
}
Event::MemberAdd(member) => println!("welcome, {member}"),
_ => {}
}
}Messages carry rich embeds as discord.js’s do: build one with EmbedBuilder and post it
with MessageOptions. Its pictures are files uploaded as the message’s attachments, never
remote URLs, so no reader’s client fetches anything from a third party.
Voice channels join like discord.js’s: channel.join()? gives a VoiceSession, and an
AudioPlayer subscribed to it plays files for a music bot.
The host is the authority: the cache and Member::can are a local view that lets an
application hide what a member cannot do, and the host still decides.
Re-exports§
pub use presence::Presence;pub use zaun_community_protocol as protocol;
Modules§
- files
- Attachment files on this side: staging an upload inside the SimpleX folder (it only sends files from there), measuring, and delivering a checked download under a safe name.
- mention
- Mentions (specification §8.5): the text that shows one and the list that notifies.
- presence
- Presence (specification §10.5): who is online, idle or do-not-disturb, and doing what
(“Playing chess”, “Listening to lofi radio”). The cache follows
presence.listand everysignal.presence; a member missing from it is offline. Custom status text is part of the member object (member.status.set, §8.3). - registry
- Bot registries for apps: a signed catalog, a history file and a
.zbotpackage, checked as the registry’s own browser verifier (zaun-registry-wasm) checks them. - ui
- Builders for bot messages and commands (§8.14), named as in the zaun-bot SDK: buttons, selects and rows, Components V2 layout, modals, and slash commands.
Structs§
- Attachment
- A file on a message.
- Audio
Player - Plays
AudioResources, one at a time, into every subscribed voice session. - Audio
Resource - Something to play: Opus packets, from an Ogg Opus file or stream, from ffmpeg (any format it reads), or from the application.
- Channel
- A channel or category of a community.
- Client
- A Zaun client. Clones share one SimpleX client and one driver; methods may be called from any thread, and block until the host answers or the timeout passes.
- Client
Builder - Configures a
Client. The directory holds the SimpleX store andzaun/, the community keys and state; give every client its own. - Community
- A community this client belongs to (or did: a handle outlives a leave).
- Community
Data - A community as this client last heard of it. Cheap to clone; a clone does not update.
- DmChannel
- A DM channel: an ordinary channel object of kind
dmwith its two participants. - DmSettings
- The member’s settings (
member.settings.get/.updateresponse). - Edit
Message - An edit of one of this member’s messages. A plain
&strreplaces the text and leaves the embeds and mentions as they are. - Embed
- A message’s rich embed as the protocol has it (
Message::embeds); build one to send withEmbedBuilder. An embed (§8.5). Every text is optional, but an embed shows something: a title, a description, an author, a footer, a picture or a field (color,timestampandurlalone do not count). - Embed
Author - A message’s rich embed as the protocol has it (
Message::embeds); build one to send withEmbedBuilder.author: {name, url?, icon?}of an embed. - Embed
Builder - A rich embed, built with chained setters and sent with
MessageOptions::embed: - Embed
Field - A message’s rich embed as the protocol has it (
Message::embeds); build one to send withEmbedBuilder.fields: [{name, value, inline}]of an embed. - Embed
Footer - A message’s rich embed as the protocol has it (
Message::embeds); build one to send withEmbedBuilder.footer: {text, icon?}of an embed. - Ephemeral
Reply - A bot’s ephemeral reply (
EPHEMERAL): only this member sees it, nothing stores it, and it lives as long as the interaction (15 minutes). Key it by its message’smessage_id. - Ffmpeg
Options - How
AudioResource::ffmpeg_fileand its siblings transcode. - HandOff
- What a hand-off signed and published: the new delegation and the descriptor naming it.
- Interaction
- Someone used one of this bot’s commands, components or modals. Answer within 3 s
(
respond, orResponse::deferfirst); follow-ups and edits work for 15 minutes. - Interaction
Failure - An interaction that got no answer (the bot timed out, failed or is not running).
- Member
- A member of a community.
- Message
- A message in a channel.
- Message
Options - A message to post: text, embeds, files and the message it answers. A plain
&stris one with text only, sochannel.send("hi")still reads as it did. - Modal
Open - A bot asks this member to fill in a modal; submit it with
Channel::submit_modalandinteractionas the modal id. - Partial
Message - A message known only by its id, as an edit, a deletion or a reaction names it: the client
keeps no message history, so its text and author are not at hand. It acts like a
Message. - Pending
Message - A post on its way (
Channel::send_pending): what to show until the host answers. - Reaction
- A reaction added or taken off.
- Response
- What a bot answers an interaction with. Build one with the constructors.
- Role
- A role of a community.
- Suggestions
- A bot’s suggestions for the option this member is typing.
- Typing
Seen - A typing state and when it stops showing.
- Voice
Leave - Why someone left a voice channel.
- Voice
Mute - Someone’s mute and deafen state in a voice channel.
- Voice
Options - How a voice session connects.
- Voice
Session - One stay in a voice channel. Dropping it leaves the channel.
- Voice
State - Someone’s state in a voice channel.
Enums§
- Audio
Player Event - What a player tells the application.
- Audio
Player Status - What a player is doing.
- Error
- A
zaun-clientfailure. - Event
- One thing that happened.
- Picture
- Where an embed’s picture (or a message’s file) comes from. Pictures are never remote URLs: a file is uploaded as one of the message’s attachments, so no reader’s client ever fetches anything from a third party.
- Typing
Now - Who else is typing in a channel, as the host last said. This client is never among them.
- Voice
Event - What happens in a voice session.
Constants§
- TEXT_
BUDGET - The largest frame text, in bytes as written inside the JSON string that carries it
(
framing::escaped_len: every"or\counts twice), that one message always carries, uncompressed even to a post-quantum connection: 13 124. - TYPING_
SHOWN_ MS - How long one typing signal shows: the host repeats it at most every 3 s while typing goes on, so two missed repeats end it.