Skip to main content

zaun_community_protocol/event/body/
bot.rs

1//! Bot and interaction event bodies (§9.2, §8.13, §8.14).
2
3use serde::{Deserialize, Serialize};
4
5use crate::command::object::{ApplicationCommand, Choice, Component, Message};
6use crate::ids::{BotId, InteractionId, MemberId};
7
8/// `bot.removed`: `{bot_id, member_id}`.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
10pub struct BotRemoved {
11    /// The bot.
12    pub bot_id: BotId,
13    /// Its member.
14    pub member_id: MemberId,
15}
16
17/// `command.updated`: one bot's whole command list (`[]` while disabled or removed).
18#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
19pub struct CommandsUpdated {
20    /// The bot.
21    pub bot_id: BotId,
22    /// Its commands.
23    pub commands: Vec<ApplicationCommand>,
24}
25
26/// `op` of `interaction.message`.
27#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
28#[serde(rename_all = "snake_case")]
29pub enum EphemeralOp {
30    /// A new ephemeral message.
31    Created,
32    /// It changed.
33    Updated,
34    /// It is gone.
35    Deleted,
36}
37
38/// `interaction.message`: an ephemeral message, to the invoker only.
39#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
40pub struct InteractionMessage {
41    /// The interaction.
42    pub interaction_id: InteractionId,
43    /// What happened.
44    pub op: EphemeralOp,
45    /// The message (absent for `deleted`).
46    #[serde(default, skip_serializing_if = "Option::is_none")]
47    pub message: Option<Box<Message>>,
48}
49
50/// `interaction.modal`: open a modal, to the invoker only.
51#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
52pub struct InteractionModal {
53    /// The interaction that opened it; submit with it as `modal_id`.
54    pub interaction_id: InteractionId,
55    /// The modal's `custom_id`.
56    pub custom_id: String,
57    /// 1–45 scalars.
58    pub title: String,
59    /// 1–5 labels or text displays.
60    pub components: Vec<Component>,
61}
62
63/// `interaction.autocomplete`: suggestions, to the invoker only.
64#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
65pub struct InteractionAutocomplete {
66    /// The interaction.
67    pub interaction_id: InteractionId,
68    /// ≤ 25.
69    pub choices: Vec<Choice>,
70}
71
72/// Why an interaction failed.
73#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
74#[serde(rename_all = "snake_case")]
75pub enum FailReason {
76    /// No answer within 3 s.
77    Timeout,
78    /// The bot trapped or answered with an error.
79    BotError,
80    /// The bot is disabled, crashed or not connected.
81    BotUnavailable,
82}
83
84/// `interaction.failed`, to the invoker only.
85#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
86pub struct InteractionFailed {
87    /// The interaction.
88    pub interaction_id: InteractionId,
89    /// Why.
90    pub reason: FailReason,
91}
92
93/// `dm.closed`: to the closer's own stream (§8.15).
94#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
95pub struct DmClosed {
96    /// The DM.
97    pub channel_id: crate::ids::ChannelId,
98}