Skip to main content

zaun_community_protocol/command/object/
member.rs

1//! The member object and ban records (specification §8.3).
2
3use serde::{Deserialize, Serialize};
4
5use crate::ids::{BanId, BotId, ChannelId, InviteId, MemberId, RoleId};
6use crate::model::MembershipState;
7
8/// A member as visible to the viewer (§8.3). Optional fields depend on the viewer's
9/// permissions; the host filters them.
10#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
11pub struct Member {
12    /// Host-assigned id.
13    pub member_id: MemberId,
14    /// 1–32 scalars.
15    pub display_name: String,
16    /// Assigned roles; `@everyone` is implicit and never listed.
17    pub role_ids: Vec<RoleId>,
18    /// Admission time, ms.
19    pub joined_at: u64,
20    /// Only for `TIMEOUT_MEMBERS` viewers and the member itself.
21    #[serde(default, skip_serializing_if = "Option::is_none")]
22    pub timeout_until: Option<u64>,
23    /// Only for the member itself and `APPROVE_MEMBERS`/`KICK_MEMBERS` viewers.
24    #[serde(default, skip_serializing_if = "Option::is_none")]
25    pub state: Option<MembershipState>,
26    /// Only for `APPROVE_MEMBERS` viewers.
27    #[serde(default, skip_serializing_if = "Option::is_none")]
28    pub admission: Option<Admission>,
29    /// The membership request note: `membership.pending` and `membership.requested` only.
30    ///
31    /// SPEC: §8.9/§9.2 say the member object comes "with `admission` and `note`" without
32    /// placing `note`; it is modelled as a member field.
33    #[serde(default, skip_serializing_if = "Option::is_none")]
34    pub note: Option<String>,
35    /// Present only for bots (§8.13).
36    #[serde(default, skip_serializing_if = "Option::is_none")]
37    pub bot_id: Option<BotId>,
38    /// The custom status text (`member.status.set`), until it expires.
39    #[serde(default, skip_serializing_if = "Option::is_none")]
40    pub status_text: Option<String>,
41    /// The custom status emoji.
42    #[serde(default, skip_serializing_if = "Option::is_none")]
43    pub status_emoji: Option<String>,
44    /// When the host clears the custom status, ms.
45    #[serde(default, skip_serializing_if = "Option::is_none")]
46    pub status_expires_at: Option<u64>,
47    /// Only in what the host sends a bot: the voice channel the member is connected to, when
48    /// the bot can see that channel (so `/play` can join the caller).
49    #[serde(default, skip_serializing_if = "Option::is_none")]
50    pub voice_channel_id: Option<ChannelId>,
51}
52
53/// How a member was admitted (§8.3).
54#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
55pub struct Admission {
56    /// `"invite"` or `"request"`.
57    pub via: AdmissionVia,
58    /// The invitation redeemed.
59    #[serde(default, skip_serializing_if = "Option::is_none")]
60    pub invite_id: Option<InviteId>,
61    /// The sponsoring member.
62    #[serde(default, skip_serializing_if = "Option::is_none")]
63    pub sponsored_by: Option<MemberId>,
64    /// The approving moderator.
65    #[serde(default, skip_serializing_if = "Option::is_none")]
66    pub approved_by: Option<MemberId>,
67}
68
69/// `admission.via` (§8.3). SPEC: a plain string (`"invite" | "request"`), not `{t}`.
70#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
71#[serde(rename_all = "snake_case")]
72pub enum AdmissionVia {
73    /// `invite.redeem`.
74    Invite,
75    /// `membership.request`.
76    Request,
77}
78
79/// One entry of `member.bans` (§8.3).
80#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
81pub struct Ban {
82    /// The ban record.
83    pub ban_id: BanId,
84    /// The banned member's display name at ban time.
85    pub display_name: String,
86    /// The moderator's reason, if given.
87    pub reason: Option<String>,
88    /// The banning moderator.
89    pub actor_id: MemberId,
90    /// Ban time, ms.
91    pub at: u64,
92}