Skip to main content

autumn_plugin_discord/
lib.rs

1//! `autumn-plugin-discord`: a Discord bot framework for Autumn.
2//!
3//! Declare slash commands as data, mount the signed interactions webhook,
4//! and answer with typed responses:
5//!
6//! ```ignore
7//! use autumn_plugin_discord::{Command, DiscordPlugin, InteractionResponse, MessagePayload};
8//! use autumn_web::prelude::*;
9//!
10//! async fn ping(ctx: autumn_plugin_discord::CommandContext) -> AutumnResult<InteractionResponse> {
11//!     Ok(InteractionResponse::channel_message(MessagePayload::content("Pong!")))
12//! }
13//!
14//! #[autumn_web::main]
15//! async fn main() {
16//!     autumn_web::app()
17//!         .plugin(DiscordPlugin::new().command(Command::new("ping", "Replies with Pong!").handler(ping)))
18//!         .run()
19//!         .await;
20//! }
21//! ```
22//!
23//! ## Configuration
24//!
25//! ```toml
26//! [discord]
27//! application_id = "123456789012345678"
28//! public_key = "<64 hex chars from the developer portal>"
29//! ```
30//!
31//! The bot token comes only from the `DISCORD_BOT_TOKEN` environment
32//! variable — never from the config file.
33//!
34//! ## Modules
35//!
36//! | Module | Purpose |
37//! |--------|---------|
38//! | [`config`] | Layered `[discord]` config: file, env, builder overrides |
39//! | [`commands`] | Slash-command declarations and dispatch |
40//! | [`interactions`] | The signed webhook route and the [`interactions::VerifiedInteraction`] extractor |
41//! | [`verify`] | Ed25519 signature verification |
42//! | [`client`] | Discord REST client (register commands, follow-ups) |
43//! | [`gateway`] | Minimal gateway client (identify, heartbeat, dispatch) |
44//! | [`health`] | `GET /applications/@me` readiness check |
45//! | [`plugin`] | The [`plugin::DiscordPlugin`] |
46
47#![forbid(unsafe_code)]
48
49pub mod client;
50pub mod commands;
51pub mod config;
52pub mod error;
53#[cfg(feature = "gateway")]
54pub mod gateway;
55pub mod health;
56pub mod interactions;
57pub mod plugin;
58pub mod types;
59pub mod verify;
60
61// ── Re-exports ─────────────────────────────────────────────────────
62pub use client::{API_BASE, ApplicationInfo, DiscordClient};
63pub use commands::{Command, CommandContext, CommandHandler, CommandRegistry, IntoCommandHandler};
64pub use config::DiscordConfig;
65pub use error::{Error, ErrorKind, Result};
66#[cfg(feature = "gateway")]
67pub use gateway::{EventHandler, GATEWAY_URL, GatewayClient};
68pub use health::{DiscordHealth, indicator as health_indicator};
69pub use interactions::VerifiedInteraction;
70pub use plugin::{DiscordPlugin, DiscordRuntime};
71pub use types::{
72    ApplicationCommandData, CommandOption, CommandOptionType, CommandOptionValue,
73    CommandRegistration, Interaction, InteractionResponse, InteractionResponseType,
74    InteractionType, Member, MessagePayload, User,
75};
76pub use verify::{SIGNATURE_HEADER, TIMESTAMP_HEADER, public_key_from_hex, verify_interaction};