war-pigeon 0.1.0

An ergonomic Rust client for War Pigeon, the runtime message delivery system.
Documentation
use crate::messages::discord::{
    DiscordEmbed, DiscordSnowflake, components::DiscordComponent, meta::DiscordMentions,
};
use serde::{Deserialize, Serialize};

#[derive(Clone, Debug, Serialize, Deserialize)]
/// A message for discord.
//
// TODO: Implement attachments.
pub struct DiscordMessage {
    /// The message contents.
    ///
    /// NOTE: 2000 characters max limit.
    ///
    /// NOTE: Required if one of [`DiscordMessage::file`], [`DiscordMessage::embeds`],
    /// or [`DiscordMessage::poll`], is not provided.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub content: Option<String>,

    /// An override for the default webhook username.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub username: Option<String>,

    /// An override for the default webhook avatar.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub avatar_url: Option<String>,

    /// Is this a text to speech message?
    ///
    /// NOTE: Defaults to false when [`None`].
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tts: Option<bool>,

    /// An array of embeds for the discord message.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub embeds: Option<Vec<DiscordEmbed>>,

    /// The allowed mention types for the message.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub allowed_mentions: Option<DiscordAllowedMentions>,

    /// An array of components to include in the message.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub components: Option<Vec<DiscordComponent>>,

    /// JSON encoded body of non-file params.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub payload_json: Option<String>,

    /// Message flags combined as a bitfield.
    ///
    /// NOTE: Only `SUPPRESS_EMBEDS`, `SUPPRESS_NOTIFICATIONS`,
    /// and `IS_COMPONENTS_V2` can be set here.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub flags: Option<i64>,

    /// The name of the thread to create.
    ///
    /// NOTE: Requires the webhook channel to be a forum or media channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub thread_name: Option<String>,

    /// An array of tag ids to apply to the thread.
    ///
    /// NOTE: Requires the webhook channel to be a forum or media channel.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub applied_tags: Option<Vec<i64>>,

    /// A poll for the message.
    ///
    /// NOTE: Required if one of [`DiscordMessage::file`], [`DiscordMessage::embeds`],
    /// or [`DiscordMessage::content`], is not provided.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub poll: Option<DiscordPoll>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct DiscordAllowedMentions {
    /// An array of allowed mentions to parse from the content.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub parse: Option<Vec<DiscordMentions>>,

    /// Array of role ids to mention.
    ///
    /// NOTE: maximum of 100.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub roles: Option<Vec<DiscordSnowflake>>,

    /// Array of user ids to mention.
    ///
    /// NOTE: maximum of 100.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub users: Option<Vec<DiscordSnowflake>>,

    /// Whether to mention the author of the message being replied to.
    ///
    /// NOTE: defaults to `false`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub replied_user: Option<bool>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
/// An interactive poll for the discord message.
pub struct DiscordPoll {
    /// The question of the poll (text only).
    pub question: DiscordPollMedia,

    /// Each of the answers available in the poll (max 10).
    pub answers: Vec<DiscordPollAnswer>,

    /// Number of hours the poll should be open for (max 32 days).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub duration: Option<u32>,

    /// Whether a user can select multiple answers.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub allow_multiselect: Option<bool>,

    /// Layout type of the poll (defaults to Discord default).
    #[serde(skip_serializing_if = "Option::is_none")]
    pub layout_type: Option<u8>,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
/// Media content for a discord poll.
pub struct DiscordPollMedia {
    /// Text of the question.
    pub text: String,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
/// An answer to a discord poll.
pub struct DiscordPollAnswer {
    /// Answer data (text only).
    pub answer: DiscordPollMedia,
}