1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
//! [Applications](https://docs.discord.com/developers/resources/application): the apps (and
//! their bot users) registered in the Developer Portal.
use compact_str::CompactString;
use serde::{Deserialize, Serialize};
use crate::{
guild::PartialGuild,
id::{ApplicationId, ChannelId, GenericId, GuildId, SkuId, UserId},
macros::{int_enum, int_flags, str_enum},
oauth2::Scope,
permissions::Permissions,
team::Team,
user::User,
util::ImageHash,
webhook_event::WebhookEventType,
};
/// An [application](https://docs.discord.com/developers/resources/application#application-object).
///
/// discord.js counterpart: `ClientApplication` / `Application`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct Application {
/// The application's ID.
pub id: ApplicationId,
/// The application's name.
pub name: CompactString,
/// The [icon hash](https://docs.discord.com/developers/reference#image-formatting).
pub icon: Option<ImageHash>,
/// The application's description.
pub description: CompactString,
/// RPC origin URLs, if RPC is enabled.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub rpc_origins: Vec<CompactString>,
/// Whether anyone (not only the owner) can add the bot to guilds.
pub bot_public: bool,
/// Whether the bot only joins after the full `OAuth2` code grant flow.
pub bot_require_code_grant: bool,
/// The application's bot user.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub bot: Option<Box<User>>,
/// The URL of the terms of service.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub terms_of_service_url: Option<CompactString>,
/// The URL of the privacy policy.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub privacy_policy_url: Option<CompactString>,
/// The application's owner (for team-owned apps, a team pseudo-user).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub owner: Option<Box<User>>,
/// The hex-encoded public key used to verify interaction requests.
pub verify_key: CompactString,
/// The team that owns the application.
pub team: Option<Box<Team>>,
/// The guild associated with the application (e.g. its support server).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub guild_id: Option<GuildId>,
/// The associated guild.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub guild: Option<Box<PartialGuild>>,
/// For games sold on Discord, the "Game SKU".
#[serde(default, skip_serializing_if = "Option::is_none")]
pub primary_sku_id: Option<SkuId>,
/// For games sold on Discord, the URL slug of the store page.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub slug: Option<CompactString>,
/// The default rich presence invite [cover image hash](https://docs.discord.com/developers/reference#image-formatting).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cover_image: Option<ImageHash>,
/// The application's public flags (legacy integer field).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub flags: Option<ApplicationFlags>,
/// The application's public flags, sent as a decimal string.
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "crate::serde_util::option_flags_string"
)]
pub flags_new: Option<ApplicationFlags>,
/// The approximate number of guilds the app is in.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub approximate_guild_count: Option<u32>,
/// The approximate number of users who installed the app.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub approximate_user_install_count: Option<u32>,
/// The approximate number of users with an `OAuth2` authorization for the app.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub approximate_user_authorization_count: Option<u32>,
/// The `OAuth2` redirect URIs.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub redirect_uris: Vec<CompactString>,
/// The [interactions endpoint URL](https://docs.discord.com/developers/interactions/receiving-and-responding#receiving-an-interaction).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub interactions_endpoint_url: Option<CompactString>,
/// The role connection (linked roles) verification URL.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub role_connections_verification_url: Option<CompactString>,
/// The URL that receives [webhook events](https://docs.discord.com/developers/events/webhook-events).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub event_webhooks_url: Option<CompactString>,
/// Whether webhook events are enabled.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub event_webhooks_status: Option<EventWebhookStatus>,
/// The webhook events the app subscribes to.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub event_webhooks_types: Vec<WebhookEventType>,
/// Up to 5 tags describing the app.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub tags: Vec<CompactString>,
/// The settings of the app's default in-app authorization link.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub install_params: Option<InstallParams>,
/// The default scopes and permissions per installation context.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub integration_types_config: Option<IntegrationTypesConfig>,
/// The custom authorization URL, if set.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub custom_install_url: Option<CompactString>,
}
/// A partial [`Application`], as attached to invites (`target_application`) (D-051).
///
/// discord.js counterpart: a partial `APIApplication` (discord-api-types), as `IntegrationApplication`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct PartialApplication {
/// The application's ID.
pub id: ApplicationId,
/// The application's name.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub name: Option<CompactString>,
/// The [icon hash](https://docs.discord.com/developers/reference#image-formatting).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub icon: Option<ImageHash>,
/// The application's description.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub description: Option<CompactString>,
/// The [cover image hash](https://docs.discord.com/developers/reference#image-formatting).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub cover_image: Option<ImageHash>,
/// The application's public flags.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub flags: Option<ApplicationFlags>,
}
int_enum! {
/// [Where an app can be installed](https://docs.discord.com/developers/resources/application#application-object-application-integration-types).
///
/// discord.js counterpart: `ApplicationIntegrationType`.
#[doc(alias = "ApplicationIntegrationType")]
pub enum IntegrationType: u8 {
/// In guilds (servers).
GuildInstall = 0,
/// For users (the app follows the user everywhere).
UserInstall = 1,
}
}
/// The default install settings per installation context; the keys of
/// [`integration_types_config`](Application::integration_types_config).
///
/// discord.js counterpart: `APIApplicationIntegrationTypesConfigMap` (discord-api-types).
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct IntegrationTypesConfig {
/// For guild installs (key `"0"`).
#[serde(rename = "0", default, skip_serializing_if = "Option::is_none")]
pub guild_install: Option<IntegrationTypeConfig>,
/// For user installs (key `"1"`).
#[serde(rename = "1", default, skip_serializing_if = "Option::is_none")]
pub user_install: Option<IntegrationTypeConfig>,
}
/// The [install settings of one installation context](https://docs.discord.com/developers/resources/application#application-object-application-integration-type-configuration-object).
///
/// discord.js counterpart: `APIApplicationIntegrationTypeConfiguration` (discord-api-types).
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct IntegrationTypeConfig {
/// The scopes and permissions of the context's default in-app authorization link.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub oauth2_install_params: Option<InstallParams>,
}
/// The [settings of an in-app authorization link](https://docs.discord.com/developers/resources/application#install-params-object).
///
/// discord.js counterpart: `ClientApplicationInstallParams`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct InstallParams {
/// The scopes to authorize.
pub scopes: Vec<Scope>,
/// The permissions requested for the bot role.
pub permissions: Permissions,
}
impl InstallParams {
/// An authorization link for `scopes`, requesting `permissions` for the bot role (only
/// used with the `bot` scope).
///
/// discord.js counterpart: the `scopes` and `permissions` of `InviteGenerationOptions`.
#[must_use]
pub fn new(scopes: impl IntoIterator<Item = Scope>, permissions: Permissions) -> Self {
Self {
scopes: scopes.into_iter().collect(),
permissions,
}
}
}
int_enum! {
/// [Whether webhook events are enabled](https://docs.discord.com/developers/resources/application#application-object-application-event-webhook-status).
///
/// discord.js counterpart: `ApplicationWebhookEventStatus`.
pub enum EventWebhookStatus: u8 {
/// Disabled by the developer (the default).
Disabled = 1,
/// Enabled by the developer.
Enabled = 2,
/// Disabled by Discord, usually because of inactivity.
DisabledByDiscord = 3,
}
}
/// A running [Activity instance](https://docs.discord.com/developers/resources/application#get-application-activity-instance-activity-instance-object).
///
/// discord.js counterpart: `ActivityInstance`.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ActivityInstance {
/// The application.
pub application_id: ApplicationId,
/// The instance's ID.
pub instance_id: CompactString,
/// The unique ID of the launch.
pub launch_id: GenericId,
/// Where the instance runs.
pub location: ActivityLocation,
/// The users connected to the instance.
pub users: Vec<UserId>,
}
/// [Where an Activity instance runs](https://docs.discord.com/developers/resources/application#get-application-activity-instance-activity-location-object).
///
/// discord.js counterpart: `ActivityLocation`.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[non_exhaustive]
pub struct ActivityLocation {
/// The location's ID.
pub id: CompactString,
/// Whether the location is a guild channel or a private channel.
pub kind: ActivityLocationKind,
/// The channel.
pub channel_id: ChannelId,
/// The guild, for guild channels.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub guild_id: Option<GuildId>,
}
str_enum! {
/// The [kind of an Activity location](https://docs.discord.com/developers/resources/application#get-application-activity-instance-activity-location-kind-enum).
///
/// discord.js counterpart: `ActivityLocationKind` (discord-api-types).
pub enum ActivityLocationKind {
/// A guild channel.
GuildChannel = "gc",
/// A private channel (DM or group DM).
PrivateChannel = "pc",
}
}
int_flags! {
/// [Flags of an application](https://docs.discord.com/developers/resources/application#application-object-application-flags).
///
/// The `GATEWAY_*` flags tell whether the app may use the privileged
/// [intents](crate::gateway::Intents): the plain flag is granted after approval (bots in 100
/// or more servers), the `*_LIMITED` flag when it is enabled in the Developer Portal for a
/// bot in fewer than 100 servers.
///
/// discord.js counterpart: `ApplicationFlags` / `ApplicationFlagsBitField`.
///
/// # Examples
///
/// ```
/// use djs_model::application::ApplicationFlags;
///
/// let flags: ApplicationFlags = serde_json::from_str("532480").unwrap();
/// assert!(flags.contains(ApplicationFlags::GATEWAY_MESSAGE_CONTENT_LIMITED));
/// ```
pub struct ApplicationFlags: u64 {
/// The app's embedded activity has been released.
///
/// **Undocumented:** known from discord-api-types, not in the official docs; may
/// change without notice.
const EMBEDDED_RELEASED = 1 << 1;
/// The app can manage emojis.
///
/// **Undocumented:** known from discord-api-types, not in the official docs; may
/// change without notice.
const MANAGED_EMOJI = 1 << 2;
/// The app's embedded activity supports in-app purchases.
///
/// **Undocumented:** known from discord-api-types, not in the official docs; may
/// change without notice.
const EMBEDDED_IAP = 1 << 3;
/// The app can create group DMs.
///
/// **Undocumented:** known from discord-api-types, not in the official docs; may
/// change without notice.
const GROUP_DM_CREATE = 1 << 4;
/// The app uses the [Auto Moderation API](https://docs.discord.com/developers/resources/auto-moderation)
/// (shown as a badge on its profile).
const APPLICATION_AUTO_MODERATION_RULE_CREATE_BADGE = 1 << 6;
/// The app has connected to RPC.
///
/// **Undocumented:** known from discord-api-types, not in the official docs; may
/// change without notice.
const RPC_HAS_CONNECTED = 1 << 11;
/// Approved for the privileged presence intent (bots in 100 or more servers).
const GATEWAY_PRESENCE = 1 << 12;
/// Presence intent enabled in the Developer Portal (bots in fewer than 100 servers).
const GATEWAY_PRESENCE_LIMITED = 1 << 13;
/// Approved for the privileged guild members intent (bots in 100 or more servers).
const GATEWAY_GUILD_MEMBERS = 1 << 14;
/// Guild members intent enabled in the Developer Portal (bots in fewer than 100
/// servers).
const GATEWAY_GUILD_MEMBERS_LIMITED = 1 << 15;
/// Unusual growth of the app prevents its verification.
const VERIFICATION_PENDING_GUILD_LIMIT = 1 << 16;
/// The app is embedded in the Discord client (not publicly available).
const EMBEDDED = 1 << 17;
/// Approved for the privileged message content intent (bots in 100 or more servers).
const GATEWAY_MESSAGE_CONTENT = 1 << 18;
/// Message content intent enabled in the Developer Portal (bots in fewer than 100
/// servers).
const GATEWAY_MESSAGE_CONTENT_LIMITED = 1 << 19;
/// The embedded app is made by Discord.
///
/// **Undocumented:** known from discord-api-types, not in the official docs; may
/// change without notice.
const EMBEDDED_FIRST_PARTY = 1 << 20;
/// The app has registered global application commands (shown as a badge on its
/// profile).
const APPLICATION_COMMAND_BADGE = 1 << 23;
}
}