djs_model/lobby.rs
1//! [Lobbies](https://docs.discord.com/developers/resources/lobby): groups of users of an app's
2//! game (Discord Social SDK), managed by the app over HTTP, optionally linked to a guild
3//! channel.
4
5use std::collections::BTreeMap;
6
7use compact_str::CompactString;
8use serde::{Deserialize, Serialize};
9
10use crate::{
11 channel::Channel,
12 id::{ApplicationId, ChannelId, LobbyId, MessageId, UserId},
13 macros::int_flags,
14 message::{MessageFlags, MessageType},
15 user::User,
16 util::Timestamp,
17};
18
19/// A [lobby](https://docs.discord.com/developers/resources/lobby#lobby-object).
20///
21/// discord.js counterpart: none (lobbies are not in discord.js v14 or discord-api-types).
22#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
23#[non_exhaustive]
24pub struct Lobby {
25 /// The lobby's ID.
26 pub id: LobbyId,
27 /// The application that created the lobby.
28 pub application_id: ApplicationId,
29 /// String key/value pairs set by the app (max 1000 characters in total; `null` and absent
30 /// are empty, D-058).
31 #[serde(
32 default,
33 skip_serializing_if = "BTreeMap::is_empty",
34 deserialize_with = "crate::serde_util::null_as_default"
35 )]
36 pub metadata: BTreeMap<CompactString, CompactString>,
37 /// The lobby's members.
38 #[serde(default)]
39 pub members: Vec<LobbyMember>,
40 /// The guild channel linked to the lobby.
41 #[serde(default, skip_serializing_if = "Option::is_none")]
42 pub linked_channel: Option<Box<Channel>>,
43}
44
45/// A [lobby member](https://docs.discord.com/developers/resources/lobby#lobby-member-object).
46///
47/// discord.js counterpart: none (lobbies are not in discord.js v14 or discord-api-types).
48#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
49#[non_exhaustive]
50pub struct LobbyMember {
51 /// The user's ID.
52 pub id: UserId,
53 /// String key/value pairs set by the app (max 1000 characters in total).
54 #[serde(
55 default,
56 skip_serializing_if = "BTreeMap::is_empty",
57 deserialize_with = "crate::serde_util::null_as_default"
58 )]
59 pub metadata: BTreeMap<CompactString, CompactString>,
60 /// The member's flags.
61 #[serde(default, skip_serializing_if = "LobbyMemberFlags::is_empty")]
62 pub flags: LobbyMemberFlags,
63 /// An extra display name (1-80 characters), e.g. an in-game character name.
64 #[serde(default, skip_serializing_if = "Option::is_none")]
65 pub additional_name: Option<CompactString>,
66}
67
68int_flags! {
69 /// [Flags of a lobby member](https://docs.discord.com/developers/resources/lobby#lobby-member-object-lobby-member-flags).
70 ///
71 /// discord.js counterpart: none (lobbies are not in discord.js v14 or discord-api-types).
72 pub struct LobbyMemberFlags: u64 {
73 /// The member can link a text channel to the lobby.
74 const CAN_LINK_LOBBY = 1 << 0;
75 }
76}
77
78/// A [message sent in a lobby](https://docs.discord.com/developers/resources/lobby#lobby-message-object)
79/// (or in a linked channel).
80///
81/// Also the data of the `LOBBY_MESSAGE_CREATE` and `LOBBY_MESSAGE_UPDATE`
82/// [webhook events](crate::webhook_event), where `application_id` is optional and updates add
83/// `timestamp` and `edited_timestamp` (D-078).
84///
85/// discord.js counterpart: none (lobbies are not in discord.js v14 or discord-api-types).
86#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
87#[non_exhaustive]
88pub struct LobbyMessage {
89 /// The message's ID.
90 pub id: MessageId,
91 /// The message's type.
92 #[serde(rename = "type")]
93 pub kind: MessageType,
94 /// The message's text.
95 pub content: CompactString,
96 /// The lobby it was sent to.
97 pub lobby_id: LobbyId,
98 /// Equal to [`lobby_id`](Self::lobby_id), for compatibility with messages.
99 pub channel_id: ChannelId,
100 /// The author.
101 pub author: User,
102 /// The author's lobby member data when the message was sent (if they had an additional
103 /// name).
104 #[serde(default, skip_serializing_if = "Option::is_none")]
105 pub lobby_member: Option<LobbyMessageMember>,
106 /// Key/value pairs delivered with the message to active Social SDK clients.
107 #[serde(
108 default,
109 skip_serializing_if = "BTreeMap::is_empty",
110 deserialize_with = "crate::serde_util::null_as_default"
111 )]
112 pub metadata: BTreeMap<CompactString, CompactString>,
113 /// Moderation key/value pairs set by the app.
114 #[serde(
115 default,
116 skip_serializing_if = "BTreeMap::is_empty",
117 deserialize_with = "crate::serde_util::null_as_default"
118 )]
119 pub moderation_metadata: BTreeMap<CompactString, CompactString>,
120 /// The message's flags.
121 #[serde(default)]
122 pub flags: MessageFlags,
123 /// The application that sent the message (always set by the lobby endpoints; in webhook
124 /// events only during active Social SDK sessions).
125 #[serde(default, skip_serializing_if = "Option::is_none")]
126 pub application_id: Option<ApplicationId>,
127 /// When the message was sent (sent by `LOBBY_MESSAGE_UPDATE` webhook events).
128 #[serde(default, skip_serializing_if = "Option::is_none")]
129 pub timestamp: Option<Timestamp>,
130 /// When the message was last edited (sent by `LOBBY_MESSAGE_UPDATE` webhook events).
131 #[serde(default, skip_serializing_if = "Option::is_none")]
132 pub edited_timestamp: Option<Timestamp>,
133}
134
135/// The author's lobby member data in a [`LobbyMessage`].
136///
137/// discord.js counterpart: none (lobbies are not in discord.js v14 or discord-api-types).
138#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
139#[non_exhaustive]
140pub struct LobbyMessageMember {
141 /// The author's additional display name.
142 pub additional_name: CompactString,
143}
144
145/// A [lobby invite](https://docs.discord.com/developers/resources/lobby#create-lobby-channel-invite-for-self):
146/// an invite to the lobby's linked channel.
147///
148/// discord.js counterpart: none (lobbies are not in discord.js v14 or discord-api-types).
149#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
150#[non_exhaustive]
151pub struct LobbyInvite {
152 /// The invite code.
153 pub code: CompactString,
154}