-
-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathapplication.h
523 lines (439 loc) · 13.3 KB
/
application.h
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/integration.h>
#include <dpp/export.h>
#include <dpp/snowflake.h>
#include <dpp/managed.h>
#include <dpp/utility.h>
#include <dpp/user.h>
#include <dpp/guild.h>
#include <dpp/permissions.h>
#include <dpp/json_fwd.h>
#include <dpp/json_interface.h>
#include <map>
#include <optional>
namespace dpp {
/**
* @brief status of a member of a team who maintain a bot/application
*/
enum team_member_status : uint8_t {
/**
* @brief User was invited to the team.
*/
tms_invited = 1,
/**
* @brief User has accepted membership onto the team.
*/
tms_accepted = 2
};
/**
* @brief Flags for a bot or application
*/
enum application_flags : uint32_t {
/**
* @brief Indicates if an app uses the Auto Moderation API
*/
apf_application_automod_rule_create_badge = (1 << 6),
/**
* @brief Has gateway presence intent
*/
apf_gateway_presence = (1 << 12),
/**
* @brief Has gateway presence intent for <100 guilds
*/
apf_gateway_presence_limited = (1 << 13),
/**
* @brief Has guild members intent
*/
apf_gateway_guild_members = (1 << 14),
/**
* @brief Has guild members intent for <100 guilds
*/
apf_gateway_guild_members_limited = (1 << 15),
/**
* @brief Verification is pending
*/
apf_verification_pending_guild_limit = (1 << 16),
/**
* @brief Embedded
*/
apf_embedded = (1 << 17),
/**
* @brief Has approval for message content
*/
apf_gateway_message_content = (1 << 18),
/**
* @brief Has message content, but <100 guilds
*/
apf_gateway_message_content_limited = (1 << 19),
/**
* @brief Indicates if the app has registered global application commands
*/
apf_application_command_badge = (1 << 23)
};
/**
* @brief Represents the settings for the bot/application's in-app authorization link
*/
struct DPP_EXPORT application_install_params {
/**
* @brief A bitmask of dpp::permissions to request for the bot role.
*/
permission permissions;
/**
* @brief The scopes as strings to add the application to the server with.
*
* @see https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes
*/
std::vector<std::string> scopes;
};
/**
* @brief Team member role types for application team members.
*
* These are hard coded to string forms by discord. If further types are added,
* this enum will be extended to support them.
*/
enum team_member_role_t : uint8_t {
/**
* @brief Team owner.
*/
tmr_owner,
/**
* @brief Team admin.
*/
tmr_admin,
/**
* @brief Developer
*/
tmr_developer,
/**
* @brief Read-Only
*/
tmr_readonly,
};
/**
* @brief Represents a team member on a team who maintain a bot/application
*/
class DPP_EXPORT team_member {
public:
/**
* @brief The user's membership state on the team.
*/
team_member_status membership_state;
/**
* @brief Will always be "".
*/
std::string permissions;
/**
* @brief The id of the parent team of which they are a member.
*/
snowflake team_id;
/**
* @brief The avatar, discriminator, id, and username, of the user.
*/
user member_user;
/**
* @brief The role of the user in the team.
*/
team_member_role_t member_role;
};
/**
* @brief Represents a team of users who maintain a bot/application
*/
class DPP_EXPORT app_team {
public:
/**
* @brief A hash of the image of the team's icon (may be empty).
*/
utility::iconhash icon;
/**
* @brief The id of the team.
*/
snowflake id;
/**
* @brief The members of the team.
*/
std::vector<team_member> members;
/**
* @brief The name of the team.
*/
std::string name;
/**
* @brief The user id of the current team owner.
*/
snowflake owner_user_id;
};
/**
* @brief Status indicating whether event webhooks are enabled or disabled for an application.
*/
enum application_event_webhook_status: uint8_t {
/**
* @brief Webhook events are disabled by developer
*/
ews_disabled = 1,
/**
* @brief Webhook events are enabled by developer
*/
ews_enabled = 2,
/**
* @brief Webhook events are disabled by Discord, usually due to inactivity
*/
ews_disabled_by_discord = 3,
};
/**
* @brief Configuration object for an app installation
*/
struct DPP_EXPORT integration_configuration {
application_install_params oauth2_install_params;
};
/**
* @brief The application class represents details of a bot application
*/
class DPP_EXPORT application : public managed, public json_interface<application> {
protected:
friend struct json_interface<application>;
/** Read class values from json object
* @param j A json object to read from
* @return A reference to self
*/
application& fill_from_json_impl(nlohmann::json* j);
public:
/**
* @brief The name of the app.
*/
std::string name;
/**
* @brief The icon hash of the app (may be empty).
*/
utility::iconhash icon;
/**
* @brief The description of the app.
*/
std::string description;
/**
* @brief Optional: an array of rpc origin urls, if rpc is enabled.
*/
std::vector<std::string> rpc_origins;
/**
* @brief When false, only app owner add the bot to guilds.
*/
bool bot_public;
/**
* @brief When true, the app's bot will only join upon completion of the full oauth2 code grant flow
*/
bool bot_require_code_grant;
/**
* @brief Optional: Partial user object for the bot user associated with the app.
*/
user bot;
/**
* @brief Optional: the url of the app's terms of service.
*/
std::string terms_of_service_url;
/**
* @brief Optional: the url of the app's privacy policy.
*/
std::string privacy_policy_url;
/**
* @brief Optional: partial user object containing info on the owner of the application.
*/
user owner;
/**
* @brief If this application is a game sold on Discord, this field will be the summary field for the store page of its primary SKU.
*
* @deprecated Will be removed in v11
*/
std::string summary;
/**
* @brief The hex encoded key for verification in interactions and the GameSDK's GetTicket.
*/
std::string verify_key;
/**
* @brief If the application belongs to a team, this will be a list of the members of that team (may be empty).
*/
app_team team;
/**
* @brief Optional: if this application is a game sold on Discord, this field will be the guild to which it has been linked.
*/
snowflake guild_id;
/**
* @brief Partial object of the associated guild.
*/
guild guild_obj;
/**
* @brief Optional: if this application is a game sold on Discord, this field will be the id of the "Game SKU" that is created, if exists.
*/
snowflake primary_sku_id;
/**
* @brief Optional: if this application is a game sold on Discord, this field will be the URL slug that links to the store page.
*/
std::string slug;
/**
* @brief Optional: the application's default rich presence invite cover image hash
*/
utility::iconhash cover_image;
/**
* @brief Optional: the application's public flags.
*/
uint32_t flags;
/**
* @brief Optional: Approximate count of guilds the app has been added to.
*/
uint64_t approximate_guild_count;
/**
* @brief Optional: Approximate count of users that have installed the app
*/
uint64_t approximate_user_install_count;
/**
* @brief Optional: Array of redirect URIs for the app.
*/
std::vector<std::string> redirect_uris;
/**
* @brief Optional: Interactions endpoint URL for the app.
*/
std::string interactions_endpoint_url;
/**
* @brief The application's role connection verification entry point
* which, when configured, will render the app as a verification method
* in the guild role verification configuration.
*/
std::string role_connections_verification_url;
/**
* @brief Event webhooks URL for the app to receive webhook events
*/
std::string event_webhooks_url;
/**
* @brief List of Webhook event types the app subscribes to.
*/
std::vector<std::string> event_webhooks_types;
/**
* If webhook events are enabled for the app.
*/
application_event_webhook_status event_webhooks_status;
/**
* @brief Up to 5 tags describing the content and functionality of the application.
*/
std::vector<std::string> tags;
/**
* @brief Settings for the application's default in-app authorization link, if enabled.
*/
application_install_params install_params;
/**
* @brief Default scopes and permissions for each supported installation context
*/
std::map<application_integration_types, integration_configuration> integration_types_config;
/**
* @brief The application's default custom authorization link, if enabled.
*/
std::string custom_install_url;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
uint8_t discoverability_state;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
uint32_t discovery_eligibility_flags;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
uint8_t explicit_content_filter;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
uint8_t creator_monetization_state;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
bool integration_public;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
bool integration_require_code_grant;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
std::vector<std::string> interactions_event_types;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
uint8_t interactions_version;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
bool is_monetized;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
uint32_t monetization_eligibility_flags;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
uint8_t monetization_state;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
bool hook;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
uint8_t rpc_application_state;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
uint8_t store_application_state;
/**
* @warning This variable is not documented by discord, we have no idea what it means and how it works. Use at your own risk.
*/
uint8_t verification_state;
/** Constructor */
application();
/** Destructor */
~application();
/**
* @brief Get the application's cover image url if they have one, otherwise returns an empty string
*
* @param size The size of the cover image in pixels. It can be any power of two between 16 and 4096,
* otherwise the default sized cover image is returned.
* @param format The format to use for the avatar. It can be one of `i_webp`, `i_jpg` or `i_png`.
* @return std::string cover image url or an empty string, if required attributes are missing or an invalid format was passed
*/
std::string get_cover_image_url(uint16_t size = 0, const image_type format = i_png) const;
/**
* @brief Get the application's icon url if they have one, otherwise returns an empty string
*
* @param size The size of the icon in pixels. It can be any power of two between 16 and 4096,
* otherwise the default sized icon is returned.
* @param format The format to use for the avatar. It can be one of `i_webp`, `i_jpg` or `i_png`.
* @return std::string icon url or an empty string, if required attributes are missing or an invalid format was passed
*/
std::string get_icon_url(uint16_t size = 0, const image_type format = i_png) const;
};
/**
* @brief A group of applications.
*
* This is not currently ever sent by Discord API but the DPP standard setup for
* objects that can be received by REST has the possibility for this, so this exists.
* Don't ever expect to see one at present.
*/
typedef std::unordered_map<snowflake, application> application_map;
}