Skip to main content

zaun_community_protocol/command/
app.rs

1//! `command.set` and `command.list` (specification ยง8.14).
2
3use serde::{Deserialize, Serialize};
4
5use super::object::{ApplicationCommand, check_commands};
6use super::{BodyError, Validate};
7
8/// `command.set`: a bot replaces its whole command list.
9#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
10pub struct Set {
11    /// Without ids; names keep their `command_id`.
12    pub commands: Vec<ApplicationCommand>,
13}
14
15/// `command.list`.
16#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
17pub struct List {}
18
19/// Response of both: commands with ids (and `bot_id` in `command.list`).
20#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
21pub struct Commands {
22    /// The commands.
23    pub commands: Vec<ApplicationCommand>,
24}
25
26impl Validate for Set {
27    fn validate(&self) -> Result<(), BodyError> {
28        if self
29            .commands
30            .iter()
31            .any(|c| c.command_id.is_some() || c.bot_id.is_some())
32        {
33            return Err(BodyError::bad(
34                "commands.command_id",
35                "is assigned by the host",
36            ));
37        }
38        check_commands(&self.commands)
39    }
40}
41
42impl Validate for List {
43    fn validate(&self) -> Result<(), BodyError> {
44        Ok(())
45    }
46}