Skip to main content

zaun_community_protocol/command/
dm.rs

1//! Direct messages between a bot and a member (specification ยง8.15), and the member's own
2//! setting for them.
3
4use serde::{Deserialize, Serialize};
5
6use super::object::Channel;
7use super::{BodyError, Validate};
8use crate::ids::{ChannelId, MemberId};
9
10/// `dm.open`: the DM with `member_id`, created when there is none (idempotent per pair).
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
12pub struct Open {
13    /// The other participant: a member when a bot opens it, a bot when a member does.
14    pub member_id: MemberId,
15}
16
17/// `dm.close`: hides the DM for the actor.
18#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
19pub struct Close {
20    /// The DM.
21    pub channel_id: ChannelId,
22}
23
24/// `dm.list`.
25#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
26pub struct List {}
27
28/// `dm.list` response: the actor's open DMs.
29#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
30pub struct Channels {
31    /// Channel objects of kind `dm`.
32    pub channels: Vec<Channel>,
33}
34
35/// `member.settings.get`.
36#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
37pub struct SettingsGet {}
38
39/// `member.settings.update`: absent fields stay.
40#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
41pub struct SettingsUpdate {
42    /// Whether bots may open DMs with this member.
43    #[serde(default, skip_serializing_if = "Option::is_none")]
44    pub dms_from_bots: Option<bool>,
45}
46
47/// The member's settings (`member.settings.get` / `.update` response).
48#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
49pub struct Settings {
50    /// Whether bots may open DMs with this member (default true).
51    pub dms_from_bots: bool,
52}
53
54macro_rules! no_checks {
55    ($($t:ty),*) => {
56        $(impl Validate for $t {
57            fn validate(&self) -> Result<(), BodyError> {
58                Ok(())
59            }
60        })*
61    };
62}
63no_checks!(Open, Close, List, SettingsGet, SettingsUpdate);