Skip to content

zaun-client 0.6.0

Generated from rustdoc for zaun_client 0.6.0. Browse the full rustdoc HTML.

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.

Item Summary
mention::EVERYONE The text that shows @everyone.
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, uncompr
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.
Item Summary
AudioPlayerEvent What a player tells the application.
AudioPlayerStatus What a player is doing.
ui::EntityKind What an entity select offers.
Error A zaun-client failure.
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 fetche
TypingNow Who else is typing in a channel, as the host last said. This client is never among them.
VoiceEvent What happens in a voice session.
Item Summary
presence::activity An activity of kind named name, for Client::set_presence. Set details, state, started_at, url (streaming) or emoji (custom) on it as needed.
files::guess_mime A media type from a file name’s extension; application/octet-stream otherwise.
registry::inspect_package What a .zbot file says, whether its signature verifies and whether it passes the registry’s package checks.
registry::key_id The id of a base64url public key: what a bot card’s source.registry_id is compared with.
presence::line “Playing {name}”, “Streaming {name}”, “Listening to {name}”, “Watching {name}”, “Competing in {name}”, or {emoji} {name} for a custom one.
files::measure The size and SHA3-256 of the file at path.
mention::member The text that shows a member mention, <@id> (discord.js userMention). It only shows where the mention is: the message’s mentions list is what notifies.
mention::parse The mentions content shows: <@id> (and Discord’s <@!id>) for members, <@&id> for roles, @everyone. Each id once, in order, at most 50 members and 20 roles; malformed ids
mention::role The text that shows a role mention, <@&id> (discord.js roleMention).
files::safe_name A name for name that is safe as one path component: no separators, no control characters, no leading dots; attachment when nothing is left.
registry::verify_catalog Verifies catalog.json bytes and the text of catalog.json.sig against the key of pinned (base64url public keys) that the catalog names, at Unix time now (seconds), after `se
registry::verify_history Verifies the catalog as verify_catalog does (no stored serial), then history/<app_id>.json against the hash the verified catalog lists for it.
Item Summary
ui::ActionRow A row of up to five buttons, or one select.
Attachment A file on a message.
AudioPlayer Plays AudioResources, one at a time, into every subscribed voice session.
AudioResource Something to play: Opus packets, from an Ogg Opus file or stream, from ffmpeg (any format it reads), or from the application.
ui::Button A button: one that sends an interaction (custom_id), or a link the reader confirms.
registry::CatalogCheck verify_catalog’s answer: the registry’s report and, when ok, the verified catalog.
Channel A channel or category of a community.
ui::Checkbox One yes/no box (type 23); never required.
ui::CheckboxGroup Several choices (type 22).
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.
ClientBuilder Configures a Client. The directory holds the SimpleX store and zaun/, the community keys and state; give every client its own.
ui::CommandBuilder A slash, user or message command.
Community A community this client belongs to (or did: a handle outlives a leave).
CommunityData A community as this client last heard of it. Cheap to clone; a clone does not update.
ui::Container A box around other components (type 17).
DmChannel A DM channel: an ordinary channel object of kind dm with its two participants.
EditMessage An edit of one of this member’s messages. A plain &str replaces the text and leaves the embeds and mentions as they are.
EmbedBuilder A rich embed, built with chained setters and sent with MessageOptions::embed:
EphemeralReply 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’s message_id.
FfmpegOptions How AudioResource::ffmpeg_file and its siblings transcode.
ui::File One attached file (type 13).
ui::FileUpload Files the member uploads (type 19).
HandOff What a hand-off signed and published: the new delegation and the descriptor naming it.
registry::HistoryCheck verify_history’s answer: the registry’s report and, when ok, the verified history.
Interaction Someone used one of this bot’s commands, components or modals. Answer within 3 s (respond, or Response::defer first); follow-ups and edits work for 15 minutes.
InteractionFailure An interaction that got no answer (the bot timed out, failed or is not running).
registry::KeyIdReport key_id’s answer.
ui::MediaGallery Up to ten pictures (type 12).
Member A member of a community.
Message A message in a channel.
MessageOptions A message to post: text, embeds, files and the message it answers. A plain &str is one with text only, so channel.send("hi") still reads as it did.
ui::Modal A modal: up to five labelled inputs and texts.
ModalOpen A bot asks this member to fill in a modal; submit it with Channel::submit_modal and interaction as the modal id.
ui::OptionBuilder An option of a slash command.
PartialMessage 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
PendingMessage A post on its way (Channel::send_pending): what to show until the host answers.
Presence A member’s presence as everyone else sees it (invisible members look Offline).
ui::RadioGroup One choice among options (type 21).
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.
ui::Section One to three texts with a button or thumbnail beside them (type 9).
ui::Select A select menu.
ui::Separator A line or a gap (type 14).
Suggestions A bot’s suggestions for the option this member is typing.
ui::TextDisplay Markdown text (type 10).
ui::TextInput A text field.
ui::Thumbnail A picture beside a section (type 11).
TypingSeen A typing state and when it stops showing.
VoiceLeave Why someone left a voice channel.
VoiceMute Someone’s mute and deafen state in a voice channel.
VoiceOptions How a voice session connects.
VoiceSession One stay in a voice channel. Dropping it leaves the channel.
VoiceState Someone’s state in a voice channel.
Item Summary
Result Result with Error.