Skip to main content

Crate zaun_client

Crate zaun_client 

Source
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.list and every signal.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 .zbot package, 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.
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.
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.
ClientBuilder
Configures a Client. The directory holds the SimpleX store and zaun/, the community keys and state; give every client its own.
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.
DmChannel
A DM channel: an ordinary channel object of kind dm with its two participants.
DmSettings
The member’s settings (member.settings.get / .update response).
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.
Embed
A message’s rich embed as the protocol has it (Message::embeds); build one to send with EmbedBuilder. 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, timestamp and url alone do not count).
EmbedAuthor
A message’s rich embed as the protocol has it (Message::embeds); build one to send with EmbedBuilder. author: {name, url?, icon?} of an embed.
EmbedBuilder
A rich embed, built with chained setters and sent with MessageOptions::embed:
EmbedField
A message’s rich embed as the protocol has it (Message::embeds); build one to send with EmbedBuilder. fields: [{name, value, inline}] of an embed.
EmbedFooter
A message’s rich embed as the protocol has it (Message::embeds); build one to send with EmbedBuilder. footer: {text, icon?} of an 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.
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, 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).
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.
ModalOpen
A bot asks this member to fill in a modal; submit it with Channel::submit_modal and interaction as the modal id.
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.
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.
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.

Enums§

AudioPlayerEvent
What a player tells the application.
AudioPlayerStatus
What a player is doing.
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 fetches anything from a third party.
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.

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.

Type Aliases§

Result
Result with Error.