DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
FoundationEntities.cpp
Go to the documentation of this file.
1/*
2 DiscordCoreAPI, A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines.
3
4 Copyright 2021, 2022 Chris M. (RealTimeChris)
5
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
19 USA
20*/
21/// FoundationEntities.cpp - Source file for the foundation entities.
22/// Oct 1, 2021
23/// https://discordcoreapi.com
24/// \file FoundationEntities.cpp
25
39
40namespace DiscordCoreInternal {
41
42 WebSocketResumeData::operator Jsonifier::Serializer() {
43 Jsonifier::Serializer data{};
44 data["op"] = 6;
45 data["d"]["seq"] = this->lastNumberReceived;
46 data["d"]["session_id"] = this->sessionId;
47 data["d"]["token"] = this->botToken;
48 return data;
49 }
50
51 WebSocketIdentifyData::operator Jsonifier::Serializer() {
52 Jsonifier::Serializer serializer{};
53 serializer["d"]["intents"] = this->intents;
54 serializer["d"]["large_threshold"] = 250;
55 for (auto& value: this->presence.activities) {
56 Jsonifier::Serializer serializer01{};
57 if (value.url != "") {
58 serializer01["url"] = value.url;
59 }
60 serializer01["name"] = value.name;
61 serializer01["type"] = value.type;
62 serializer["d"]["presence"]["activities"].emplaceBack(serializer01);
63 }
64 serializer["d"]["presence"]["afk"] = this->presence.afk;
65 if (this->presence.since != 0) {
66 serializer["d"]["presence"]["since"] = this->presence.since;
67 }
68 switch (this->presence.status) {
70 serializer["d"]["presence"]["status"] = "online";
71 break;
72 }
74 serializer["d"]["presence"]["status"] = "dnd";
75 break;
76 }
78 serializer["d"]["presence"]["status"] = "invisible";
79 break;
80 }
82 serializer["d"]["presence"]["status"] = "offline";
83 break;
84 }
86 serializer["d"]["presence"]["status"] = "idle";
87 break;
88 }
89 }
90 serializer["d"]["properties"]["browser"] = "DiscordCoreAPI";
91 serializer["d"]["properties"]["device"] = "DiscordCoreAPI";
92#ifdef _WIN32
93 serializer["d"]["properties"]["os"] = "Windows";
94#elif __linux__
95 serializer["d"]["properties"]["os"] = "Linux";
96#endif
97 serializer["d"]["shard"].emplaceBack(this->currentShard);
98 serializer["d"]["shard"].emplaceBack(this->numberOfShards);
99 serializer["d"]["token"] = this->botToken;
100 serializer["op"] = 2;
101 return serializer;
102 }
103
104 VoiceSocketProtocolPayloadData::operator Jsonifier::Serializer() {
105 Jsonifier::Serializer data{};
106 data["op"] = 1;
107 data["d"]["protocol"] = "udp";
108 data["d"]["data"]["port"] = this->voicePort;
109 data["d"]["data"]["mode"] = this->voiceEncryptionMode;
110 std::string externalIpReal{};
111 for (auto& value: this->externalIp) {
112 externalIpReal.push_back(value);
113 }
114 data["d"]["data"]["address"] = externalIpReal;
115 return data;
116 }
117
118 VoiceIdentifyData::operator Jsonifier::Serializer() {
119 Jsonifier::Serializer data{};
120 data["op"] = 0;
121 data["d"]["session_id"] = this->connectionData.sessionId;
122 data["d"]["token"] = this->connectionData.token;
123 data["d"]["server_id"] = this->connectInitData.guildId;
124 data["d"]["user_id"] = this->connectInitData.userId;
125 return data;
126 }
127
128 SendSpeakingData::operator Jsonifier::Serializer() {
129 Jsonifier::Serializer data{};
130 data["op"] = 5;
131 data["d"]["speaking"] = static_cast<int32_t>(this->type);
132 data["d"]["delay"] = this->delay;
133 data["d"]["ssrc"] = this->ssrc;
134 return data;
135 }
136
137 HttpsWorkloadData& HttpsWorkloadData::operator=(HttpsWorkloadData&& other) noexcept {
138 if (this != &other) {
139 this->headersToInsert = std::move(other.headersToInsert);
140 this->thisWorkerId.store(this->thisWorkerId.load());
141 this->relativePath = std::move(other.relativePath);
142 this->callStack = std::move(other.callStack);
143 this->workloadClass = other.workloadClass;
144 this->baseUrl = std::move(other.baseUrl);
145 this->content = std::move(other.content);
146 this->workloadType = other.workloadType;
147 this->payloadType = other.payloadType;
148 }
149 return *this;
150 }
151
152 HttpsWorkloadData& HttpsWorkloadData::operator=(HttpsWorkloadType type) noexcept {
153 if (!HttpsWorkloadData::workloadIdsExternal.contains(type)) {
154 std::unique_ptr<std::atomic_int64_t> integer{ std::make_unique<std::atomic_int64_t>() };
155 std::unique_ptr<std::atomic_int64_t> integer02{ std::make_unique<std::atomic_int64_t>() };
156 HttpsWorkloadData::workloadIdsExternal[type] = std::move(integer);
157 HttpsWorkloadData::workloadIdsInternal[type] = std::move(integer02);
158 }
159 this->thisWorkerId.store(HttpsWorkloadData::incrementAndGetWorkloadId(type));
160 this->workloadType = type;
161 return *this;
162 }
163
164 HttpsWorkloadData::HttpsWorkloadData(HttpsWorkloadType type) noexcept {
165 *this = type;
166 }
167
168 int64_t HttpsWorkloadData::incrementAndGetWorkloadId(HttpsWorkloadType workloadType) noexcept {
169 int64_t value{ HttpsWorkloadData::workloadIdsExternal[workloadType]->load() };
170 HttpsWorkloadData::workloadIdsExternal[workloadType]->store(value + 1);
171 return value;
172 }
173
174 std::unordered_map<HttpsWorkloadType, std::unique_ptr<std::atomic_int64_t>> HttpsWorkloadData::workloadIdsExternal{};
175 std::unordered_map<HttpsWorkloadType, std::unique_ptr<std::atomic_int64_t>> HttpsWorkloadData::workloadIdsInternal{};
176
177 HelloData::HelloData(Jsonifier::Value jsonData) {
178 this->heartbeatInterval = DiscordCoreAPI::getUint64(jsonData, "heartbeat_interval");
179 }
180
181 WebSocketMessage::WebSocketMessage(Jsonifier::Value jsonData) {
182 this->op = DiscordCoreAPI::getInt32(jsonData, "op");
183
184 this->s = DiscordCoreAPI::getInt32(jsonData, "s");
185
186 this->t = DiscordCoreAPI::getString(jsonData, "t");
187 }
188
189 InvalidSessionData::InvalidSessionData(Jsonifier::Value jsonData) {
190 this->d = DiscordCoreAPI::getBool(jsonData, "d");
191 }
192
193 ReadyData::ReadyData(Jsonifier::Value jsonData) {
194 this->resumeGatewayUrl = DiscordCoreAPI::getString(jsonData, "resume_gateway_url");
195 this->resumeGatewayUrl = this->resumeGatewayUrl.substr(this->resumeGatewayUrl.find("wss://") + std::string{ "wss://" }.size());
196 this->resumeGatewayUrl = this->resumeGatewayUrl.substr(0, this->resumeGatewayUrl.find("/"));
197
198 this->sessionId = DiscordCoreAPI::getString(jsonData, "session_id");
199
200 this->v = DiscordCoreAPI::getUint32(jsonData, "v");
201
202 Jsonifier::Value user{};
203 if (jsonData["user"].get(user) == Jsonifier::ErrorCode::Success) {
204 this->user = DiscordCoreAPI::UserData{ user };
205 }
206 }
207}
208
209namespace DiscordCoreAPI {
210
211 UpdatePresenceData::operator Serializer() {
212 Serializer data{};
213 data["op"] = 3;
214 for (auto& value: this->activities) {
215 Serializer dataNew{};
216 if (value.url != "") {
217 dataNew["url"] = std::string{ value.url };
218 }
219 dataNew["name"] = std::string{ value.name };
220 dataNew["type"] = value.type;
221 data["d"]["activities"].emplaceBack(dataNew);
222 }
223 switch (this->status) {
225 data["status"] = "online";
226 break;
227 }
229 data["status"] = "dnd";
230 break;
231 }
233 data["status"] = "invisible";
234 break;
235 }
237 data["status"] = "offline";
238 break;
239 }
241 data["status"] = "idle";
242 break;
243 }
244 }
245 if (this->since != 0) {
246 data["since"] = this->since;
247 }
248 data["afk"] = this->afk;
249 return data;
250 }
251
253 TimeStamp timeStamp{ (this->id.operator size_t() >> 22) + 1420070400000, timeFormat };
254 return timeStamp.operator std::string();
255 }
256
257 RoleTagsData::RoleTagsData(Value jsonData) {
258 this->botId = getString(jsonData, "bot_id");
259
260 this->integrationId = getString(jsonData, "integration_id");
261 }
262
263 UserData::UserData(Value jsonData) {
264 this->id = getId(jsonData, "id");
265 if (this->id == 0) {
266 return;
267 }
268
269 int32_t newFlags{};
270 newFlags = setBool(newFlags, UserFlags::MFAEnabled, getBool(jsonData, "mfa_enabled"));
271
272 newFlags = setBool(newFlags, UserFlags::Verified, getBool(jsonData, "verified"));
273
274 newFlags = setBool(newFlags, UserFlags::System, getBool(jsonData, "system"));
275
276 newFlags = setBool(newFlags, UserFlags::Bot, getBool(jsonData, "bot"));
277
278 newFlags += getUint32(jsonData, "public_flags");
279
280 newFlags = setBool(newFlags, this->flags, true);
281
282 this->flags = static_cast<UserFlags>(newFlags);
283
284 this->userName = getString(jsonData, "username");
285
286 this->avatar = getString(jsonData, "avatar");
287
288 this->discriminator = getString(jsonData, "discriminator");
289 }
290
291 std::string UserData::getAvatarUrl() {
292 std::string stringNew{ "https://cdn.discordapp.com/" };
293 stringNew += "avatars/" + this->id + "/" + this->avatar.getIconHash();
294 return stringNew;
295 }
296
297 AttachmentData ::AttachmentData(Value jsonData) {
298 this->id = getId(jsonData, "id");
299
300 this->filename = getString(jsonData, "filename");
301
302 this->contentType = getString(jsonData, "content_type");
303
304 this->ephemeral = getBool(jsonData, "ephemeral");
305
306 this->description = getString(jsonData, "description");
307
308 this->size = getUint32(jsonData, "size");
309
310 this->url = getString(jsonData, "url");
311
312 this->proxyUrl = getString(jsonData, "proxy_url");
313
314 this->width = getUint32(jsonData, "width");
315
316 this->height = getUint32(jsonData, "height");
317 }
318
319 EmbedFooterData::EmbedFooterData(Value jsonData) {
320 this->text = getString(jsonData, "text");
321
322 this->iconUrl = getString(jsonData, "icon_url");
323
324 this->proxyIconUrl = getString(jsonData, "proxy_icon_url");
325 }
326
327 EmbedImageData::EmbedImageData(Value jsonData) {
328 this->url = getString(jsonData, "url");
329
330 this->proxyUrl = getString(jsonData, "proxy_url");
331
332 this->width = getUint32(jsonData, "width");
333
334 this->height = getUint32(jsonData, "height");
335 }
336
337 EmbedThumbnailData::EmbedThumbnailData(Value jsonData) {
338 this->url = getString(jsonData, "url");
339
340 this->proxyUrl = getString(jsonData, "proxy_url");
341
342 this->width = getUint32(jsonData, "width");
343
344 this->height = getUint32(jsonData, "height");
345 }
346
347 EmbedVideoData::EmbedVideoData(Value jsonData) {
348 this->url = getString(jsonData, "url");
349
350 this->proxyUrl = getString(jsonData, "proxy_url");
351
352 this->width = getUint32(jsonData, "width");
353
354 this->height = getUint32(jsonData, "height");
355 }
356
357 EmbedProviderData::EmbedProviderData(Value jsonData) {
358 this->url = getString(jsonData, "url");
359
360 this->name = getString(jsonData, "name");
361 }
362
363 EmbedAuthorData::EmbedAuthorData(Value jsonData) {
364 this->url = getString(jsonData, "url");
365
366 this->proxyIconUrl = getString(jsonData, "proxy_icon_url");
367
368 this->name = getString(jsonData, "name");
369
370 this->iconUrl = getString(jsonData, "icon_url");
371 }
372
373 EmbedFieldData::EmbedFieldData(Value jsonData) {
374 this->Inline = getBool(jsonData, "inline");
375
376 this->name = getString(jsonData, "name");
377
378 this->value = getString(jsonData, "value");
379 }
380
381 EmbedData::EmbedData(Value jsonData) {
382 this->title = getString(jsonData, "title");
383
384 this->type = getString(jsonData, "type");
385
386 this->description = getString(jsonData, "description");
387
388 this->url = getString(jsonData, "url");
389
390 this->timeStamp = getString(jsonData, "timestamp");
391
392 this->hexColorValue = getUint32(jsonData, "color");
393
394 Value object{};
395 if (!getObject(object, "footer", jsonData)) {
396 EmbedFooterData data{ object };
397 this->footer = std::move(data);
398 }
399
400 if (!getObject(object, "image", jsonData)) {
401 EmbedImageData data{ object };
402 this->image = std::move(data);
403 }
404
405 if (!getObject(object, "provider", jsonData)) {
406 EmbedProviderData data{ object };
407 this->provider = std::move(data);
408 }
409
410 if (!getObject(object, "thumbnail", jsonData)) {
411 EmbedThumbnailData data{ object };
412 this->thumbnail = std::move(data);
413 }
414
415 if (!getObject(object, "video", jsonData)) {
416 EmbedVideoData data{ object };
417 this->video = std::move(data);
418 }
419
420 if (!getObject(object, "author", jsonData)) {
421 EmbedAuthorData data{ object };
422 this->author = std::move(data);
423 }
424
425 Jsonifier::Array arrayValue{};
426 if (!getArray(arrayValue, "fields", jsonData)) {
427 this->fields.clear();
428 for (JsonifierResult<Value> value: arrayValue) {
429 EmbedFieldData newData{ value.value() };
430 this->fields.emplace_back(std::move(newData));
431 }
432 }
433 }
434
435 MessageReferenceData::MessageReferenceData(Value jsonData) {
436 this->messageId = getId(jsonData, "message_id");
437
438 this->channelId = getId(jsonData, "channel_id");
439
440 this->guildId = getId(jsonData, "guild_id");
441
442 this->failIfNotExists = getBool(jsonData, "fail_if_not_exists");
443 }
444
445 ThreadMetadataData::ThreadMetadataData(Value jsonData) {
446 this->archived = getBool(jsonData, "archived");
447
448 this->invitable = getBool(jsonData, "invitable");
449
450 this->autoArchiveDuration = getUint32(jsonData, "auto_archive_duration");
451
452 this->archiveTimestamp = getString(jsonData, "archive_timestamp");
453
454 this->locked = getBool(jsonData, "locked");
455 }
456
457 ThreadMemberData::ThreadMemberData(Value jsonData) {
458 this->id = getId(jsonData, "id");
459
460 this->userId = getId(jsonData, "user_id");
461
462 this->joinTimestamp = getString(jsonData, "join_timestamp");
463
464 this->flags = getUint32(jsonData, "flags");
465 }
466
467 ThreadMemberDataVector::ThreadMemberDataVector(Value jsonData) {
468 if (jsonData.type() != Jsonifier::JsonType::Null) {
469 Jsonifier::Array arrayValue{};
470 if (!getArray(arrayValue, jsonData)) {
471 for (JsonifierResult<Value> value: arrayValue) {
472 ThreadMemberData newData{ value.value() };
473 this->threadMembers.emplace_back(std::move(newData));
474 }
475 }
476 }
477 }
478
479 VoiceStateDataLight::VoiceStateDataLight(Value jsonData) {
480 this->channelId = getId(jsonData, "channel_id");
481
482 this->guildId = getId(jsonData, "guild_id");
483
484 this->userId = getId(jsonData, "user_id");
485 }
486
487 VoiceStateData::VoiceStateData(Value jsonData) {
488 this->requestToSpeakTimestamp = getString(jsonData, "request_to_speak_timestamp");
489
490 this->channelId = getId(jsonData, "channel_id");
491
492 this->guildId = getId(jsonData, "guild_id");
493
494 this->selfStream = getBool(jsonData, "self_stream");
495
496 this->userId = getId(jsonData, "user_id");
497
498 this->selfVideo = getBool(jsonData, "self_video");
499
500 this->sessionId = getString(jsonData, "session_id");
501
502 this->selfDeaf = getBool(jsonData, "self_deaf");
503
504 this->selfMute = getBool(jsonData, "self_mute");
505
506 this->suppress = getBool(jsonData, "suppress");
507
508 this->deaf = getBool(jsonData, "deaf");
509
510 this->mute = getBool(jsonData, "mute");
511 }
512
513 RoleData::RoleData(Value jsonData) {
514 this->id = getId(jsonData, "id");
515
516 this->name = getString(jsonData, "name");
517
518 std::stringstream stream{};
519 stream << getString(jsonData, "unicode_emoji");
520 for (auto& value: stream.str()) {
521 this->unicodeEmoji.emplace_back(value);
522 }
523 if (this->unicodeEmoji.size() > 3) {
524 this->unicodeEmoji = static_cast<std::string>(this->unicodeEmoji).substr(1, this->unicodeEmoji.size() - 3);
525 }
526
527 this->guildId = getId(jsonData, "guild_id");
528
529 this->color = getUint32(jsonData, "color");
530
531 uint8_t newFlags{};
532 newFlags = setBool(newFlags, RoleFlags::Hoist, getBool(jsonData, "hoist"));
533
534 newFlags = setBool(newFlags, RoleFlags::Managed, getBool(jsonData, "managed"));
535
536 newFlags = setBool(newFlags, RoleFlags::Mentionable, getBool(jsonData, "mentionable"));
537
538 this->flags = static_cast<RoleFlags>(newFlags);
539
540 this->position = getUint32(jsonData, "position");
541
542 this->permissions = getString(jsonData, "permissions");
543 }
544
545 EmojiData::EmojiData(Value jsonData) {
546 this->id = getId(jsonData, "id");
547
548 this->name = getString(jsonData, "name");
549
550 Jsonifier::Array arrayValue{};
551 if (!getArray(arrayValue, "roles", jsonData)) {
552 for (JsonifierResult<Value> value: arrayValue) {
553 RoleData newData{ value.value() };
554 this->roles.emplace_back(std::move(newData));
555 }
556 }
557
558 Value object{};
559 if (!getObject(object, "user", jsonData)) {
560 this->user = UserData{ object };
561 }
562
563 this->requireColons = getBool(jsonData, "require_colons");
564
565 this->managed = getBool(jsonData, "managed");
566
567 this->animated = getBool(jsonData, "animated");
568
569 this->available = getBool(jsonData, "available");
570 }
571
572 PresenceUpdateData::PresenceUpdateData(Value jsonData) {
573 this->guildId = getId(jsonData, "guild_id");
574
575 auto stringNew = getString(jsonData, "status");
576
577 if (stringNew == "online") {
578 uint8_t newFlags = setBool(uint8_t{}, PresenceUpdateFlags::Status_Online, true);
579 this->theStatus = static_cast<PresenceUpdateFlags>(newFlags);
580 } else if (stringNew == "idle") {
581 uint8_t newFlags = setBool(uint8_t{}, PresenceUpdateFlags::Status_Idle, true);
582 this->theStatus = static_cast<PresenceUpdateFlags>(newFlags);
583 } else if (stringNew == "dnd") {
584 uint8_t newFlags = setBool(uint8_t{}, PresenceUpdateFlags::Status_Dnd, true);
585 this->theStatus = static_cast<PresenceUpdateFlags>(newFlags);
586 }
587
588 parseObject(jsonData, this->theStatus);
589 }
590
591 GuildMemberData& GuildMemberData::operator=(GuildMemberData&& other) noexcept {
592 if (this != &other) {
593 this->permissions = std::move(other.permissions);
594 this->joinedAt = std::move(other.joinedAt);
595 this->avatar = std::move(other.avatar);
596 this->roles = std::move(other.roles);
597 this->flags = std::move(other.flags);
598 this->nick = std::move(other.nick);
599 this->guildId = other.guildId;
600 this->id = other.id;
601 }
602 return *this;
603 }
604
605 GuildMemberData& GuildMemberData::operator=(Value jsonData) {
606 uint8_t newFlags{};
607 newFlags = setBool(newFlags, GuildMemberFlags::Pending, getBool(jsonData, "pending"));
608
609 newFlags = setBool(newFlags, GuildMemberFlags::Mute, getBool(jsonData, "mute"));
610
611 newFlags = setBool(newFlags, GuildMemberFlags::Deaf, getBool(jsonData, "deaf"));
612
613 this->flags = static_cast<GuildMemberFlags>(newFlags);
614
615 this->joinedAt = getString(jsonData, "joined_at");
616
617 this->guildId = getId(jsonData, "guild_id");
618
619 Jsonifier::Array arrayValue{};
620 if (!getArray(arrayValue, "roles", jsonData)) {
621 this->roles.clear();
622 for (JsonifierResult<Value> value: arrayValue) {
623 this->roles.emplace_back(getId(value.value()));
624 }
625 }
626
627 this->permissions = getString(jsonData, "permissions");
628
629 Value object{};
630 if (!getObject(object, "user", jsonData)) {
631 UserData user{ object };
632 this->id = user.id;
633 Users::insertUser(std::move(user));
634 }
635
636 this->avatar = getString(jsonData, "avatar");
637
638 newFlags += getUint8(jsonData, "flags");
639
640 this->flags = static_cast<GuildMemberFlags>(newFlags);
641
642 this->nick = getString(jsonData, "nick");
643 return *this;
644 }
645
646 GuildMemberData::GuildMemberData(Value jsonData) {
647 *this = jsonData;
648 }
649
650 VoiceStateDataLight GuildMemberData::getVoiceStateData() {
651 VoiceStateDataLight dataToGet{};
652 dataToGet.guildId = this->guildId;
653 dataToGet.userId = this->id;
654 if (GuildMembers::getVsCache().contains(dataToGet)) {
655 return GuildMembers::getVsCache()[dataToGet];
656 } else {
657 return dataToGet;
658 }
659 }
660
661 std::string GuildMemberData::getAvatarUrl() {
662 if (this->avatar.getIconHash() != "") {
663 std::string stringNew{ "https://cdn.discordapp.com/" };
664 stringNew += "guilds/" + this->guildId + "/users/" + this->id + "/avatars/" + this->avatar.getIconHash();
665 return stringNew;
666 } else {
667 return this->getUserData().getAvatarUrl();
668 }
669 }
670
671 UserData GuildMemberData::getUserData() {
672 if (this->id.operator size_t() != 0) {
673 return Users::getCachedUser({ .userId = this->id });
674 } else {
675 return {};
676 }
677 }
678
679 OverWriteData::OverWriteData(Value jsonData) {
680 this->id = getId(jsonData, "id");
681
682 this->allow = getUint64(jsonData, "allow");
683
684 this->deny = getUint64(jsonData, "deny");
685
686 this->type = static_cast<PermissionOverwritesType>(getUint8(jsonData, "type"));
687 }
688
689 DefaultReactionData::DefaultReactionData(Value jsonData) {
690 this->emojiId = getId(jsonData, "emoji_id");
691
692 this->emojiName = getString(jsonData, "emoji_name");
693 }
694
695 ForumTagData::ForumTagData(Value jsonData) {
696 this->emojiId = getId(jsonData, "emoji_id");
697
698 this->emojiName = getString(jsonData, "emoji_name");
699
700 this->id = getId(jsonData, "id");
701
702 this->moderated = getBool(jsonData, "moderated");
703
704 this->name = getString(jsonData, "name");
705 }
706
707 ChannelData::ChannelData(Value jsonData) {
708 uint8_t newFlags{};
709 newFlags = setBool(newFlags, ChannelFlags::NSFW, getBool(jsonData, "nsfw"));
710
711 this->type = static_cast<ChannelType>(getUint8(jsonData, "type"));
712
713 this->defaultSortOrder = static_cast<SortOrderTypes>(getUint8(jsonData, "default_sort_order"));
714
715 this->memberCount = getUint32(jsonData, "member_count");
716
717 this->ownerId = getId(jsonData, "owner_id");
718
719 this->id = getId(jsonData, "id");
720
721 newFlags += getUint8(jsonData, "flags");
722
723 this->flags = static_cast<ChannelFlags>(newFlags);
724
725 this->parentId = getId(jsonData, "parent_id");
726
727 this->guildId = getId(jsonData, "guild_id");
728
729 this->position = getUint32(jsonData, "position");
730
731 Jsonifier::Array arrayValue{};
732 if (!getArray(arrayValue, "permission_overwrites", jsonData)) {
733 this->permissionOverwrites.clear();
734 for (JsonifierResult<Value> value: arrayValue) {
735 OverWriteData dataNew{ value.value() };
736 this->permissionOverwrites.emplace_back(std::move(dataNew));
737 }
738 }
739
740 this->name = getString(jsonData, "name");
741 }
742
743 ActiveThreadsData::ActiveThreadsData(Value jsonData) {
744 Jsonifier::Array arrayValue{};
745 if (!getArray(arrayValue, "threads", jsonData)) {
746 for (JsonifierResult<Value> value: arrayValue) {
747 ChannelData newData{ value.value() };
748 this->threads.emplace_back(std::move(newData));
749 }
750 }
751
752 if (!getArray(arrayValue, "members", jsonData)) {
753 for (JsonifierResult<Value> value: arrayValue) {
754 ThreadMemberData newData{ value.value() };
755 this->members.emplace_back(std::move(newData));
756 }
757 }
758
759 this->hasMore = getBool(jsonData, "has_more");
760 }
761
762 ArchivedThreadsData::ArchivedThreadsData(Value jsonData) {
763 Jsonifier::Array arrayValue{};
764
765 if (!getArray(arrayValue, "threads", jsonData)) {
766 for (JsonifierResult<Value> value: arrayValue) {
767 ChannelData newData{ value.value() };
768 this->threads.emplace_back(std::move(newData));
769 }
770 }
771
772 ;
773 if (!getArray(arrayValue, "members", jsonData)) {
774 for (JsonifierResult<Value> value: arrayValue) {
775 ThreadMemberData newData{ value.value() };
776 this->members.emplace_back(std::move(newData));
777 }
778 }
779
780 this->hasMore = getBool(jsonData, "has_more");
781 }
782
783 TriggerMetaData::TriggerMetaData(Value jsonData) {
784 Jsonifier::Array arrayValue{};
785
786 if (!getArray(arrayValue, "keyword_filter", jsonData)) {
787 for (JsonifierResult<Value> value: arrayValue) {
788 this->keywordFilter.emplace_back(value.getString().value().data());
789 }
790 }
791
792 if (!getArray(arrayValue, "presets", jsonData)) {
793 for (JsonifierResult<Value> value: arrayValue) {
794 this->presets.emplace_back(static_cast<KeywordPresetType>(value.getUint64().value()));
795 }
796 }
797
798 if (!getArray(arrayValue, "allow_list", jsonData)) {
799 for (JsonifierResult<Value> value: arrayValue) {
800 this->allowList.emplace_back(value.getString().value());
801 }
802 }
803
804 this->mentionTotalLimit = getUint32(jsonData, "mention_total_limit");
805 }
806
807 ActionMetaData::ActionMetaData(Value jsonData) {
808 this->channelId = getId(jsonData, "channel_id");
809
810 this->durationSeconds = getUint64(jsonData, "duration_seconds");
811 }
812
813 ActionData::ActionData(Value jsonData) {
814 Value object{};
815 if (!getObject(object, "metadata", jsonData)) {
816 this->metadata = ActionMetaData{ object };
817 }
818
819 this->type = static_cast<ActionType>(getUint64(jsonData, "type"));
820 }
821
822 AutoModerationRuleData::AutoModerationRuleData(Value jsonData) {
823 this->name = getString(jsonData, "name");
824
825 this->id = getId(jsonData, "id");
826
827 this->enabled = getBool(jsonData, "enabled");
828
829 this->triggerType = static_cast<TriggerType>(getUint8(jsonData, "trigger_type"));
830
831 this->eventType = static_cast<EventType>(getUint8(jsonData, "event_type"));
832
833 this->creatorId = getId(jsonData, "creator_id");
834
835 Jsonifier::Array arrayValue{};
836 if (!getArray(arrayValue, "actions", jsonData)) {
837 for (JsonifierResult<Value> value: arrayValue) {
838 ActionData newData{ value.value() };
839 this->actions.emplace_back(std::move(newData));
840 }
841 }
842
843 if (!getArray(arrayValue, "exempt_roles", jsonData)) {
844 this->exemptRoles.clear();
845 for (JsonifierResult<Value> value: arrayValue) {
846 this->exemptRoles.emplace_back(strtoull(std::string{ value.getString().takeValue() }));
847 }
848 }
849
850 if (!getArray(arrayValue, "exempt_channels", jsonData)) {
851 this->exemptChannels.clear();
852 for (JsonifierResult<Value> value: arrayValue) {
853 this->exemptChannels.emplace_back(strtoull(std::string{ value.getString().takeValue() }));
854 }
855 }
856
857 Value object{};
858 if (!getObject(object, "trigger_metadata", jsonData)) {
859 this->triggerMetaData = TriggerMetaData{ object };
860 }
861
862 this->guildId = getId(jsonData, "guild_id");
863 }
864
865 ApplicationCommandPermissionData::ApplicationCommandPermissionData(Value jsonData) {
866 this->id = getId(jsonData, "id");
867
868 this->permission = getBool(jsonData, "permission");
869
870 this->type = static_cast<ApplicationCommandPermissionType>(getUint8(jsonData, "type"));
871 }
872
873 GuildApplicationCommandPermissionsData::GuildApplicationCommandPermissionsData(Value jsonData) {
874 this->guildId = getId(jsonData, "guild_id");
875
876 this->applicationId = getId(jsonData, "application_id");
877
878 this->id = getId(jsonData, "id");
879
880 Jsonifier::Array arrayValue{};
881 if (!getArray(arrayValue, "permissions", jsonData)) {
882 this->permissions.clear();
883 for (JsonifierResult<Value> value: arrayValue) {
884 ApplicationCommandPermissionData newData{ value.value() };
885 this->permissions.emplace_back(std::move(newData));
886 }
887 }
888 }
889
890 GuildApplicationCommandPermissionsDataVector::GuildApplicationCommandPermissionsDataVector(Value jsonData) {
891 if (jsonData.type() != Jsonifier::JsonType::Null) {
892 Jsonifier::Array arrayValue{};
893 if (!getArray(arrayValue, jsonData)) {
894 for (JsonifierResult<Value> value: arrayValue) {
895 GuildApplicationCommandPermissionsData newData{ value.value() };
896 this->guildApplicationCommandPermissionss.emplace_back(std::move(newData));
897 }
898 }
899 }
900 }
901
902 EmojiDataVector::EmojiDataVector(Value jsonData) {
903 if (jsonData.type() != Jsonifier::JsonType::Null) {
904 Jsonifier::Array arrayValue{};
905 if (!getArray(arrayValue, jsonData)) {
906 for (JsonifierResult<Value> value: arrayValue) {
907 EmojiData newData{ value.value() };
908 this->theEmojis.emplace_back(std::move(newData));
909 }
910 }
911 }
912 }
913
914 ReactionData::ReactionData(Value jsonData) {
915 this->count = getUint32(jsonData, "count");
916
917 this->me = getBool(jsonData, "me");
918
919 Value object{};
920 if (!getObject(object, "emoji", jsonData)) {
921 this->emoji = EmojiData{ object };
922 }
923
924 this->guildId = getId(jsonData, "guild_id");
925
926 this->channelId = getId(jsonData, "channel_id");
927
928 this->userId = getId(jsonData, "user_id");
929
930 this->messageId = getId(jsonData, "message_id");
931
932 if (!getObject(object, "member", jsonData)) {
933 this->member = GuildMemberData{ object };
934 }
935 }
936
937 VoiceRegionData::VoiceRegionData(Value jsonData) {
938 this->id = getId(jsonData, "id");
939
940 this->custom = getBool(jsonData, "custom");
941
942 this->deprecated = getBool(jsonData, "deprecated");
943
944 this->optimal = getBool(jsonData, "optimal");
945
946 this->name = getString(jsonData, "name");
947 }
948
949 VoiceRegionDataVector::VoiceRegionDataVector(Value jsonData) {
950 if (jsonData.type() != Jsonifier::JsonType::Null) {
951 Jsonifier::Array arrayValue{};
952 if (!getArray(arrayValue, jsonData)) {
953 for (JsonifierResult<Value> value: arrayValue) {
954 VoiceRegionData newData{ value.value() };
955 this->voiceRegions.emplace_back(std::move(newData));
956 }
957 }
958 }
959 }
960
961 MessageActivityData::MessageActivityData(Value jsonData) {
962 this->type = static_cast<MessageActivityType>(getUint8(jsonData, "type"));
963
964 this->partyId = getString(jsonData, "party_id");
965 }
966
967 BanData::BanData(Value jsonData) {
968 Value object{};
969 if (!getObject(object, "user", jsonData)) {
970 this->user = UserData{ object };
971 }
972
973 this->reason = getString(jsonData, "reason");
974 }
975
976 BanDataVector::BanDataVector(Value jsonData) {
977 if (jsonData.type() != Jsonifier::JsonType::Null) {
978 Jsonifier::Array arrayValue{};
979 if (!getArray(arrayValue, jsonData)) {
980 for (JsonifierResult<Value> value: arrayValue) {
981 BanData newData{ value.value() };
982 this->bans.emplace_back(std::move(newData));
983 }
984 }
985 }
986 }
987
988 TeamMembersObjectData::TeamMembersObjectData(Value jsonData) {
989 this->membershipState = getUint32(jsonData, "membership_state");
990
991 this->teamId = getId(jsonData, "team_id");
992
993 Jsonifier::Array arrayValue{};
994 if (!getArray(arrayValue, "permissions", jsonData)) {
995 for (JsonifierResult<Value> value: arrayValue) {
996 this->permissions.emplace_back(Permissions{ value.getString().value().data() });
997 }
998 }
999
1000 Value object{};
1001 if (!getObject(object, "user", jsonData)) {
1002 this->user = UserData{ object };
1003 }
1004 }
1005
1006 TeamObjectData::TeamObjectData(Value jsonData) {
1007 this->icon = getString(jsonData, "icon");
1008
1009 this->id = getId(jsonData, "id");
1010
1011 Jsonifier::Array arrayValue{};
1012 if (!getArray(arrayValue, "members", jsonData)) {
1013 for (JsonifierResult<Value> value: arrayValue) {
1014 TeamMembersObjectData newData{ value.value() };
1015 this->members.emplace_back(std::move(newData));
1016 }
1017 }
1018
1019 this->ownerUserId = getId(jsonData, "owner_user_id");
1020 }
1021
1022 InstallParamsData::InstallParamsData(Value jsonData) {
1023 Jsonifier::Array arrayValue{};
1024 if (!getArray(arrayValue, "scopes", jsonData)) {
1025 for (JsonifierResult<Value> value: arrayValue) {
1026 this->scopes.emplace_back(Permissions{ value.getString().value().data() });
1027 }
1028 }
1029
1030 this->permissions = getString(jsonData, "name");
1031 }
1032
1033 ApplicationData::ApplicationData(Value jsonData) {
1034 Value object{};
1035 if (!getObject(object, "params", jsonData)) {
1036 this->params = InstallParamsData{ object };
1037 }
1038
1039 Jsonifier::Array arrayValue{};
1040 if (!getArray(arrayValue, "tags", jsonData)) {
1041 for (JsonifierResult<Value> value: arrayValue) {
1042 this->tags.emplace_back(value.getString().value().data());
1043 }
1044 }
1045
1046 this->id = getId(jsonData, "id");
1047
1048 this->name = getString(jsonData, "name");
1049
1050 this->icon = getString(jsonData, "icon");
1051
1052 this->description = getString(jsonData, "description");
1053
1054 if (!getArray(arrayValue, "rpc_origins", jsonData)) {
1055 for (JsonifierResult<Value> value: arrayValue) {
1056 this->rpcOrigins.emplace_back(value.getString().value().data());
1057 }
1058 }
1059
1060 this->botPublic = getBool(jsonData, "bot_public");
1061
1062 this->botRequireCodeGrant = getBool(jsonData, "bot_require_code_grant");
1063
1064 this->termsOfServiceUrl = getString(jsonData, "terms_of_service_url");
1065
1066 this->privacyPolicyUrl = getString(jsonData, "privacy_policy_url");
1067
1068 if (!getObject(object, "owner", jsonData)) {
1069 this->owner = UserData{ object };
1070 }
1071
1072 if (!getObject(object, "team", jsonData)) {
1073 this->team = TeamObjectData{ object };
1074 }
1075
1076 this->summary = getString(jsonData, "summary");
1077
1078 this->verifyKey = getString(jsonData, "verify_key");
1079
1080 this->guildId = getId(jsonData, "guild_id");
1081
1082 this->primarySkuId = getString(jsonData, "primary_sku_id");
1083
1084 this->slug = getString(jsonData, "slug");
1085
1086 this->coverImage = getString(jsonData, "cover_image");
1087
1088 this->flags = static_cast<ApplicationFlags>(getUint8(jsonData, "flags"));
1089 }
1090
1092 Value object{};
1093 if (!getObject(object, "application", jsonData)) {
1094 this->application = ApplicationData{ object };
1095 }
1096
1097 Jsonifier::Array arrayValue{};
1098 if (!getArray(arrayValue, "features", jsonData)) {
1099 this->scopes.clear();
1100 for (JsonifierResult<Value> value: arrayValue) {
1101 this->scopes.emplace_back(std::string{ value.getString().takeValue() });
1102 }
1103 }
1104
1105 this->expires = getString(jsonData, "expires");
1106 if (!getObject(object, "user", jsonData)) {
1107 this->user = UserData{ object };
1108 }
1109 }
1110
1111 AccountData::AccountData(Value jsonData) {
1112 this->id = getId(jsonData, "id");
1113
1114 this->name = getString(jsonData, "name");
1115 }
1116
1117 GuildWidgetData::GuildWidgetData(Value jsonData) {
1118 this->enabled = getBool(jsonData, "enabled");
1119
1120 this->channelId = getId(jsonData, "channel_id");
1121 };
1122
1123 GuildWidgetImageData::GuildWidgetImageData(Value jsonData) {
1124 this->url = getString(jsonData, "widget_image");
1125 }
1126
1127 IntegrationData::IntegrationData(Value jsonData) {
1128 this->id = getId(jsonData, "id");
1129
1130 this->name = getString(jsonData, "name");
1131
1132 this->type = getString(jsonData, "type");
1133
1134 this->enabled = getBool(jsonData, "enabled");
1135
1136 this->syncing = getBool(jsonData, "syncing");
1137
1138 this->roleId = getId(jsonData, "role_id");
1139
1140 this->enableEmoticons = getBool(jsonData, "enable_emoticons");
1141
1142 this->expireBehavior = getUint32(jsonData, "expire_behavior");
1143
1144 this->expireGracePeriod = getUint32(jsonData, "expire_grace_period");
1145
1146 Value object{};
1147 if (!getObject(object, "user", jsonData)) {
1148 this->user = UserData{ object };
1149 }
1150
1151 if (!getObject(object, "account", jsonData)) {
1152 this->account = AccountData{ object };
1153 }
1154
1155 if (!getObject(object, "application", jsonData)) {
1156 this->application = ApplicationData{ object };
1157 }
1158
1159 this->syncedAt = getString(jsonData, "synced_at");
1160
1161 this->subscriberCount = getUint32(jsonData, "subscriber_count");
1162
1163 this->revoked = getBool(jsonData, "revoked");
1164 }
1165
1166 IntegrationDataVector::IntegrationDataVector(Value jsonData) {
1167 if (jsonData.type() != Jsonifier::JsonType::Null) {
1168 Jsonifier::Array arrayValue{};
1169 if (!getArray(arrayValue, jsonData)) {
1170 for (JsonifierResult<Value> value: arrayValue) {
1171 IntegrationData newData{ value.value() };
1172 this->integeregrations.emplace_back(std::move(newData));
1173 }
1174 }
1175 }
1176 }
1177
1178 OptionalAuditEntryInfoData::OptionalAuditEntryInfoData(Value jsonData) {
1179 this->deleteMemberDays = getString(jsonData, "delete_member_days");
1180
1181 this->membersRemoved = getString(jsonData, "members_removed");
1182
1183 this->channelId = getId(jsonData, "channel_id");
1184
1185 this->messageId = getId(jsonData, "message_id");
1186
1187 this->count = getString(jsonData, "count");
1188
1189 this->id = getId(jsonData, "id");
1190
1191 this->type = getString(jsonData, "type");
1192
1193 this->roleName = getString(jsonData, "role_name");
1194 }
1195
1196 AuditLogChangeData::AuditLogChangeData(Value jsonData) {
1197 this->newValue.value = getString(jsonData, "new_value");
1198
1199 this->oldValue.value = getString(jsonData, "old_value");
1200
1201 this->key = getString(jsonData, "key");
1202 }
1203
1204 GuildPruneCountData::GuildPruneCountData(Value jsonData) {
1205 this->count = getUint32(jsonData, "pruned");
1206 }
1207
1208 AuditLogEntryData::AuditLogEntryData(Value jsonData) {
1209 this->targetId = getId(jsonData, "target_id");
1210
1211 Jsonifier::Array arrayValue{};
1212 if (!getArray(arrayValue, "changes", jsonData)) {
1213 for (JsonifierResult<Value> value: arrayValue) {
1214 AuditLogChangeData newData{ value.value() };
1215 this->changes.emplace_back(std::move(newData));
1216 }
1217 }
1218
1219 this->userId = getId(jsonData, "user_id");
1220
1221 this->id = getId(jsonData, "id");
1223
1224 this->actionType = static_cast<AuditLogEvent>(getUint16(jsonData, "action_type"));
1225
1226 Value object{};
1227 if (!getObject(object, "options", jsonData)) {
1228 this->options = OptionalAuditEntryInfoData{ object };
1229 }
1230
1231 this->reason = getString(jsonData, "reason");
1232 }
1233
1234 WelcomeScreenChannelData::WelcomeScreenChannelData(Value jsonData) {
1235 this->channelId = getId(jsonData, "channel_id");
1236
1237 this->description = getString(jsonData, "description");
1238
1239 this->emojiId = getId(jsonData, "emoji_id");
1240
1241 this->emojiName = getString(jsonData, "emoji_name");
1242 }
1243
1244 WelcomeScreenData::WelcomeScreenData(Value jsonData) {
1245 this->description = getString(jsonData, "description");
1246
1247 Jsonifier::Array arrayValue{};
1248 if (!getArray(arrayValue, "welcome_channels", jsonData)) {
1249 for (JsonifierResult<Value> value: arrayValue) {
1250 WelcomeScreenChannelData newData{ value.value() };
1251 this->welcomeChannels.emplace_back(std::move(newData));
1252 }
1253 }
1254 }
1255
1256 StageInstanceData::StageInstanceData(Value jsonData) {
1257 this->id = getId(jsonData, "id");
1258
1259 this->guildId = getId(jsonData, "guild_id");
1260
1261 this->channelId = getId(jsonData, "channel_id");
1262
1263 this->topic = getString(jsonData, "topic");
1264
1265 this->privacyLevel = static_cast<StageInstancePrivacyLevel>(getUint8(jsonData, "privacy_level"));
1266
1267 this->discoverableDisabled = getBool(jsonData, "discoverable_disabled");
1268 }
1269
1270 StickerData::StickerData(Value jsonData) {
1271 this->asset = getString(jsonData, "asset");
1272
1273 this->description = getString(jsonData, "description");
1274
1275 this->formatType = static_cast<StickerFormatType>(getUint8(jsonData, "format_type"));
1276
1277 uint8_t newFlags{};
1278 newFlags = setBool(newFlags, StickerFlags::Available, getBool(jsonData, "available"));
1279
1280 this->flags = static_cast<StickerFlags>(newFlags);
1281
1282 this->guildId = getId(jsonData, "guild_id");
1283
1284 this->id = getId(jsonData, "id");
1285
1286 this->packId = getString(jsonData, "pack_id");
1287
1288 this->type = static_cast<StickerType>(getUint8(jsonData, "type"));
1289
1290 this->sortValue = getUint32(jsonData, "sort_value");
1291
1292 this->name = getString(jsonData, "name");
1293
1294 Value object{};
1295 if (!getObject(object, "user", jsonData)) {
1296 this->user = UserData{ object };
1297 }
1298 }
1299
1300 GuildPreviewData::GuildPreviewData(Value jsonData) {
1301 this->approximatePresenceCount = getUint32(jsonData, "approximate_presence_count");
1302
1303 this->approximateMemberCount = getUint32(jsonData, "approximate_member_count");
1304
1305 this->discoverySplash = getString(jsonData, "discovery_splash");
1306
1307 Jsonifier::Array arrayValue{};
1308 if (!getArray(arrayValue, "emojis", jsonData)) {
1309 for (JsonifierResult<Value> value: arrayValue) {
1310 EmojiData newData{ value.value() };
1311 this->emojis.emplace_back(std::move(newData));
1312 }
1313 }
1314
1315 if (!getArray(arrayValue, "stickers", jsonData)) {
1316 for (JsonifierResult<Value> value: arrayValue) {
1317 StickerData newData{ value.value() };
1318 this->stickers.emplace_back(std::move(newData));
1319 }
1320 }
1321
1322 if (!getArray(arrayValue, "features", jsonData)) {
1323 this->features.clear();
1324 for (JsonifierResult<Value> value: arrayValue) {
1325 this->features.emplace_back(value.getString().takeValue());
1326 }
1327 }
1328
1329 this->description = getString(jsonData, "description");
1330
1331 this->splash = getString(jsonData, "splash");
1332
1333 this->icon = getString(jsonData, "icon");
1334
1335 this->name = getString(jsonData, "name");
1336
1337 this->id = getId(jsonData, "id");
1338 }
1339
1340 VoiceConnection* GuildData::connectToVoice(const Snowflake guildMemberId, const Snowflake channelId, bool selfDeaf, bool selfMute,
1341 StreamInfo streamInfoNew) {
1342 if (DiscordCoreClient::getVoiceConnection(this->id) && DiscordCoreClient::getVoiceConnection(this->id)->areWeConnected()) {
1343 this->voiceConnectionPtr = DiscordCoreClient::getVoiceConnection(this->id);
1344 return this->voiceConnectionPtr;
1345 } else if (static_cast<Snowflake>(guildMemberId) != 0 || static_cast<Snowflake>(channelId) != 0) {
1346 Snowflake channelId{};
1347 if (static_cast<Snowflake>(guildMemberId) != 0) {
1348 VoiceStateDataLight dataLight{};
1349 dataLight.guildId = this->id;
1350 dataLight.userId = guildMemberId;
1351 auto voiceStateData = GuildMembers::getVsCache()[dataLight];
1352 if (voiceStateData.channelId != 0) {
1353 channelId = voiceStateData.channelId;
1354 }
1355 } else {
1356 channelId = channelId;
1357 }
1358 uint64_t theShardId{ (this->id.operator size_t() >> 22) % this->discordCoreClient->configManager.getTotalShardCount() };
1359 auto theBaseSocketAgentIndex{ static_cast<int32_t>(
1360 floor(static_cast<double>(theShardId) / static_cast<double>(this->discordCoreClient->configManager.getTotalShardCount()) *
1361 this->discordCoreClient->baseSocketAgentsMap.size())) };
1362 VoiceConnectInitData voiceConnectInitData{};
1363 voiceConnectInitData.currentShard = theShardId;
1364 voiceConnectInitData.streamInfo = streamInfoNew;
1365 voiceConnectInitData.channelId = channelId;
1366 voiceConnectInitData.guildId = this->id;
1367 voiceConnectInitData.userId = this->discordCoreClient->getBotUser().id;
1368 voiceConnectInitData.selfDeaf = selfDeaf;
1369 voiceConnectInitData.selfMute = selfMute;
1370 StopWatch stopWatch{ 10000ms };
1371 auto voiceConnection = DiscordCoreClient::getVoiceConnection(this->id);
1372 voiceConnection->connect(voiceConnectInitData);
1373 while (voiceConnection->areWeConnected()) {
1374 std::this_thread::sleep_for(1ms);
1375 }
1376 this->voiceConnectionPtr = voiceConnection;
1377 return this->voiceConnectionPtr;
1378 } else {
1379 return nullptr;
1380 }
1381 }
1382
1383 std::string GuildData::getIconUrl() noexcept {
1384 std::string stringNew{ "https://cdn.discordapp.com/" };
1385 stringNew += "icons/" + this->id + "/" + this->icon.getIconHash() + ".png";
1386 return stringNew;
1387 }
1388
1389 bool GuildData::areWeConnected() {
1390 return DiscordCoreClient::getVoiceConnection(this->id)->areWeConnected();
1391 }
1392
1393 void GuildData::disconnect() {
1394 if (DiscordCoreClient::getVoiceConnection(this->id)) {
1395 UpdateVoiceStateData updateVoiceData{};
1396 updateVoiceData.channelId = 0;
1397 updateVoiceData.selfDeaf = false;
1398 updateVoiceData.selfMute = false;
1399 updateVoiceData.guildId = this->id;
1400 this->discordCoreClient->getBotUser().updateVoiceStatus(updateVoiceData);
1401 DiscordCoreClient::getVoiceConnection(this->id)->disconnect();
1402 this->voiceConnectionPtr = nullptr;
1403 }
1404 }
1405
1406 GuildData::GuildData(Value jsonData) {
1407 uint8_t newFlags{};
1408 newFlags = setBool(newFlags, GuildFlags::WidgetEnabled, getBool(jsonData, "widget_enabled"));
1409
1410 newFlags = setBool(newFlags, GuildFlags::Unavailable, getBool(jsonData, "unavailable"));
1411
1412 newFlags = setBool(newFlags, GuildFlags::Owner, getBool(jsonData, "owner"));
1413
1414 newFlags = setBool(newFlags, GuildFlags::Large, getUint8(jsonData, "large"));
1415
1416 this->flags = static_cast<GuildFlags>(newFlags);
1417
1418 this->ownerId = getId(jsonData, "owner_id");
1419
1420 this->memberCount = getUint32(jsonData, "member_count");
1421
1422 this->joinedAt = getString(jsonData, "joined_at");
1423
1424 this->id = getId(jsonData, "id");
1425
1426 this->icon = getString(jsonData, "icon");
1427
1428 this->name = getString(jsonData, "name");
1429
1430 this->threads.clear();
1431
1432 Jsonifier::Array arrayValue{};
1433 if (!getArray(arrayValue, "features", jsonData)) {
1434 this->threads.clear();
1435 for (auto value: arrayValue) {
1436 auto object = value.value();
1437 this->threads.emplace_back(getId(object, "id"));
1438 }
1439 }
1440
1441 if (!getArray(arrayValue, "stickers", jsonData)) {
1442 this->stickers.clear();
1443 for (auto value: arrayValue) {
1444 this->stickers.emplace_back(getId(value.value(), "id"));
1445 }
1446 }
1447
1448 if (!getArray(arrayValue, "guild_scheduled_events", jsonData)) {
1449 this->guildScheduledEvents.clear();
1450 for (auto value: arrayValue) {
1451 this->guildScheduledEvents.emplace_back(getId(value.value(), "id"));
1452 }
1453 }
1454
1455 if (!getArray(arrayValue, "stage_instances", jsonData)) {
1456 this->stageInstances.clear();
1457 for (auto value: arrayValue) {
1458 this->stageInstances.emplace_back(getId(value.value(), "id"));
1459 }
1460 }
1461
1462 if (!getArray(arrayValue, "emoji", jsonData)) {
1463 this->emoji.clear();
1464 for (auto value: arrayValue) {
1465 this->emoji.emplace_back(getId(value.value(), "id"));
1466 }
1467 }
1468
1469 if (Roles::doWeCacheRoles()) {
1470 this->roles.clear();
1471 if (!getArray(arrayValue, "roles", jsonData)) {
1472 for (auto value: arrayValue) {
1473 RoleData newData{ value.value() };
1474 newData.guildId = this->id;
1475 this->roles.emplace_back(newData.id);
1476 Roles::insertRole(std::move(newData));
1477 }
1478 }
1479 }
1480
1481 if (GuildMembers::doWeCacheGuildMembers()) {
1482 this->members.clear();
1483 GuildMemberData newData{};
1484 if (!getArray(arrayValue, "members", jsonData)) {
1485 for (auto value: arrayValue) {
1486 newData = value.value();
1487 newData.guildId = this->id;
1488 this->members.emplace_back(newData.id);
1489 GuildMembers::insertGuildMember(std::move(newData));
1490 }
1491 }
1492 }
1493
1494 if (!getArray(arrayValue, "voice_states", jsonData)) {
1495 for (auto value: arrayValue) {
1496 VoiceStateDataLight dataNew{ value.value() };
1497 dataNew.guildId = this->id;
1498 GuildMembers::vsCache[dataNew] = dataNew;
1499 }
1500 }
1501
1502 if (GuildMembers::doWeCacheGuildMembers()) {
1503 this->presences.clear();
1504 if (!getArray(arrayValue, "presences", jsonData)) {
1505 for (auto value: arrayValue) {
1506 PresenceUpdateData newData{ value.value() };
1507 newData.guildId = this->id;
1508 this->presences.emplace_back(std::move(newData));
1509 }
1510 }
1511 }
1512
1513 if (Channels::doWeCacheChannels()) {
1514 this->channels.clear();
1515 if (!getArray(arrayValue, "channels", jsonData)) {
1516 for (auto value: arrayValue) {
1517 ChannelData newData{ value.value() };
1518 newData.guildId = this->id;
1519 this->channels.emplace_back(newData.id);
1520 Channels::insertChannel(std::move(newData));
1521 }
1522 }
1523 }
1524 }
1525
1526 GuildDataVector::GuildDataVector(Value jsonData) {
1527 if (jsonData.type() != Jsonifier::JsonType::Null) {
1528 Jsonifier::Array arrayValue{};
1529 if (!getArray(arrayValue, jsonData)) {
1530 for (JsonifierResult<Value> value: arrayValue) {
1531 GuildData newData{ value.value() };
1532 this->guilds.emplace_back(std::move(newData));
1533 }
1534 }
1535 }
1536 }
1537
1538 GuildScheduledEventMetadata::GuildScheduledEventMetadata(Value jsonData) {
1539 this->location = getString(jsonData, "location");
1540 }
1541
1542 GuildScheduledEventData::GuildScheduledEventData(Value jsonData) {
1543 this->privacyLevel = static_cast<GuildScheduledEventPrivacyLevel>(getUint8(jsonData, "privacy_level"));
1544
1545 this->entityType = static_cast<GuildScheduledEventEntityType>(getUint8(jsonData, "entity_type"));
1546
1547 this->status = static_cast<GuildScheduledEventStatus>(getUint8(jsonData, "status"));
1548
1549 Value object{};
1550 if (!getObject(object, "entity_metadata", jsonData)) {
1551 this->entityMetadata = GuildScheduledEventMetadata{ object };
1552 }
1553
1554 this->scheduledStartTime = getString(jsonData, "scheduled_start_time");
1555
1556 this->scheduledEndTime = getString(jsonData, "scheduled_end_time");
1557
1558 this->userCount = getUint32(jsonData, "user_count");
1559
1560 this->channelId = getId(jsonData, "channel_id");
1561
1562 this->creatorId = getId(jsonData, "creator_id");
1563
1564 this->entityId = getId(jsonData, "entity_id");
1565
1566 this->guildId = getId(jsonData, "guild_id");
1567
1568 this->id = getId(jsonData, "id");
1569
1570 this->description = getString(jsonData, "description");
1571
1572 if (!getObject(object, "creator", jsonData)) {
1573 this->creator = UserData{ object };
1574 }
1575
1576 this->name = getString(jsonData, "name");
1577 }
1578
1579 GuildScheduledEventUserData::GuildScheduledEventUserData(Value jsonData) {
1580 this->guildScheduledEventId = getId(jsonData, "guild_scheduled_event_id");
1581
1582 Value object{};
1583 if (!getObject(object, "member", jsonData)) {
1584 this->member = GuildMemberData{ object };
1585 }
1586
1587 if (!getObject(object, "user", jsonData)) {
1588 this->user = UserData{ object };
1589 }
1590 }
1591
1592 GuildScheduledEventUserDataVector::GuildScheduledEventUserDataVector(Value jsonData) {
1593 if (jsonData.type() != Jsonifier::JsonType::Null) {
1594 Jsonifier::Array arrayValue{};
1595 if (!getArray(arrayValue, jsonData)) {
1596 for (JsonifierResult<Value> value: arrayValue) {
1597 GuildScheduledEventUserData newData{ value.value() };
1598 this->guildScheduledEventUsers.emplace_back(std::move(newData));
1599 }
1600 }
1601 }
1602 }
1603
1604 GuildScheduledEventDataVector::GuildScheduledEventDataVector(Value jsonData) {
1605 if (jsonData.type() != Jsonifier::JsonType::Null) {
1606 Jsonifier::Array arrayValue{};
1607 if (!getArray(arrayValue, jsonData)) {
1608 for (JsonifierResult<Value> value: arrayValue) {
1609 GuildScheduledEventData newData{ value.value() };
1610 this->guildScheduledEvents.emplace_back(std::move(newData));
1611 }
1612 }
1613 }
1614 }
1615
1616 InviteData::InviteData(Value jsonData) {
1617 this->code = getUint32(jsonData, "code");
1618
1619 Value object{};
1620 if (!getObject(object, "guild", jsonData)) {
1621 this->guild = GuildData{ object };
1622 }
1623
1624 if (!getObject(object, "channel", jsonData)) {
1625 this->channel = ChannelData{ object };
1626 }
1627
1628 if (!getObject(object, "inviter", jsonData)) {
1629 this->inviter = UserData{ object };
1630 }
1631
1632 this->targetType = getUint32(jsonData, "target_type");
1633
1634 if (!getObject(object, "target_user", jsonData)) {
1635 this->targetUser = UserData{ object };
1636 }
1637
1638 if (!getObject(object, "target_application", jsonData)) {
1639 this->targetApplication = ApplicationData{ object };
1640 }
1641
1642 if (!getObject(object, "stage_instance", jsonData)) {
1643 this->stageInstance = StageInstanceData{ object };
1644 }
1645
1646 if (!getObject(object, "guild_scheduled_event", jsonData)) {
1647 this->guildScheduledEvent = GuildScheduledEventData{ object };
1648 }
1649
1650 this->approximatePresenceCount = getUint32(jsonData, "approximate_presence_count");
1651
1652 this->approximateMemberCount = getUint32(jsonData, "approximate_member_count");
1653
1654 this->guildId = getId(jsonData, "guild_id");
1655
1656 this->expiresAt = getString(jsonData, "expires_at");
1657
1658 this->uses = getUint32(jsonData, "uses");
1659
1660 this->maxUses = getUint32(jsonData, "max_uses");
1661
1662 this->maxAge = getUint32(jsonData, "max_age");
1663
1664 this->temporary = getBool(jsonData, "temporary");
1665
1666 this->createdAt = getString(jsonData, "created_at");
1667 }
1668
1669 InviteDataVector::InviteDataVector(Value jsonData) {
1670 if (jsonData.type() != Jsonifier::JsonType::Null) {
1671 Jsonifier::Array arrayValue{};
1672 if (!getArray(arrayValue, jsonData)) {
1673 for (JsonifierResult<Value> value: arrayValue) {
1674 InviteData newData{ value.value() };
1675 this->invites.emplace_back(std::move(newData));
1676 }
1677 }
1678 }
1679 }
1680
1681 GuildTemplateData::GuildTemplateData(Value jsonData) {
1682 Value object{};
1683 if (!getObject(object, "serialized_source_guild", jsonData)) {
1684 this->serializedSourceGuild = GuildData{ object };
1685 }
1686
1687 if (!getObject(object, "creator", jsonData)) {
1688 this->creator = UserData{ object };
1689 }
1690
1691 this->sourceGuildId = getString(jsonData, "source_guild_id");
1692
1693 this->description = getString(jsonData, "description");
1694
1695 this->usageCount = getUint32(jsonData, "usage_count");
1696
1697 this->creatorId = getString(jsonData, "creator_id");
1698
1699 this->createdAt = getString(jsonData, "created_at");
1700
1701 this->updatedAt = getString(jsonData, "updated_at");
1702
1703 this->isDirty = getBool(jsonData, "is_dirty");
1704
1705 this->code = getString(jsonData, "code");
1706
1707 this->name = getString(jsonData, "name");
1708 }
1709
1710 GuildTemplateDataVector::GuildTemplateDataVector(Value jsonData) {
1711 if (jsonData.type() != Jsonifier::JsonType::Null) {
1712 Jsonifier::Array arrayValue{};
1713 if (!getArray(arrayValue, jsonData)) {
1714 for (JsonifierResult<Value> value: arrayValue) {
1715 GuildTemplateData newData{ value.value() };
1716 this->guildTemplates.emplace_back(std::move(newData));
1717 }
1718 }
1719 }
1720 }
1721
1722 WebHookData::WebHookData(Value jsonData) {
1723 this->id = getId(jsonData, "id");
1724
1725 this->type = static_cast<WebHookType>(getUint8(jsonData, "type"));
1726
1727 this->guildId = getId(jsonData, "guild_id");
1728
1729 this->channelId = getId(jsonData, "channel_id");
1730
1731 Value object{};
1732 if (!getObject(object, "user", jsonData)) {
1733 this->user = UserData{ object };
1734 }
1735
1736 this->name = getString(jsonData, "name");
1737
1738 this->avatar = getString(jsonData, "avatar");
1739
1740 this->token = getString(jsonData, "token");
1741
1742 this->applicationId = getId(jsonData, "application_id");
1743
1744 if (!getObject(object, "source_guild", jsonData)) {
1745 this->sourceGuild = GuildData{ object };
1746 }
1747
1748 if (!getObject(object, "source_channel", jsonData)) {
1749 this->sourceChannel = ChannelData{ object };
1750 }
1751
1752 this->url = getString(jsonData, "url");
1753 }
1754
1755 WebHookDataVector::WebHookDataVector(Value jsonData) {
1756 if (jsonData.type() != Jsonifier::JsonType::Null) {
1757 Jsonifier::Array arrayValue{};
1758 if (!getArray(arrayValue, jsonData)) {
1759 for (JsonifierResult<Value> value: arrayValue) {
1760 WebHookData newData{ value.value() };
1761 this->webHooks.emplace_back(std::move(newData));
1762 }
1763 }
1764 }
1765 }
1766
1767 AuditLogData::AuditLogData(Value jsonData) {
1768 Jsonifier::Array arrayValue{};
1769 if (!getArray(arrayValue, "webhooks", jsonData)) {
1770 for (JsonifierResult<Value> value: arrayValue) {
1771 WebHookData newData{ value.value() };
1772 this->webhooks.emplace_back(std::move(newData));
1773 }
1774 }
1775
1776 if (!getArray(arrayValue, "guild_scheduled_events", jsonData)) {
1777 for (JsonifierResult<Value> value: arrayValue) {
1778 GuildScheduledEventData newData{ value.value() };
1779 this->guildScheduledEvents.emplace_back(std::move(newData));
1780 }
1781 }
1782
1783 if (!getArray(arrayValue, "auto_moderation_rules", jsonData)) {
1784 for (JsonifierResult<Value> value: arrayValue) {
1785 AutoModerationRuleData newData{ value.value() };
1786 this->autoModerationRules.emplace_back(std::move(newData));
1787 }
1788 }
1789
1790 if (!getArray(arrayValue, "users", jsonData)) {
1791 for (JsonifierResult<Value> value: arrayValue) {
1792 UserData newData{ value.value() };
1793 this->users.emplace_back(std::move(newData));
1794 }
1795 }
1796
1797 if (!getArray(arrayValue, "audit_log_entries", jsonData)) {
1798 for (JsonifierResult<Value> value: arrayValue) {
1799 AuditLogEntryData newData{ value.value() };
1800 this->auditLogEntries.emplace_back(std::move(newData));
1801 }
1802 }
1803
1804 if (!getArray(arrayValue, "integrations", jsonData)) {
1805 for (JsonifierResult<Value> value: arrayValue) {
1806 IntegrationData newData{ value.value() };
1807 this->integrations.emplace_back(std::move(newData));
1808 }
1809 }
1810
1811 if (!getArray(arrayValue, "threads", jsonData)) {
1812 for (JsonifierResult<Value> value: arrayValue) {
1813 ChannelData newData{ value.value() };
1814 this->threads.emplace_back(std::move(newData));
1815 }
1816 }
1817 }
1818
1819 ReactionRemoveData::ReactionRemoveData(Value jsonData) {
1820 this->userId = getId(jsonData, "user_id");
1821
1822 this->channelId = getId(jsonData, "channel_id");
1823
1824 this->messageId = getId(jsonData, "message_id");
1825
1826 this->guildId = getId(jsonData, "guild_id");
1827
1828 Value object{};
1829 if (!getObject(object, "emoji", jsonData)) {
1830 this->emoji = EmojiData{ object };
1831 }
1832 }
1833
1834 ApplicationCommandOptionChoiceData::ApplicationCommandOptionChoiceData(Value jsonData) {
1835 std::string_view string{};
1836 uint64_t integer{};
1837 bool theBool{};
1838 double doubleVal{};
1839
1840 if (jsonData["value"].get(string) == Jsonifier::ErrorCode::Success) {
1841 this->value = static_cast<std::string>(string);
1842 this->type = JsonType::String;
1843 } else if (jsonData["value"].get(integer) == Jsonifier::ErrorCode::Success) {
1844 this->value = std::to_string(integer);
1845 this->type = JsonType::Int64;
1846 } else if (jsonData["value"].get(theBool) == Jsonifier::ErrorCode::Success) {
1847 this->type = JsonType::Bool;
1848 std::stringstream stream{};
1849 stream << std::boolalpha << theBool;
1850 this->value = stream.str();
1851 } else if (jsonData["value"].get(doubleVal) == Jsonifier::ErrorCode::Success) {
1852 this->type = JsonType::Float;
1853 this->value = std::to_string(doubleVal);
1854 }
1855
1856 this->name = getString(jsonData, "name");
1857
1858 Object map{};
1859 if (jsonData["name_localizations"].get(map) == Jsonifier::ErrorCode::Success) {
1860 this->nameLocalizations.clear();
1861 for (auto value: map) {
1862 this->nameLocalizations.emplace(value.unescapedKey().takeValue(), value.value().getString().takeValue());
1863 }
1864 }
1865 }
1866
1867 bool operator==(const ApplicationCommandOptionChoiceData& lhs, const ApplicationCommandOptionChoiceData& rhs) {
1868 if (lhs.name != rhs.name) {
1869 return false;
1870 }
1871 if (lhs.nameLocalizations != rhs.nameLocalizations) {
1872 return false;
1873 }
1874 if (lhs.type != rhs.type) {
1875 return false;
1876 }
1877 if (lhs.value != rhs.value) {
1878 return false;
1879 }
1880 return true;
1881 }
1882
1883 ApplicationCommandOptionData::ApplicationCommandOptionData(Value jsonData) {
1884 this->name = getString(jsonData, "name");
1885
1886 Object map{};
1887 if (jsonData["name_localizations"].get(map) == Jsonifier::ErrorCode::Success) {
1888 this->nameLocalizations.clear();
1889 for (auto value: map) {
1890 this->nameLocalizations.emplace(value.unescapedKey().takeValue(), value.value().getString().takeValue());
1891 }
1892 }
1893
1894 if (jsonData["description_localizations"].get(map) == Jsonifier::ErrorCode::Success) {
1895 this->descriptionLocalizations.clear();
1896 for (auto value: map) {
1897 this->descriptionLocalizations.emplace(value.unescapedKey().takeValue(), value.value().getString().takeValue());
1898 }
1899 }
1900
1901 this->description = getString(jsonData, "description");
1902
1903 Jsonifier::Array arrayValue{};
1904 if (!getArray(arrayValue, "channel_types", jsonData)) {
1905 for (JsonifierResult<Value> value: arrayValue) {
1906 this->channelTypes.emplace_back(static_cast<ChannelType>(value.getUint64().value()));
1907 }
1908 }
1909
1910 this->type = static_cast<ApplicationCommandOptionType>(getUint8(jsonData, "type"));
1911
1913 this->minValue = getInt64(jsonData, "min_value");
1914 } else if (this->type == ApplicationCommandOptionType::Number) {
1915 this->minValue = getFloat(jsonData, "min_value");
1916 }
1917
1919 this->maxValue = getInt32(jsonData, "max_value");
1920 } else if (this->type == ApplicationCommandOptionType::Number) {
1921 this->maxValue = getFloat(jsonData, "max_value");
1922 }
1923
1924 this->required = getBool(jsonData, "required");
1925
1926 this->autocomplete = getBool(jsonData, "autocomplete");
1927
1929 if (!getArray(arrayValue, "options", jsonData)) {
1930 for (JsonifierResult<Value> value: arrayValue) {
1931 ApplicationCommandOptionData newData{ value.value() };
1932 this->options.emplace_back(std::move(newData));
1933 }
1934 }
1935 }
1936 if (!getArray(arrayValue, "choices", jsonData)) {
1937 for (JsonifierResult<Value> value: arrayValue) {
1938 ApplicationCommandOptionChoiceData newData{ value.value() };
1939 this->choices.emplace_back(std::move(newData));
1940 }
1941 }
1942 }
1943
1944 bool operator==(const ApplicationCommandOptionData& lhs, const ApplicationCommandOptionData& rhs) {
1945 if (lhs.autocomplete != rhs.autocomplete) {
1946 return false;
1947 }
1948 if (lhs.channelTypes != rhs.channelTypes) {
1949 return false;
1950 }
1951 if (lhs.description != rhs.description) {
1952 return false;
1953 }
1954 if (lhs.descriptionLocalizations != rhs.descriptionLocalizations) {
1955 return false;
1956 }
1957 if (lhs.maxValue != rhs.maxValue) {
1958 return false;
1959 }
1960 if (lhs.minValue != rhs.minValue) {
1961 return false;
1962 }
1963 if (lhs.name != rhs.name) {
1964 return false;
1965 }
1966 if (lhs.nameLocalizations != rhs.nameLocalizations) {
1967 return false;
1968 }
1969 if (lhs.options.size() != rhs.options.size()) {
1970 return false;
1971 }
1972 if (lhs.required != rhs.required) {
1973 return false;
1974 }
1975 if (lhs.type != rhs.type) {
1976 return false;
1977 }
1978 if (lhs.choices.size() != rhs.choices.size()) {
1979 return false;
1980 }
1981 for (int32_t x = 0; x < rhs.choices.size(); ++x) {
1982 if (lhs.choices[x] != rhs.choices[x]) {
1983 }
1984 }
1985 return true;
1986 }
1987
1988 ApplicationCommandData::ApplicationCommandData(Value jsonData) {
1989 this->id = getId(jsonData, "id");
1990
1991 this->defaultMemberPermissions = getString(jsonData, "default_member_permissions");
1992
1993 this->dmPermission = getBool(jsonData, "dm_permission");
1994
1995 this->version = getString(jsonData, "version");
1996
1997 this->type = static_cast<ApplicationCommandType>(getUint8(jsonData, "type"));
1998
1999 Object map{};
2000 if (jsonData["name_localizations"].get(map) == Jsonifier::ErrorCode::Success) {
2001 this->nameLocalizations.clear();
2002 for (auto value: map) {
2003 this->nameLocalizations.emplace(value.unescapedKey().takeValue(), value.value().getString().takeValue());
2004 }
2005 }
2006
2007 if (jsonData["description_localizations"].get(map) == Jsonifier::ErrorCode::Success) {
2008 this->descriptionLocalizations.clear();
2009 for (auto value: map) {
2010 this->descriptionLocalizations.emplace(value.unescapedKey().takeValue(), value.value().getString().takeValue());
2011 }
2012 }
2013
2014 this->applicationId = getId(jsonData, "application_id");
2015
2016 this->name = getString(jsonData, "name");
2017
2018 this->description = getString(jsonData, "description");
2019
2020 this->version = getString(jsonData, "version");
2021
2022 Jsonifier::Array arrayValue{};
2023 if (!getArray(arrayValue, "options", jsonData)) {
2024 for (JsonifierResult<Value> value: arrayValue) {
2025 ApplicationCommandOptionData newData{ value.value() };
2026 this->options.emplace_back(std::move(newData));
2027 }
2028 }
2029 }
2030
2031 bool operator==(const ApplicationCommandData& lhs, const ApplicationCommandData& rhs) {
2032 if (lhs.description != rhs.description) {
2033 return false;
2034 }
2035 if (lhs.name != rhs.name) {
2036 return false;
2037 }
2038 if (lhs.type != rhs.type) {
2039 return false;
2040 }
2041 if (lhs.options.size() != rhs.options.size()) {
2042 return false;
2043 }
2044 for (size_t x = 0; x < lhs.options.size(); ++x) {
2045 if (lhs.options[x] != rhs.options[x]) {
2046 return false;
2047 }
2048 }
2049 return true;
2050 }
2051
2052 TypingStartData::TypingStartData(Value jsonData) {
2053 this->channelId = getId(jsonData, "channel_id");
2054
2055 this->guildId = getId(jsonData, "guild_id");
2056
2057 Value object{};
2058 if (!getObject(object, "member", jsonData)) {
2059 this->member = GuildMemberData{ object };
2060 }
2061
2062 this->userId = getId(jsonData, "user_id");
2063
2064 this->timeStamp = getUint32(jsonData, "timestamp");
2065 }
2066
2067 YouTubeFormat::YouTubeFormat(Value jsonData) {
2068 this->audioQuality = getString(jsonData, "audioQuality");
2069
2070 this->averageBitrate = getUint32(jsonData, "averageBitrate");
2071
2072 this->audioSampleRate = getString(jsonData, "audioSampleRate");
2073
2074 this->bitrate = getUint32(jsonData, "bitrate");
2075
2076 this->contentLength = strtoull(getString(jsonData, "contentLength"));
2077
2078 this->fps = getUint32(jsonData, "fps");
2079
2080 this->height = getUint32(jsonData, "height");
2081
2082 this->height = getUint32(jsonData, "width");
2083
2084 this->aitags = getString(jsonData, "aitags");
2085
2086 this->itag = getUint32(jsonData, "itag");
2087
2088 this->downloadUrl = getString(jsonData, "url");
2089
2090 this->mimeType = getString(jsonData, "mimeType");
2091
2092 this->quality = getString(jsonData, "quality");
2093
2094 std::string string = getString(jsonData, "signatureCipher");
2095 if (string == "") {
2096 string = getString(jsonData, "cipher");
2097 }
2098
2099 this->signatureCipher = string;
2100
2101 auto ampersandSpFind = this->signatureCipher.find("&sp");
2102 if (ampersandSpFind != std::string::npos) {
2103 this->signature = this->signatureCipher.substr(0, ampersandSpFind);
2104 }
2105
2106 auto urlFind = this->signatureCipher.find("url");
2107 if (urlFind != std::string::npos) {
2108 this->downloadUrl = this->signatureCipher.substr(urlFind + 4);
2109 } else {
2110 this->downloadUrl = getString(jsonData, "url");
2111 }
2112 }
2113
2114 YouTubeFormatVector::YouTubeFormatVector(Value jsonData) {
2115 Value valueNew{};
2116 if (!getObject(valueNew, "streamingData", jsonData)) {
2117 Jsonifier::Array arrayValue{};
2118 if (!getArray(arrayValue, "formats", valueNew)) {
2119 for (JsonifierResult<Value> value: arrayValue) {
2120 YouTubeFormat newData{ value.value() };
2121 this->formats.emplace_back(std::move(newData));
2122 }
2123 }
2124 }
2125
2126
2127 if (!getObject(valueNew, "streamingData", jsonData)) {
2128 Jsonifier::Array arrayValue{};
2129 if (!getArray(arrayValue, "adaptiveFormats", valueNew)) {
2130 for (JsonifierResult<Value> value: arrayValue) {
2131 YouTubeFormat newData{ value.value() };
2132 this->formats.emplace_back(std::move(newData));
2133 }
2134 }
2135 }
2136 }
2137
2138 UserCommandInteractionData::UserCommandInteractionData(Value jsonData) {
2139 this->targetId = getId(jsonData, "target_id");
2140 }
2141
2142 MessageCommandInteractionData::MessageCommandInteractionData(Value jsonData) {
2143 this->targetId = getId(jsonData, "target_id");
2144 }
2145
2146 ComponentInteractionData::ComponentInteractionData(Value jsonData) {
2147 Jsonifier::Array arrayValue{};
2148 if (!getArray(arrayValue, "values", jsonData)) {
2149 this->values.clear();
2150 for (auto iterator = arrayValue.begin(); iterator != arrayValue.end(); ++iterator) {
2151 this->values.emplace_back(iterator.value().operator*().getString().takeValue());
2152 }
2153 }
2154
2155 this->customId = getString(jsonData, "custom_id");
2156
2157 this->componentType = static_cast<ComponentType>(getUint8(jsonData, "component_type"));
2158 }
2159
2160 ModalInteractionData::ModalInteractionData(Value jsonData) {
2161 Value theComponent{};
2162 if (jsonData["components"][0]["components"][0].get(theComponent) == Jsonifier::ErrorCode::Success) {
2163 this->value = getString(theComponent, "value");
2164 this->customIdSmall = getString(theComponent, "value");
2165 }
2166
2167 this->customId = getString(jsonData, "custom_id");
2168 }
2169
2170 AllowedMentionsData::AllowedMentionsData(Value jsonData) {
2171 Jsonifier::Array arrayValue{};
2172 if (!getArray(arrayValue, "parse", jsonData)) {
2173 for (JsonifierResult<Value> value: arrayValue) {
2174 this->parse.emplace_back(static_cast<std::string>(value.getString().value()));
2175 }
2176 }
2177
2178 if (!getArray(arrayValue, "roles", jsonData)) {
2179 for (JsonifierResult<Value> value: arrayValue) {
2180 this->roles.emplace_back(static_cast<std::string>(value.getString().value()));
2181 }
2182 }
2183
2184 if (!getArray(arrayValue, "users", jsonData)) {
2185 for (JsonifierResult<Value> value: arrayValue) {
2186 this->users.emplace_back(static_cast<std::string>(value.getString().value()));
2187 }
2188 }
2189
2190 this->repliedUser = getBool(jsonData, "replied_user");
2191 }
2192
2193 SelectOptionData::SelectOptionData(Value jsonData) {
2194 this->label = getString(jsonData, "label");
2195
2196 this->value = getString(jsonData, "value");
2197
2198 this->description = getString(jsonData, "description");
2199
2200 Value theEmoji{};
2201 if (jsonData["emoji"].get(theEmoji) == Jsonifier::ErrorCode::Success) {
2202 this->emoji = EmojiData{ theEmoji };
2203 }
2204
2205 this->_default = getBool(jsonData, "default");
2206 }
2207
2208 ActionRowData::ActionRowData(Value jsonData) {
2209 Jsonifier::Array arrayValue{};
2210 if (!getArray(arrayValue, "components", jsonData)) {
2211 this->components.clear();
2212 for (JsonifierResult<Value> value: arrayValue) {
2213 ComponentData newData{ value.value() };
2214 this->components.emplace_back(std::move(newData));
2215 }
2216 }
2217 }
2218
2219 ComponentData::ComponentData(Value jsonData) {
2220 this->type = static_cast<ComponentType>(getUint8(jsonData, "type"));
2221
2222 this->customId = getString(jsonData, "custom_id");
2223
2224 this->placeholder = getString(jsonData, "placeholder");
2225
2226 this->disabled = getBool(jsonData, "disabled");
2227
2228 this->style = getUint32(jsonData, "style");
2229
2230 this->label = getString(jsonData, "label");
2231
2232 this->minLength = getUint32(jsonData, "min_length");
2233
2234 this->maxLength = getUint32(jsonData, "max_length");
2235
2236 this->maxValues = getUint32(jsonData, "max_values");
2237
2238 this->maxValues = getUint32(jsonData, "min_values");
2239
2240 this->title = getString(jsonData, "title");
2241
2242 this->required = getBool(jsonData, "required");
2243
2244 Value object{};
2245 if (!getObject(object, "emoji", jsonData)) {
2246 this->emoji = EmojiData{ object };
2247 }
2248
2249 this->url = getString(jsonData, "url");
2250
2251 Jsonifier::Array arrayValue{};
2252 if (!getArray(arrayValue, "select_option_data", jsonData)) {
2253 this->options.clear();
2254 for (JsonifierResult<Value> value: arrayValue) {
2255 SelectOptionData newData{ value.value() };
2256 this->options.emplace_back(std::move(newData));
2257 }
2258 }
2259
2260 if (!getArray(arrayValue, "channel_types", jsonData)) {
2261 this->channelTypes.clear();
2262 for (JsonifierResult<Value> value: arrayValue) {
2263 ChannelType newData{ static_cast<ChannelType>(value.value().getInt64().takeValue()) };
2264 this->channelTypes.emplace_back(std::move(newData));
2265 }
2266 }
2267 }
2268
2269 ChannelMentionData::ChannelMentionData(Value jsonData) {
2270 this->id = getId(jsonData, "id");
2271
2272 this->guildId = getId(jsonData, "guild_id");
2273
2274 this->type = static_cast<ChannelType>(getUint8(jsonData, "type"));
2275
2276 this->name = getString(jsonData, "name");
2277 }
2278
2279 ChannelPinsUpdateEventData::ChannelPinsUpdateEventData(Value jsonData) {
2280 this->guildId = getId(jsonData, "guild_id");
2281
2282 this->channelId = getId(jsonData, "channel_id");
2283
2284 this->lastPinTimeStamp = getString(jsonData, "last_pin_timestamp");
2285 }
2286
2287 ThreadListSyncData::ThreadListSyncData(Value jsonData) {
2288 this->guildId = getId(jsonData, "guild_id");
2289
2290 Jsonifier::Array arrayValue{};
2291 if (!getArray(arrayValue, "channel_ids", jsonData)) {
2292 for (JsonifierResult<Value> value: arrayValue) {
2293 this->channelIds.emplace_back(value.getString().takeValue());
2294 }
2295 }
2296
2297 if (!getArray(arrayValue, "members", jsonData)) {
2298 for (JsonifierResult<Value> value: arrayValue) {
2299 ThreadMemberData newData{ value.value() };
2300 this->members.emplace_back(std::move(newData));
2301 }
2302 }
2303
2304 if (!getArray(arrayValue, "threads", jsonData)) {
2305 for (JsonifierResult<Value> value: arrayValue) {
2306 ChannelData newData{ value.value() };
2307 this->threads.emplace_back(std::move(newData));
2308 }
2309 }
2310 }
2311
2312 ThreadMembersUpdateData::ThreadMembersUpdateData(Value jsonData) {
2313 this->guildId = getId(jsonData, "guild_id");
2314
2315 this->id = getId(jsonData, "id");
2316
2317 this->memberCount = getUint32(jsonData, "member_count");
2318
2319 Jsonifier::Array arrayValue{};
2320 if (!getArray(arrayValue, "added_members", jsonData)) {
2321 for (JsonifierResult<Value> value: arrayValue) {
2322 ThreadMemberData newData{ value.value() };
2323 this->addedMembers.emplace_back(std::move(newData));
2324 }
2325 }
2326
2327 if (!getArray(arrayValue, "removed_member_ids", jsonData)) {
2328 for (JsonifierResult<Value> value: arrayValue) {
2329 this->removedMemberIds.emplace_back(value.getString().takeValue());
2330 }
2331 }
2332 }
2333
2334 MessageInteractionData::MessageInteractionData(Value jsonData) {
2335 this->id = getId(jsonData, "id");
2336
2337 this->type = static_cast<InteractionType>(getUint8(jsonData, "type"));
2338
2339 this->name = getString(jsonData, "name");
2340
2341 Value object{};
2342 if (!getObject(object, "user", jsonData)) {
2343 this->user = UserData{ object };
2344 }
2345
2346 if (!getObject(object, "member", jsonData)) {
2347 this->member = GuildMemberData{ object };
2348 }
2349 }
2350
2351 StickerItemData::StickerItemData(Value jsonData) {
2352 this->id = getId(jsonData, "id");
2353
2354 this->name = getString(jsonData, "name");
2355
2356 this->formatType = static_cast<StickerItemType>(getUint8(jsonData, "format_type"));
2357 }
2358
2359 MessageDataOld::MessageDataOld(Value jsonData) {
2360 this->content = getString(jsonData, "content");
2361
2362 this->id = getId(jsonData, "id");
2363
2364 this->channelId = getId(jsonData, "channel_id");
2365
2366 this->guildId = getId(jsonData, "guild_id");
2367
2368 Value object{};
2369 if (!getObject(object, "author", jsonData)) {
2370 this->author = UserData{ object };
2371 }
2372
2373 if (!getObject(object, "member", jsonData)) {
2374 this->member = GuildMemberData{ object };
2375 }
2376
2377 this->timeStamp = getString(jsonData, "timestamp");
2378
2379 this->editedTimestamp = getString(jsonData, "edited_timestamp");
2380
2381 this->tts = getBool(jsonData, "tts");
2382
2383 this->mentionEveryone = getBool(jsonData, "mention_everyone");
2384
2385
2386 Jsonifier::Array arrayValue{};
2387 if (!getArray(arrayValue, "mentions", jsonData)) {
2388 this->mentions.clear();
2389 for (JsonifierResult<Value> value: arrayValue) {
2390 UserData newData{ value.value() };
2391 this->mentions.emplace_back(std::move(newData));
2392 }
2393 }
2394
2395 if (!getArray(arrayValue, "mention_roles", jsonData)) {
2396 this->mentionRoles.clear();
2397 for (JsonifierResult<Value> value: arrayValue) {
2398 std::string_view object = value.getString().takeValue();
2399 this->mentionRoles.emplace_back(std::move(object));
2400 }
2401 }
2402
2403 if (!getArray(arrayValue, "mention_channels", jsonData)) {
2404 this->mentionChannels.clear();
2405 for (JsonifierResult<Value> value: arrayValue) {
2406 ChannelMentionData newChannelData{ value.value() };
2407 this->mentionChannels.emplace_back(std::move(newChannelData));
2408 }
2409 }
2410
2411 if (!getArray(arrayValue, "attachments", jsonData)) {
2412 this->attachments.clear();
2413 for (JsonifierResult<Value> value: arrayValue) {
2414 AttachmentData newAttachmentData{ value.value() };
2415 this->attachments.emplace_back(std::move(newAttachmentData));
2416 }
2417 }
2418
2419 if (!getArray(arrayValue, "embeds", jsonData)) {
2420 this->embeds.clear();
2421 for (JsonifierResult<Value> value: arrayValue) {
2422 EmbedData newEmbedData{ value.value() };
2423 this->embeds.emplace_back(std::move(newEmbedData));
2424 }
2425 }
2426
2427 if (!getArray(arrayValue, "reactions", jsonData)) {
2428 this->reactions.clear();
2429 for (JsonifierResult<Value> value: arrayValue) {
2430 ReactionData newReactionData{ value.value() };
2431 this->reactions.emplace_back(std::move(newReactionData));
2432 }
2433 }
2434
2435 this->nonce = getString(jsonData, "nonce");
2436
2437 this->pinned = getBool(jsonData, "pinned");
2438
2439 this->webHookId = getId(jsonData, "webhook_id");
2440
2441 this->type = static_cast<MessageType>(getUint8(jsonData, "type"));
2442 if (!getObject(object, "activity", jsonData)) {
2443 this->activity = MessageActivityData{ object };
2444 }
2445
2446 if (!getObject(object, "application", jsonData)) {
2447 this->application = ApplicationData{ object };
2448 }
2449
2450 this->applicationId = getId(jsonData, "application_id");
2451
2452 if (!getObject(object, "message_reference", jsonData)) {
2453 this->messageReference = MessageReferenceData{ object };
2454 }
2455
2456 this->flags = getUint32(jsonData, "flags");
2457 if (!getArray(arrayValue, "sticker_items", jsonData)) {
2458 this->stickerItems.clear();
2459 for (JsonifierResult<Value> value: arrayValue) {
2460 StickerItemData newReactionData{ value.value() };
2461 this->stickerItems.emplace_back(std::move(newReactionData));
2462 }
2463 }
2464
2465 if (!getArray(arrayValue, "stickers", jsonData)) {
2466 this->stickers.clear();
2467 for (JsonifierResult<Value> value: arrayValue) {
2468 StickerData newReactionData{ value.value() };
2469 this->stickers.emplace_back(std::move(newReactionData));
2470 }
2471 }
2472
2473 if (!getObject(object, "interaction", jsonData)) {
2474 this->interaction = MessageInteractionData{ object };
2475 }
2476
2477 if (!getArray(arrayValue, "components", jsonData)) {
2478 this->components.clear();
2479 for (JsonifierResult<Value> value: arrayValue) {
2480 ActionRowData newActionRowData{ value.value() };
2481 this->components.emplace_back(std::move(newActionRowData));
2482 }
2483 }
2484
2485 if (!getObject(object, "thread", jsonData)) {
2486 this->thread = ChannelData{ object };
2487 }
2488 }
2489
2490 MessageData::MessageData(Value jsonData) {
2491 this->content = getString(jsonData, "content");
2492
2493 this->id = getId(jsonData, "id");
2494
2495 this->channelId = getId(jsonData, "channel_id");
2496
2497 this->guildId = getId(jsonData, "guild_id");
2498
2499 Value object{};
2500 if (!getObject(object, "author", jsonData)) {
2501 this->author = UserData{ object };
2502 }
2503
2504 if (!getObject(object, "member", jsonData)) {
2505 this->member = GuildMemberData{ object };
2506 }
2507
2508 this->timeStamp = getString(jsonData, "timestamp");
2509
2510 this->editedTimestamp = getString(jsonData, "edited_timestamp");
2511
2512 this->tts = getBool(jsonData, "tts");
2513
2514 this->mentionEveryone = getBool(jsonData, "mention_everyone");
2515
2516
2517 Jsonifier::Array arrayValue{};
2518 if (!getArray(arrayValue, "mentions", jsonData)) {
2519 this->mentions.clear();
2520 for (JsonifierResult<Value> value: arrayValue) {
2521 UserData newData{ value.value() };
2522 this->mentions.emplace_back(std::move(newData));
2523 }
2524 }
2525
2526 if (!getArray(arrayValue, "mention_roles", jsonData)) {
2527 this->mentionRoles.clear();
2528 for (JsonifierResult<Value> value: arrayValue) {
2529 std::string_view object = value.getString().takeValue();
2530 this->mentionRoles.emplace_back(std::move(object));
2531 }
2532 }
2533
2534 if (!getArray(arrayValue, "mention_channels", jsonData)) {
2535 this->mentionChannels.clear();
2536 for (JsonifierResult<Value> value: arrayValue) {
2537 ChannelMentionData newChannelData{ value.value() };
2538 this->mentionChannels.emplace_back(std::move(newChannelData));
2539 }
2540 }
2541
2542 if (!getArray(arrayValue, "attachments", jsonData)) {
2543 this->attachments.clear();
2544 for (JsonifierResult<Value> value: arrayValue) {
2545 AttachmentData newAttachmentData{ value.value() };
2546 this->attachments.emplace_back(std::move(newAttachmentData));
2547 }
2548 }
2549
2550 if (!getArray(arrayValue, "embeds", jsonData)) {
2551 this->embeds.clear();
2552 for (JsonifierResult<Value> value: arrayValue) {
2553 EmbedData newEmbedData{ value.value() };
2554 this->embeds.emplace_back(std::move(newEmbedData));
2555 }
2556 }
2557
2558 if (!getArray(arrayValue, "reactions", jsonData)) {
2559 this->reactions.clear();
2560 for (JsonifierResult<Value> value: arrayValue) {
2561 ReactionData newReactionData{ value.value() };
2562 this->reactions.emplace_back(std::move(newReactionData));
2563 }
2564 }
2565
2566 this->nonce = getString(jsonData, "nonce");
2567
2568 this->pinned = getBool(jsonData, "pinned");
2569
2570 this->webHookId = getId(jsonData, "webhook_id");
2571
2572 this->type = static_cast<MessageType>(getUint8(jsonData, "type"));
2573
2574 if (!getObject(object, "activity", jsonData)) {
2575 this->activity = MessageActivityData{ object };
2576 }
2577
2578 if (!getObject(object, "application", jsonData)) {
2579 this->application = ApplicationData{ object };
2580 }
2581
2582 this->applicationId = getId(jsonData, "application_id");
2583
2584 if (!getObject(object, "referenced_message", jsonData)) {
2585 this->referencedMessage = std::make_unique<MessageDataOld>(object);
2586 }
2587
2588 if (!getObject(object, "message_reference", jsonData)) {
2589 this->messageReference = MessageReferenceData{ object };
2590 }
2591
2592 this->flags = getUint32(jsonData, "flags");
2593
2594 if (!getArray(arrayValue, "sticker_items", jsonData)) {
2595 this->stickerItems.clear();
2596 for (JsonifierResult<Value> value: arrayValue) {
2597 StickerItemData newReactionData{ value.value() };
2598 this->stickerItems.emplace_back(std::move(newReactionData));
2599 }
2600 }
2601
2602 if (!getArray(arrayValue, "stickers", jsonData)) {
2603 this->stickers.clear();
2604 for (JsonifierResult<Value> value: arrayValue) {
2605 StickerData newReactionData{ value.value() };
2606 this->stickers.emplace_back(std::move(newReactionData));
2607 }
2608 }
2609
2610 if (!getObject(object, "interaction", jsonData)) {
2611 this->interaction = MessageInteractionData{ object };
2612 }
2613
2614 if (!getArray(arrayValue, "components", jsonData)) {
2615 this->components.clear();
2616 for (JsonifierResult<Value> value: arrayValue) {
2617 ActionRowData newActionRowData{ value.value() };
2618 this->components.emplace_back(std::move(newActionRowData));
2619 }
2620 }
2621
2622 if (!getObject(object, "thread", jsonData)) {
2623 this->thread = ChannelData{ object };
2624 }
2625 }
2626
2627 ResolvedData::ResolvedData(Value jsonData) {
2628 Object arrayValue{};
2629 if (jsonData["attachments"].get(arrayValue) == Jsonifier::ErrorCode::Success) {
2630 this->attachments.clear();
2631 for (JsonifierResult<Field> value: arrayValue) {
2632 AttachmentData newData{ value.value() };
2633 this->attachments[strtoull(std::string{ value.key().takeValue().raw() })] = std::move(newData);
2634 }
2635 }
2636 if (jsonData["users"].get(arrayValue) == Jsonifier::ErrorCode::Success) {
2637 this->users.clear();
2638 for (JsonifierResult<Field> value: arrayValue) {
2639 UserData newData{ value.value() };
2640 this->users[strtoull(std::string{ value.key().takeValue().raw() })] = std::move(newData);
2641 }
2642 }
2643 if (jsonData["channels"].get(arrayValue) == Jsonifier::ErrorCode::Success) {
2644 this->channels.clear();
2645 for (JsonifierResult<Field> value: arrayValue) {
2646 ChannelData newData{ value.value() };
2647 this->channels[strtoull(std::string{ value.key().takeValue().raw() })] = std::move(newData);
2648 }
2649 }
2650 if (jsonData["roles"].get(arrayValue) == Jsonifier::ErrorCode::Success) {
2651 this->roles.clear();
2652 for (JsonifierResult<Field> value: arrayValue) {
2653 RoleData newData{ value.value() };
2654 }
2655 }
2656
2657 if (jsonData["members"].get(arrayValue) == Jsonifier::ErrorCode::Success) {
2658 this->members.clear();
2659 for (JsonifierResult<Field> value: arrayValue) {
2660 GuildMemberData newData{ value.value() };
2661 this->members[strtoull(std::string{ value.key().takeValue().raw() })] = std::move(newData);
2662 }
2663 }
2664
2665 if (jsonData["messages"].get(arrayValue) == Jsonifier::ErrorCode::Success) {
2666 this->messages.clear();
2667 for (JsonifierResult<Field> value: arrayValue) {
2668 MessageData newData{ value.value() };
2669 this->messages[strtoull(std::string{ value.key().takeValue().raw() })] = std::move(newData);
2670 }
2671 }
2672 }
2673
2674 StickerPackData::StickerPackData(Value jsonData) {
2675 Jsonifier::Array arrayValue{};
2676 if (!getArray(arrayValue, "stickers", jsonData)) {
2677 for (JsonifierResult<Value> value: arrayValue) {
2678 StickerData newData{ value.value() };
2679 this->stickers.emplace_back(std::move(newData));
2680 }
2681 }
2682
2683 this->coverStickerId = getString(jsonData, "cover_sticker_id");
2684
2685 this->bannerAssetId = getString(jsonData, "banner_asset_id");
2686
2687 this->description = getString(jsonData, "description");
2688
2689 this->name = getString(jsonData, "name");
2690
2691 this->Id = getId(jsonData, "id");
2692
2693 this->skuId = getString(jsonData, "sku_id");
2694 }
2695
2696 StickerPackDataVector::StickerPackDataVector(Value jsonData) {
2697 if (jsonData.type() != Jsonifier::JsonType::Null) {
2698 Jsonifier::Array arrayValue{};
2699 if (!getArray(arrayValue, jsonData)) {
2700 for (JsonifierResult<Value> value: arrayValue) {
2701 StickerPackData newData{ value.value() };
2702 this->stickerPacks.emplace_back(std::move(newData));
2703 }
2704 }
2705 }
2706 }
2707
2708 ConnectionData::ConnectionData(Value jsonData) {
2709 this->name = getString(jsonData, "name");
2710
2711 this->id = getId(jsonData, "id");
2712
2713 this->type = getString(jsonData, "type");
2714
2715 this->showActivity = getBool(jsonData, "show_activity");
2716
2717 this->friendSync = getBool(jsonData, "friend_sync");
2718
2719 this->revoked = getBool(jsonData, "revoked");
2720
2721 this->verified = getBool(jsonData, "verified");
2722
2723 this->visibility = static_cast<ConnectionVisibilityTypes>(getUint8(jsonData, "visibility"));
2724
2725 Jsonifier::Array arrayValue{};
2726 if (!getArray(arrayValue, "integrations", jsonData)) {
2727 for (JsonifierResult<Value> value: arrayValue) {
2728 IntegrationData newData{ value.value() };
2729 this->integrations.emplace_back(std::move(newData));
2730 }
2731 }
2732 }
2733
2734 ApplicationCommandInteractionDataOption::ApplicationCommandInteractionDataOption(Value jsonData) {
2735 this->type = static_cast<ApplicationCommandOptionType>(getUint8(jsonData, "type"));
2736
2737 this->focused = getBool(jsonData, "focused");
2738
2739 this->name = getString(jsonData, "name");
2740 Jsonifier::Array arrayValue{};
2741 if (!getArray(arrayValue, "options", jsonData)) {
2742 for (JsonifierResult<Value> value: arrayValue) {
2743 ApplicationCommandInteractionDataOption newData{ value.value() };
2744 this->options.emplace_back(std::move(newData));
2745 }
2746 }
2747
2748 Jsonifier::Value newValue{};
2749 if (jsonData["value"].get(newValue) == Jsonifier::Success) {
2750 switch (newValue.type()) {
2751 case JsonType::String: {
2752 this->value.type = JsonType::String;
2753 this->value.value = newValue.getString().value();
2754 return;
2755 }
2756 case JsonType::Uint64: {
2757 this->value.type = JsonType::Uint64;
2758 this->value.value = newValue.getUint64().value();
2759 return;
2760 }
2761 case JsonType::Bool: {
2762 this->value.type = JsonType::Bool;
2763 this->value.value = newValue.getBool().value();
2764 return;
2765 }
2766 case JsonType::Float: {
2767 this->value.type = JsonType::Float;
2768 this->value.value = newValue.getDouble().value();
2769 return;
2770 }
2771 }
2772 }
2773
2774 this->value.type = JsonType::Null;
2775 }
2776
2777 ApplicationCommandInteractionData::ApplicationCommandInteractionData(Value jsonData) {
2778 this->type = static_cast<ApplicationCommandType>(getUint8(jsonData, "type"));
2779
2780 this->name = getString(jsonData, "name");
2781
2782 this->guildId = getId(jsonData, "guild_id");
2783
2784 this->id = getId(jsonData, "id");
2785
2786 Jsonifier::Array arrayValue{};
2787 if (!getArray(arrayValue, "options", jsonData)) {
2788 for (JsonifierResult<Value> value: arrayValue) {
2789 ApplicationCommandInteractionDataOption newData{ value.value() };
2790 this->options.emplace_back(std::move(newData));
2791 }
2792 }
2793
2794 Value object{};
2795 if (!getObject(object, "resolved", jsonData)) {
2796 this->resolved = ResolvedData{ object };
2797 }
2798 }
2799
2800 InteractionDataData::InteractionDataData(Value jsonData) {
2801 Value object{};
2802 if (!getObject(object, "id", jsonData)) {
2803 this->applicationCommandData = ApplicationCommandInteractionData{ jsonData };
2804 }
2805
2806 if (!getObject(object, "target_id", jsonData)) {
2807 this->messageInteractionData = MessageCommandInteractionData{ jsonData };
2808 this->userInteractionData = UserCommandInteractionData{ jsonData };
2809 }
2810
2811 uint64_t componentType{};
2812 if (!getObject(object, "component_type", jsonData)) {
2813 this->componentData = ComponentInteractionData{ jsonData };
2814 }
2815
2816 if (!getObject(object, "components", jsonData)) {
2817 this->modalData = ModalInteractionData{ jsonData };
2818 }
2819 }
2820
2821 InteractionData::InteractionData(Value jsonData) {
2822 Value object{};
2823 if (!getObject(object, "data", jsonData)) {
2824 this->data = InteractionDataData{ object };
2825 }
2826
2827 this->appPermissions = getString(jsonData, "app_permissions");
2828
2829 this->type = static_cast<InteractionType>(getUint8(jsonData, "type"));
2830
2831 this->token = getString(jsonData, "token");
2832 if (!getObject(object, "member", jsonData)) {
2833 this->member = GuildMemberData{ object };
2834 this->user.id = this->member.id;
2835 this->user.userName = this->member.getUserData().userName;
2836 }
2837
2838 if (!getObject(object, "user", jsonData)) {
2839 this->user = UserData{ object };
2840 }
2841
2842 this->channelId = getId(jsonData, "channel_id");
2843
2844 this->guildId = getId(jsonData, "guild_id");
2845
2846 this->locale = getString(jsonData, "locale");
2847
2848 this->guildLocale = getString(jsonData, "guild_locale");
2849
2850 if (!getObject(object, "message", jsonData)) {
2851 this->message = MessageData{ object };
2852 }
2853
2854 this->version = getUint32(jsonData, "version");
2855
2856 this->id = getId(jsonData, "id");
2857
2858 this->applicationId = getId(jsonData, "application_id");
2859 }
2860
2861 SessionStartData::SessionStartData(Value jsonData) {
2862 this->maxConcurrency = getUint32(jsonData, "max_concurrency");
2863
2864 this->remaining = getUint32(jsonData, "remaining");
2865
2866 this->resetAfter = getUint32(jsonData, "reset_after");
2867
2868 this->total = getUint32(jsonData, "total");
2869 }
2870
2871 GatewayBotData::GatewayBotData(Value jsonData) {
2872 this->url = getString(jsonData, "url");
2873
2874 this->shards = getUint32(jsonData, "shards");
2875
2876 Value object{};
2877 if (!getObject(object, "session_start_limit", jsonData)) {
2878 this->sessionStartLimit = SessionStartData{ object };
2879 }
2880 }
2881
2882 GuildEmojisUpdateEventData::GuildEmojisUpdateEventData(Value jsonData) {
2883 this->guildId = getId(jsonData, "guild_id");
2884
2885 Jsonifier::Array arrayValue{};
2886 if (!getArray(arrayValue, "emojis", jsonData)) {
2887 for (JsonifierResult<Value> value: arrayValue) {
2888 EmojiData newData{ value.value() };
2889 this->emojis.emplace_back(std::move(newData));
2890 }
2891 }
2892 }
2893
2894 GuildStickersUpdateEventData::GuildStickersUpdateEventData(Value jsonData) {
2895 this->guildId = getId(jsonData, "guild_id");
2896
2897 Jsonifier::Array arrayValue{};
2898 if (!getArray(arrayValue, "stickers", jsonData)) {
2899 for (JsonifierResult<Value> value: arrayValue) {
2900 StickerData newData{ value.value() };
2901 this->stickers.emplace_back(std::move(newData));
2902 }
2903 }
2904 }
2905
2906 GuildMembersChunkEventData::GuildMembersChunkEventData(Value jsonData) {
2907 this->guildId = getId(jsonData, "guild_id");
2908
2909 this->nonce = getString(jsonData, "nonce");
2910
2911 this->chunkIndex = getUint32(jsonData, "chunk_index");
2912
2913 this->chunkCount = getUint32(jsonData, "chunk_count");
2914
2915 Jsonifier::Array arrayValue{};
2916 if (!getArray(arrayValue, "presences", jsonData)) {
2917 for (JsonifierResult<Value> value: arrayValue) {
2918 PresenceUpdateData newData{ value.value() };
2919 this->presences.emplace_back(std::move(newData));
2920 }
2921 }
2922
2923 if (!getArray(arrayValue, "not_found", jsonData)) {
2924 for (JsonifierResult<Value> value: arrayValue) {
2925 this->notFound.emplace_back(value.getString().takeValue());
2926 }
2927 }
2928
2929 if (!getArray(arrayValue, "members", jsonData)) {
2930 for (JsonifierResult<Value> value: arrayValue) {
2931 GuildMemberData newData{ value.value() };
2932 this->members.emplace_back(std::move(newData));
2933 }
2934 }
2935 }
2936
2937 MediaTranscoding::MediaTranscoding(Value jsonData) {
2938 this->thePreset = getString(jsonData, "preset");
2939
2940 this->theUrl = getString(jsonData, "url");
2941 }
2942
2943 Song::Song(Value jsonData) {
2944 this->duration =
2945 getString(getObject(getObject(getObject(jsonData, "lengthText"), "accessibility"), "accessibilityData"), "label");
2946 std::string newString = getString(
2947 getObject(getArray(getObject(getObject(getArray(jsonData, "detailedMetadataSnippets"), 0), "snippetText"), "runs"), 0),
2948 "text");
2949 if (newString.size() > 256) {
2950 newString = newString.substr(0, 256);
2951 }
2952 this->description = utf8MakeValid(newString);
2953
2954 this->thumbnailUrl = getString(getObject(getArray(getObject(jsonData, "thumbnail"), "thumbnails"), 0), "url");
2955 std::string newTitle01 = getString(getObject(getArray(getObject(jsonData, "title"), "runs"), 0), "text");
2956 if (newTitle01.size() > 256) {
2957 newTitle01 = newTitle01.substr(0, 256);
2958 }
2959 if (newTitle01.size() > 0) {
2960 this->songTitle = utf8MakeValid(newTitle01);
2961 }
2962 std::string newTitle02 = getString(getObject(jsonData, "title"), "simpleText");
2963 if (newTitle02.size() > 256) {
2964 newTitle02 = newTitle02.substr(0, 256);
2965 }
2966 if (newTitle02.size() > 0) {
2967 this->songTitle = utf8MakeValid(newTitle02);
2968 }
2969
2970 if (newTitle01 != "") {
2971 this->songTitle = newTitle01;
2972 } else {
2973 this->songTitle = newTitle02;
2974 }
2975
2976 this->songId = getString(jsonData, "videoId");
2977
2978 this->trackAuthorization = getString(jsonData, "track_authorization");
2979
2980 std::vector<MediaTranscoding> theMedia{};
2981 auto arrayValueNew = getArray(getObject(jsonData, "media"), "transcodings");
2982 if (arrayValueNew.didItSucceed) {
2983 for (auto value: arrayValueNew.arrayValue) {
2984 MediaTranscoding dataNew{ value.value() };
2985 theMedia.emplace_back(dataNew);
2986 }
2987 }
2988
2989 bool isItFound{};
2990 for (auto& value: theMedia) {
2991 if (value.thePreset == "opus_0_0") {
2992 isItFound = true;
2993 this->firstDownloadUrl = value.theUrl;
2994 this->songId = value.theUrl;
2995 this->doWeGetSaved = true;
2996 }
2997 }
2998 bool isItFound2{};
2999 if (!isItFound) {
3000 for (auto& value: theMedia) {
3001 if (value.thePreset == "mp3_0_0") {
3002 this->firstDownloadUrl = value.theUrl;
3003 this->songId = value.theUrl;
3004 isItFound2 = true;
3005 }
3006 }
3007 }
3008 if (!isItFound2 && !isItFound) {
3009 for (auto& value: theMedia) {
3010 this->firstDownloadUrl = value.theUrl;
3011 this->songId = value.theUrl;
3012 }
3013 }
3014
3015 newString = getString(jsonData, "title");
3016 if (newString.size() > 0) {
3017 if (newString.size() > 256) {
3018 newString = newString.substr(0, 256);
3019 }
3020 this->songTitle = utf8MakeValid(newString);
3021 }
3022
3023 newString = getString(jsonData, "description");
3024 if (newString.size() > 0) {
3025 if (newString.size() > 256) {
3026 newString = newString.substr(0, 256);
3027 }
3028 this->description = utf8MakeValid(newString);
3029 this->description += "...";
3030 }
3031
3032 newString = getString(jsonData, "artwork_url");
3033 if (newString.size() > 0) {
3034 this->thumbnailUrl = newString;
3035 }
3036
3037 newString = getString(getObject(jsonData, "user"), "avatar_url");
3038 if (newString.size() > 0) {
3039 this->thumbnailUrl = newString;
3040 }
3041
3042 uint32_t theDuration = getUint32(jsonData, "duration");
3043 if (theDuration != 0) {
3044 this->duration = TimeStamp::convertMsToDurationString(theDuration);
3045 }
3046
3047 newString = getString(jsonData, "permalink_url");
3048 if (newString.size() > 0) {
3049 this->viewUrl = newString;
3050 }
3051 }
3052
3053 AttachmentData::operator Serializer() {
3054 Serializer data{};
3055 data["content_type"] = this->contentType;
3056 data["description"] = this->description;
3057 data["ephemeral"] = this->ephemeral;
3058 data["file_name"] = this->filename;
3059 data["proxy_url"] = this->proxyUrl;
3060 data["height"] = this->height;
3061 data["width"] = this->width;
3062 data["size"] = this->size;
3063 data["url"] = this->url;
3064 return data;
3065 }
3066
3067 EmbedFieldData::operator Serializer() {
3068 Serializer data{};
3069 data["inline"] = this->Inline;
3070 data["value"] = escapeCharacters(this->value);
3071 data["name"] = escapeCharacters(this->name);
3072 return data;
3073 }
3074
3075 EmbedData::operator Serializer() {
3076 Serializer data{};
3077 for (auto& value2: this->fields) {
3078 data["fields"].emplaceBack(value2.operator Serializer());
3079 }
3080 std::string realColorVal = std::to_string(this->hexColorValue.getIntColorValue());
3081 data["footer"]["proxy_icon_url"] = this->footer.proxyIconUrl;
3082 data["footer"]["icon_url"] = this->footer.iconUrl;
3083 data["footer"]["text"] = escapeCharacters(this->footer.text);
3084 data["author"]["proxy_icon_url"] = this->author.proxyIconUrl;
3085 data["author"]["icon_url"] = this->author.iconUrl;
3086 data["author"]["name"] = this->author.name;
3087 data["author"]["url"] = this->author.url;
3088 data["thumbnail"]["proxy_url"] = this->thumbnail.proxyUrl;
3089 data["thumbnail"]["height"] = this->thumbnail.height;
3090 data["thumbnail"]["width"] = this->thumbnail.width;
3091 data["thumbnail"]["url"] = this->thumbnail.url;
3092 data["image"]["proxy_url"] = this->image.proxyUrl;
3093 data["image"]["height"] = this->image.height;
3094 data["image"]["width"] = this->image.width;
3095 data["image"]["url"] = this->image.url;
3096 data["video"]["proxy_url"] = this->video.proxyUrl;
3097 data["video"]["height"] = this->video.height;
3098 data["video"]["url"] = this->video.url;
3099 data["video"]["width"] = this->video.width;
3100 data["provider"]["name"] = this->provider.name;
3101 data["provider"]["url"] = this->provider.url;
3102 data["description"] = escapeCharacters(this->description);
3103 data["timestamp"] = this->timeStamp;
3104 data["title"] = escapeCharacters(this->title);
3105 data["color"] = realColorVal;
3106 data["type"] = this->type;
3107 data["url"] = this->url;
3108 return data;
3109 }
3110
3111 EmbedData& EmbedData::setAuthor(const std::string& authorName, const std::string& authorAvatarUrl) {
3112 this->author.name = authorName;
3113 this->author.iconUrl = authorAvatarUrl;
3114 return *this;
3115 }
3116
3117 EmbedData& EmbedData::setFooter(const std::string& footerText, const std::string& footerIconUrlText) {
3118 this->footer.text = footerText;
3119 this->footer.iconUrl = footerIconUrlText;
3120 return *this;
3121 }
3122
3123 EmbedData& EmbedData::setTimeStamp(const std::string& timeStamp) {
3124 this->timeStamp = timeStamp;
3125 return *this;
3126 }
3127
3128 EmbedData& EmbedData::addField(const std::string& name, const std::string& value, bool Inline) {
3129 EmbedFieldData field{};
3130 field.Inline = Inline;
3131 field.value = value;
3132 field.name = name;
3133 this->fields.emplace_back(field);
3134 return *this;
3135 }
3136
3137 EmbedData& EmbedData::setDescription(const std::string& descriptionNew) {
3138 this->description = descriptionNew;
3139 return *this;
3140 }
3141
3142 EmbedData& EmbedData::setColor(const std::string& hexColorValueNew) {
3143 this->hexColorValue = hexColorValueNew;
3144 return *this;
3145 }
3146
3147 EmbedData& EmbedData::setThumbnail(const std::string& thumbnailUrl) {
3148 this->thumbnail.url = thumbnailUrl;
3149 return *this;
3150 }
3151
3152 EmbedData& EmbedData::setTitle(const std::string& titleNew) {
3153 this->title = titleNew;
3154 return *this;
3155 }
3156
3157 EmbedData& EmbedData::setImage(const std::string& imageUrl) {
3158 this->image.url = imageUrl;
3159 return *this;
3160 }
3161
3162 MessageReferenceData::operator Serializer() {
3163 Serializer data{};
3164 data["fail_if_not_exists"] = this->failIfNotExists;
3165 data["message_id"] = this->messageId;
3166 data["channel_id"] = this->channelId;
3167 data["guild_id"] = this->guildId;
3168 return data;
3169 }
3170
3171 GuildApplicationCommandPermissionsDataVector::operator std::vector<GuildApplicationCommandPermissionsData>() {
3172 return this->guildApplicationCommandPermissionss;
3173 }
3174
3175 BanDataVector::operator std::vector<BanData>() {
3176 return this->bans;
3177 }
3178
3179 UpdateVoiceStateData::operator Serializer() {
3180 Serializer data{};
3181 data["op"] = 4;
3182 if (this->channelId == 0) {
3183 data["d"]["channel_id"] = JsonType::Null;
3184 } else {
3185 data["d"]["channel_id"] = this->channelId;
3186 }
3187 data["d"]["self_deaf"] = this->selfDeaf;
3188 data["d"]["self_mute"] = this->selfMute;
3189 data["d"]["guild_id"] = this->guildId;
3190 return data;
3191 }
3192
3193 GuildDataVector::operator std::vector<GuildData>() {
3194 return this->guilds;
3195 }
3196
3197 GuildScheduledEventUserDataVector::operator std::vector<GuildScheduledEventUserData>() {
3198 return this->guildScheduledEventUsers;
3199 }
3200
3201 GuildScheduledEventDataVector::operator std::vector<GuildScheduledEventData>() {
3202 return this->guildScheduledEvents;
3203 }
3204
3205 InviteDataVector::operator std::vector<InviteData>() {
3206 return this->invites;
3207 }
3208
3209 GuildTemplateDataVector::operator std::vector<GuildTemplateData>() {
3210 return this->guildTemplates;
3211 }
3212
3213 WebHookDataVector::operator std::vector<WebHookData>() {
3214 return this->webHooks;
3215 }
3216
3217 auto AuditLogData::getAuditLogData(const Snowflake userIdOfChanger, AuditLogEvent auditLogType) {
3218 for (auto& value: this->auditLogEntries) {
3219 if (value.id == userIdOfChanger && value.actionType == auditLogType) {
3220 return value;
3221 }
3222 }
3223 return AuditLogEntryData();
3224 }
3225
3226 auto AuditLogData::getAuditLogData(AuditLogEvent auditLogType, const Snowflake userIdOfTarget) {
3227 for (auto& value: this->auditLogEntries) {
3228 if (value.targetId == userIdOfTarget && value.actionType == auditLogType) {
3229 return value;
3230 }
3231 }
3232 return AuditLogEntryData();
3233 }
3234
3235 ApplicationCommandOptionChoiceData::operator Serializer() {
3236 Serializer data{};
3237 data["name"] = this->name;
3238 data["name_localizations"] = this->nameLocalizations;
3239 switch (this->type) {
3240 case JsonType::Int64: {
3241 data["value"] = uint64_t{ stoull(this->value) };
3242 break;
3243 }
3244 case JsonType::Uint64: {
3245 data["value"] = uint64_t{ stoull(this->value) };
3246 break;
3247 }
3248 case JsonType::Float: {
3249 data["value"] = double{ stod(this->value) };
3250 break;
3251 }
3252 case JsonType::Bool: {
3253 if (this->value == "false") {
3254 data["value"] = bool{};
3255 } else {
3256 data["value"] = bool{ true };
3257 }
3258 break;
3259 }
3260 case JsonType::String: {
3261 data["value"] = this->value;
3262 break;
3263 }
3264 case JsonType::Null: {
3265 data["value"] = this->value;
3266 break;
3267 }
3268 }
3269 return data;
3270 }
3271
3272 ApplicationCommandOptionData::operator Serializer() {
3273 Serializer data{};
3274 if (this->type == ApplicationCommandOptionType::Channel) {
3275 data["channel_types"] = this->channelTypes;
3276 }
3278 data["required"] = this->required;
3279 }
3280 if (this->descriptionLocalizations.size() > 0) {
3281 data["description_localizations"] = this->descriptionLocalizations;
3282 }
3283 if (this->nameLocalizations.size() > 0) {
3284 data["name_localizations"] = this->nameLocalizations;
3285 }
3286 data["description"] = this->description;
3287 if (this->minValue != std::numeric_limits<int32_t>::max()) {
3288 data["min_value"] = this->minValue;
3289 }
3290 if (this->maxValue != std::numeric_limits<int32_t>::min()) {
3291 data["max_value"] = this->maxValue;
3292 }
3293 data["required"] = this->required;
3294 data["name"] = this->name;
3295 data["type"] = this->type;
3296 for (auto& value: this->choices) {
3297 data["choices"].emplaceBack(value.operator Serializer());
3298 }
3299 if (this->choices.size() == 0) {
3300 data["autocomplete"] = this->autocomplete;
3301 }
3302 for (auto& value: this->options) {
3303 data["options"].emplaceBack(value.operator Serializer());
3304 }
3305 return data;
3306 }
3307
3308 ThreadMemberDataVector::operator std::vector<ThreadMemberData>() {
3309 return this->threadMembers;
3310 }
3311
3312 YouTubeFormatVector::operator std::vector<YouTubeFormat>() {
3313 return this->formats;
3314 }
3315
3316 AudioFrameData& AudioFrameData::operator+=(std::basic_string_view<std::byte> other) noexcept {
3317 if (this->data.size() < this->currentSize + other.size()) {
3318 this->data.resize(other.size() + this->currentSize);
3319 }
3320 std::copy(other.data(), other.data() + other.size(), this->data.data() + this->currentSize);
3321 this->currentSize += other.size();
3322 this->type = AudioFrameType::RawPCM;
3323 return *this;
3324 }
3325
3326 AudioFrameData& AudioFrameData::operator+=(std::byte character) {
3327 this->currentSize++;
3328 this->data.push_back(character);
3329 return *this;
3330 }
3331
3332 bool operator==(const AudioFrameData& lhs, const AudioFrameData& rhs) {
3333 if (lhs.data != rhs.data) {
3334 return false;
3335 }
3336 if (lhs.currentSize != rhs.currentSize) {
3337 return false;
3338 }
3339 if (lhs.guildMemberId != rhs.guildMemberId) {
3340 return false;
3341 }
3342 if (lhs.type != rhs.type) {
3343 return false;
3344 }
3345 return true;
3346 }
3347
3348 AudioFrameData& AudioFrameData::operator=(AudioFrameData&& other) noexcept {
3349 if (this->data.size() < other.data.size() + this->currentSize) {
3350 this->data.resize(other.data.size() + this->currentSize);
3351 }
3352 std::copy(other.data.data(), other.data.data() + other.data.size(), this->data.data() + this->currentSize);
3353 this->currentSize += other.data.size();
3354 this->guildMemberId = std::move(other.guildMemberId);
3355 this->type = other.type;
3356 other.currentSize = 0;
3357 other.type = AudioFrameType::Unset;
3358 return *this;
3359 }
3360
3361 AudioFrameData::AudioFrameData(AudioFrameData&& other) noexcept {
3362 *this = std::move(other);
3363 }
3364
3365 void AudioFrameData::clearData() noexcept {
3367 this->guildMemberId = 0;
3368 this->currentSize = 0;
3369 this->data.clear();
3370 }
3371
3372 AllowedMentionsData::operator Serializer() {
3373 Serializer data{};
3374 for (auto& value: this->parse) {
3375 data["parse"].emplaceBack(value);
3376 }
3377 for (auto& value: this->roles) {
3378 data["roles"].emplaceBack(value);
3379 }
3380 for (auto& value: this->users) {
3381 data["users"].emplaceBack(value);
3382 }
3383 data["replied_user"] = this->repliedUser;
3384 return data;
3385 }
3386
3387 ActionRowData::operator Serializer() {
3388 Serializer data{};
3389 data["type"] = 1;
3390 if (this->components.size() > 0) {
3391 for (auto& valueNew: this->components) {
3392 if (valueNew.type == ComponentType::Button) {
3393 Serializer component{};
3394 if (valueNew.emoji.name != "") {
3395 component["emoji"]["animated"] = valueNew.emoji.animated;
3396 component["emoji"]["name"] = std::string{ valueNew.emoji.name };
3397 if (valueNew.emoji.id != 0) {
3398 component["emoji"]["id"] = valueNew.emoji.id;
3399 }
3400 }
3401 component["custom_id"] = valueNew.customId;
3402 component["disabled"] = valueNew.disabled;
3403 component["label"] = valueNew.label;
3404 component["style"] = valueNew.style;
3405 component["type"] = valueNew.type;
3406 component["url"] = valueNew.url;
3407 data["components"].emplaceBack(component);
3408 } else if (valueNew.type == ComponentType::String_Select || valueNew.type == ComponentType::User_Select ||
3409 valueNew.type == ComponentType::Role_Select || valueNew.type == ComponentType::Mentionable_Select ||
3410 valueNew.type == ComponentType::Channel_Select) {
3411 Serializer component{};
3412 for (auto& value01: valueNew.options) {
3413 Serializer option{};
3414 if (valueNew.emoji.name != "") {
3415 component["emoji"]["animated"] = valueNew.emoji.animated;
3416 component["emoji"]["name"] = std::string{ valueNew.emoji.name };
3417 if (valueNew.emoji.id != 0) {
3418 component["emoji"]["id"] = valueNew.emoji.id;
3419 }
3420 }
3421 option["description"] = value01.description;
3422 option["default"] = value01._default;
3423 option["label"] = value01.label;
3424 option["value"] = value01.value;
3425 component["options"].emplaceBack(option);
3426 };
3427 component["placeholder"] = valueNew.placeholder;
3428 component["max_values"] = valueNew.maxValues;
3429 component["min_values"] = valueNew.minValues;
3430 component["custom_id"] = valueNew.customId;
3431 component["disabled"] = valueNew.disabled;
3432 component["type"] = valueNew.type;
3433 data["components"].emplaceBack(component);
3434
3435 } else if (valueNew.type == ComponentType::Text_Input) {
3436 Serializer component{};
3437 component["placeholder"] = valueNew.placeholder;
3438 component["min_length"] = valueNew.minLength;
3439 component["max_length"] = valueNew.maxLength;
3440 component["custom_id"] = valueNew.customId;
3441 component["required"] = valueNew.required;
3442 component["style"] = valueNew.style;
3443 component["label"] = valueNew.label;
3444 component["value"] = valueNew.value;
3445 component["type"] = valueNew.type;
3446 data["components"].emplaceBack(component);
3447 }
3448 }
3449 }
3450 return data;
3451 }
3452
3453 MessageData& MessageData::operator=(const MessageData& other) {
3454 if (this != &other) {
3455 if (other.referencedMessage) {
3456 *this->referencedMessage = *other.referencedMessage;
3457 }
3458 this->messageReference = other.messageReference;
3459 this->mentionEveryone = other.mentionEveryone;
3460 this->mentionChannels = other.mentionChannels;
3461 this->editedTimestamp = other.editedTimestamp;
3462 this->applicationId = other.applicationId;
3463 this->stickerItems = other.stickerItems;
3464 this->mentionRoles = other.mentionRoles;
3465 this->application = other.application;
3466 this->interaction = other.interaction;
3467 this->attachments = other.attachments;
3468 this->components = other.components;
3469 this->timeStamp = other.timeStamp;
3470 this->channelId = other.channelId;
3471 this->webHookId = other.webHookId;
3472 this->reactions = other.reactions;
3473 this->activity = other.activity;
3474 this->mentions = other.mentions;
3475 this->stickers = other.stickers;
3476 this->content = other.content;
3477 this->guildId = other.guildId;
3478 this->member = other.member;
3479 this->thread = other.thread;
3480 this->pinned = other.pinned;
3481 this->author = other.author;
3482 this->embeds = other.embeds;
3483 this->nonce = other.nonce;
3484 this->flags = other.flags;
3485 this->type = other.type;
3486 this->tts = other.tts;
3487 this->id = other.id;
3488 }
3489 return *this;
3490 }
3491
3492 MessageData::MessageData(const MessageData& other) {
3493 *this = other;
3494 }
3495
3496 StickerPackDataVector::operator std::vector<StickerPackData>() {
3497 return this->stickerPacks;
3498 }
3499
3500 ConnectionDataVector::operator std::vector<ConnectionData>() {
3501 return this->connections;
3502 }
3503
3504 ConnectionDataVector::ConnectionDataVector(Value jsonData) noexcept {
3505 if (jsonData.type() != Jsonifier::JsonType::Null) {
3506 Jsonifier::Array arrayValue{};
3507 if (!getArray(arrayValue, jsonData)) {
3508 for (JsonifierResult<Value> value: arrayValue) {
3509 ConnectionData newData{ value.value() };
3510 this->connections.emplace_back(std::move(newData));
3511 }
3512 }
3513 }
3514 }
3515
3516 VoiceRegionDataVector::operator std::vector<VoiceRegionData>() {
3517 return this->voiceRegions;
3518 }
3519
3520 IntegrationDataVector::operator std::vector<IntegrationData>() {
3521 return this->integeregrations;
3522 }
3523
3524 InputEventData& InputEventData::operator=(InputEventData&& other) noexcept {
3525 if (this != &other) {
3526 *this->interactionData = std::move(*other.interactionData);
3527 this->responseType = other.responseType;
3528 }
3529 return *this;
3530 }
3531
3532 InputEventData::InputEventData(InputEventData&& other) noexcept {
3533 *this = std::move(other);
3534 }
3535
3536 InputEventData& InputEventData::operator=(const InputEventData& other) noexcept {
3537 if (this != &other) {
3538 *this->interactionData = *other.interactionData;
3539 this->responseType = other.responseType;
3540 }
3541 return *this;
3542 }
3543
3544 InputEventData::InputEventData(const InputEventData& other) noexcept {
3545 *this = other;
3546 }
3547
3548 InputEventData& InputEventData::operator=(const InteractionData& other) noexcept {
3549 *this->interactionData = other;
3550 return *this;
3551 }
3552
3553 InputEventData::InputEventData(const InteractionData& interactionData) noexcept {
3554 *this = interactionData;
3555 }
3556
3558 UserData returnData{};
3559 returnData.id = this->interactionData->user.id;
3560 returnData = Users::getCachedUser({ .userId = returnData.id });
3561 return this->interactionData->user;
3562 }
3563
3565 ChannelData returnData{};
3566 returnData.id = this->interactionData->channelId;
3567 returnData = Channels::getCachedChannel({ returnData.id });
3568 return returnData;
3569 }
3570
3572 GuildMemberData returnData{ this->interactionData->member };
3573 returnData = GuildMembers::getCachedGuildMember({ .guildMemberId = returnData.id, .guildId = this->interactionData->guildId });
3574 return returnData;
3575 }
3576
3578 GuildData returnData{};
3579 returnData.id = this->interactionData->guildId;
3580 returnData = Guilds::getCachedGuild({ .guildId = this->interactionData->guildId });
3581 return returnData;
3582 }
3583
3585 return *this->interactionData;
3586 }
3587
3589 return this->interactionData->message;
3590 }
3591
3592 RespondToInputEventData& RespondToInputEventData::operator=(const InteractionData& dataPackage) {
3593 this->applicationId = dataPackage.applicationId;
3594 this->interactionToken = dataPackage.token;
3595 this->messageId = dataPackage.message.id;
3596 this->channelId = dataPackage.channelId;
3597 this->interactionId = dataPackage.id;
3598 this->eventType = dataPackage.type;
3599 return *this;
3600 };
3601
3602 RespondToInputEventData::RespondToInputEventData(const InteractionData& dataPackage) {
3603 *this = dataPackage;
3604 }
3605
3606 RespondToInputEventData& RespondToInputEventData::operator=(const InputEventData& dataPackage) {
3607 this->applicationId = dataPackage.getInteractionData().applicationId;
3608 this->interactionToken = dataPackage.getInteractionData().token;
3609 this->interactionId = dataPackage.getInteractionData().id;
3610 this->channelId = dataPackage.getChannelData().id;
3611 this->messageId = dataPackage.getMessageData().id;
3612 return *this;
3613 }
3614
3615 RespondToInputEventData::RespondToInputEventData(const InputEventData& dataPackage) {
3616 *this = dataPackage;
3617 }
3618
3619 RespondToInputEventData& RespondToInputEventData::addButton(bool disabled, const std::string& customIdNew,
3620 const std::string& buttonLabel, ButtonStyle buttonStyle, const std::string& emojiName, Snowflake emojiId, const std::string& url) {
3621 if (this->components.size() == 0) {
3622 ActionRowData actionRowData;
3623 this->components.emplace_back(actionRowData);
3624 }
3625 if (this->components.size() < 5) {
3626 if (this->components[this->components.size() - 1].components.size() < 5) {
3627 ComponentData component;
3628 component.type = ComponentType::Button;
3629 component.emoji.name = emojiName;
3630 component.label = buttonLabel;
3631 component.style = static_cast<int32_t>(buttonStyle);
3632 component.customId = customIdNew;
3633 component.disabled = disabled;
3634 component.emoji.id = emojiId;
3635 component.url = url;
3636 this->components[this->components.size() - 1].components.emplace_back(component);
3637 } else if (this->components[this->components.size() - 1].components.size() == 5) {
3638 ActionRowData actionRowData;
3639 this->components.emplace_back(actionRowData);
3640 }
3641 }
3642 return *this;
3643 }
3644
3645 RespondToInputEventData& RespondToInputEventData::addSelectMenu(bool disabled, const std::string& customIdNew,
3646 std::vector<SelectOptionData> options, const std::string& placeholder, int32_t maxValues, int32_t minValues, SelectMenuType type,
3647 std::vector<ChannelType> channelTypes) {
3648 if (this->components.size() == 0) {
3649 ActionRowData actionRowData;
3650 this->components.emplace_back(actionRowData);
3651 }
3652 if (this->components.size() < 5) {
3653 if (this->components[this->components.size() - 1].components.size() < 5) {
3654 ComponentData componentData;
3655 componentData.type = static_cast<ComponentType>(type);
3656 componentData.channelTypes = channelTypes;
3657 componentData.placeholder = placeholder;
3658 componentData.customId = customIdNew;
3659 componentData.maxValues = maxValues;
3660 componentData.minValues = minValues;
3661 componentData.disabled = disabled;
3662 componentData.options = options;
3663 this->components[this->components.size() - 1].components.emplace_back(componentData);
3664 } else if (this->components[this->components.size() - 1].components.size() == 5) {
3665 ActionRowData actionRowData;
3666 this->components.emplace_back(actionRowData);
3667 }
3668 }
3669 return *this;
3670 }
3671
3672 RespondToInputEventData& RespondToInputEventData::addModal(const std::string& topTitleNew, const std::string& topCustomIdNew,
3673 const std::string& titleNew, const std::string& customIdNew, bool required, int32_t minLength, int32_t maxLength,
3674 TextInputStyle inputStyle, const std::string& label, const std::string& placeholder) {
3675 this->title = topTitleNew;
3676 this->customId = topCustomIdNew;
3677 if (this->components.size() == 0) {
3678 ActionRowData actionRowData;
3679 this->components.emplace_back(actionRowData);
3680 }
3681 if (this->components.size() < 5) {
3682 if (this->components[this->components.size() - 1].components.size() < 5) {
3683 ComponentData component{};
3684 component.type = ComponentType::Text_Input;
3685 component.customId = customIdNew;
3686 component.style = static_cast<int32_t>(inputStyle);
3687 component.title = titleNew;
3688 component.maxLength = maxLength;
3689 component.minLength = minLength;
3690 component.label = label;
3691 component.required = required;
3692 component.placeholder = placeholder;
3693 this->components[this->components.size() - 1].components.emplace_back(component);
3694 } else if (this->components[this->components.size() - 1].components.size() == 5) {
3695 ActionRowData actionRowData;
3696 this->components.emplace_back(actionRowData);
3697 }
3698 }
3699 return *this;
3700 }
3701
3703 this->files.emplace_back(theFile);
3704 return *this;
3705 }
3706
3708 this->allowedMentions = dataPackage;
3709 return *this;
3710 }
3711
3713 this->type = typeNew;
3714 return *this;
3715 }
3716
3718 this->components.emplace_back(dataPackage);
3719 return *this;
3720 }
3721
3723 this->embeds.emplace_back(dataPackage);
3724 return *this;
3725 }
3726
3728 this->content = dataPackage;
3729 return *this;
3730 }
3731
3733 this->tts = enabledTTs;
3734 return *this;
3735 }
3736
3738 std::unordered_map<std::string, std::string> theNameLocalizations) {
3740 choiceData.nameLocalizations = theNameLocalizations;
3741 choiceData.name = theName;
3742 switch (value.getType()) {
3743 case JsonType::String: {
3744 choiceData.type = JsonType::String;
3745 break;
3746 }
3747 case JsonType::Float: {
3748 choiceData.type = JsonType::Float;
3749 break;
3750 }
3751 case JsonType::Uint64: {
3752 choiceData.type = JsonType::Uint64;
3753 break;
3754 }
3755 case JsonType::Int64: {
3756 choiceData.type = JsonType::Int64;
3757 break;
3758 }
3759 case JsonType::Bool: {
3760 choiceData.type = JsonType::Bool;
3761 break;
3762 }
3763 }
3764 value.refreshString(JsonifierSerializeType::Json);
3765 choiceData.value = value.operator std::string();
3766 this->choices.emplace_back(choiceData);
3767 return *this;
3768 }
3769
3771 this->targetUserId = targetUserIdNew;
3772 return *this;
3773 }
3774
3775 MessageResponseBase& MessageResponseBase::addButton(bool disabled, const std::string& customIdNew, const std::string& buttonLabel,
3776 ButtonStyle buttonStyle, const std::string& emojiName, Snowflake emojiId, const std::string& url) {
3777 if (this->components.size() == 0) {
3778 ActionRowData actionRowData;
3779 this->components.emplace_back(actionRowData);
3780 }
3781 if (this->components.size() < 5) {
3782 if (this->components[this->components.size() - 1].components.size() < 5) {
3783 ComponentData component;
3784 component.type = ComponentType::Button;
3785 component.emoji.name = emojiName;
3786 component.label = buttonLabel;
3787 component.style = static_cast<int32_t>(buttonStyle);
3788 component.customId = customIdNew;
3789 component.disabled = disabled;
3790 component.emoji.id = emojiId;
3791 component.url = url;
3792 this->components[this->components.size() - 1].components.emplace_back(component);
3793 } else if (this->components[this->components.size() - 1].components.size() == 5) {
3794 ActionRowData actionRowData;
3795 this->components.emplace_back(actionRowData);
3796 }
3797 }
3798 return *this;
3799 }
3800
3801 MessageResponseBase& MessageResponseBase::addSelectMenu(bool disabled, const std::string& customIdNew,
3802 std::vector<SelectOptionData> options, const std::string& placeholder, int32_t maxValues, int32_t minValues, SelectMenuType type,
3803 std::vector<ChannelType> channelTypes) {
3804 if (this->components.size() == 0) {
3805 ActionRowData actionRowData;
3806 this->components.emplace_back(actionRowData);
3807 }
3808 if (this->components.size() < 5) {
3809 if (this->components[this->components.size() - 1].components.size() < 5) {
3810 ComponentData componentData;
3811 componentData.type = static_cast<ComponentType>(type);
3812 componentData.channelTypes = channelTypes;
3813 componentData.placeholder = placeholder;
3814 componentData.customId = customIdNew;
3815 componentData.maxValues = maxValues;
3816 componentData.minValues = minValues;
3817 componentData.disabled = disabled;
3818 componentData.options = options;
3819 this->components[this->components.size() - 1].components.emplace_back(componentData);
3820 } else if (this->components[this->components.size() - 1].components.size() == 5) {
3821 ActionRowData actionRowData;
3822 this->components.emplace_back(actionRowData);
3823 }
3824 }
3825 return *this;
3826 }
3827
3828 MessageResponseBase& MessageResponseBase::addModal(const std::string& topTitleNew, const std::string& topCustomIdNew,
3829 const std::string& titleNew, const std::string& customIdNew, bool required, int32_t minLength, int32_t maxLength,
3830 TextInputStyle inputStyle, const std::string& label, const std::string& placeholder) {
3831 this->title = topTitleNew;
3832 this->customId = topCustomIdNew;
3833 if (this->components.size() == 0) {
3834 ActionRowData actionRowData;
3835 this->components.emplace_back(actionRowData);
3836 }
3837 if (this->components.size() < 5) {
3838 if (this->components[this->components.size() - 1].components.size() < 5) {
3839 ComponentData component{};
3840 component.type = ComponentType::Text_Input;
3841 component.customId = customIdNew;
3842 component.style = static_cast<int32_t>(inputStyle);
3843 component.title = titleNew;
3844 component.maxLength = maxLength;
3845 component.minLength = minLength;
3846 component.label = label;
3847 component.required = required;
3848 component.placeholder = placeholder;
3849 this->components[this->components.size() - 1].components.emplace_back(component);
3850 } else if (this->components[this->components.size() - 1].components.size() == 5) {
3851 ActionRowData actionRowData;
3852 this->components.emplace_back(actionRowData);
3853 }
3854 }
3855 return *this;
3856 }
3857
3859 this->files.emplace_back(theFile);
3860 return *this;
3861 }
3862
3864 this->allowedMentions = dataPackage;
3865 return *this;
3866 }
3867
3869 this->components.emplace_back(dataPackage);
3870 return *this;
3871 }
3872
3874 this->embeds.emplace_back(dataPackage);
3875 return *this;
3876 }
3877
3878 MessageResponseBase& MessageResponseBase::addContent(const std::string& dataPackage) {
3879 this->content = dataPackage;
3880 return *this;
3881 }
3882
3884 this->tts = enabledTTs;
3885 return *this;
3886 }
3887
3888 InteractionResponseData& InteractionResponseData::operator=(const RespondToInputEventData& other) {
3889 this->data.allowedMentions = other.allowedMentions;
3890 this->data.components = other.components;
3891 this->data.customId = other.customId;
3892 this->data.choices = other.choices;
3893 this->data.content = other.content;
3894 this->data.embeds = other.embeds;
3895 this->data.title = other.title;
3896 this->data.files = other.files;
3897 this->data.flags = other.flags;
3898 this->data.tts = other.tts;
3899 return *this;
3900 }
3901
3902 InteractionResponseData::InteractionResponseData(const RespondToInputEventData& other) {
3903 *this = other;
3904 }
3905
3906 InteractionResponseData::operator Serializer() {
3907 Serializer data{};
3908 data["type"] = this->type;
3909 if (this->data.attachments.size() > 0) {
3910 for (auto& value: this->data.attachments) {
3911 data["data"]["attachments"].emplaceBack(value);
3912 }
3913 }
3914 if (this->data.components.size() == 0) {
3915 data["data"]["components"].emplaceBack(ActionRowData{});
3916 data["data"]["components"].getValue<Serializer::ArrayType>().clear();
3917 } else {
3918 for (auto& value: this->data.components) {
3919 data["data"]["components"].emplaceBack(value);
3920 }
3921 }
3922 if (this->data.allowedMentions.parse.size() > 0 || this->data.allowedMentions.roles.size() > 0 ||
3923 this->data.allowedMentions.users.size() > 0) {
3924 data["data"]["allowed_mentions"] = this->data.allowedMentions.operator Serializer();
3925 }
3926 if (this->data.choices.size() > 0) {
3927 for (auto& value: this->data.choices) {
3928 Serializer valueNew{};
3929 valueNew["name"] = value.name;
3930 valueNew["name_localizations"] = value.nameLocalizations;
3931 valueNew["value"] = value.value;
3932 data["data"]["choices"].emplaceBack(value);
3933 }
3934 }
3935 if (this->data.embeds.size() == 0) {
3936 data["data"]["embeds"].emplaceBack(EmbedData{});
3937 data["data"]["embeds"].getValue<Serializer::ArrayType>().clear();
3938 } else {
3939 for (auto& value: this->data.embeds) {
3940 data["data"]["embeds"].emplaceBack(value);
3941 }
3942 }
3943 if (this->data.customId != "") {
3944 data["data"]["custom_id"] = this->data.customId;
3945 }
3946 if (this->data.content != "") {
3947 data["data"]["content"] = this->data.content;
3948 }
3949 if (this->data.title != "") {
3950 data["data"]["title"] = this->data.title;
3951 }
3952 data["data"]["flags"] = this->data.flags;
3953 data["data"]["tts"] = this->data.tts;
3954 return data;
3955 }
3956
3957 void parseCommandDataOption(std::unordered_map<std::string, JsonStringValue>& values, ApplicationCommandInteractionDataOption& data) {
3958 JsonStringValue valueNew{};
3959 valueNew.type = data.value.type;
3960 valueNew.value = data.value.value;
3961 values.insert_or_assign(data.name, valueNew);
3962 for (auto& value: data.options) {
3963 parseCommandDataOption(values, value);
3964 }
3965 }
3966
3967 CommandData& CommandData::operator=(const CommandData& other) noexcept {
3968 this->subCommandGroupName = other.subCommandGroupName;
3969 this->subCommandName = other.subCommandName;
3970 this->commandName = other.commandName;
3971 this->optionsArgs = other.optionsArgs;
3972 this->eventData = other.eventData;
3973 return *this;
3974 }
3975
3976 CommandData::CommandData(const CommandData& other) noexcept {
3977 *this = other;
3978 }
3979
3980 CommandData::CommandData(InputEventData inputEventData) {
3981 if (inputEventData.interactionData->data.applicationCommandData.name != "") {
3982 this->commandName = inputEventData.interactionData->data.applicationCommandData.name;
3983 }
3984 if (inputEventData.interactionData->data.messageInteractionData.targetId != 0) {
3985 this->optionsArgs.values.emplace("target_id",
3986 JsonStringValue{ .value = inputEventData.interactionData->data.messageInteractionData.targetId, .type = JsonType::String });
3987 } else if (inputEventData.interactionData->data.userInteractionData.targetId != 0) {
3988 this->optionsArgs.values.emplace("target_id",
3989 JsonStringValue{ .value = inputEventData.interactionData->data.userInteractionData.targetId, .type = JsonType::String });
3990 }
3991 this->eventData = inputEventData;
3992 for (auto& value: this->eventData.interactionData->data.applicationCommandData.options) {
3993 JsonStringValue valueNew{};
3994 valueNew.type = value.value.type;
3995 valueNew.value = value.value.value;
3996 this->optionsArgs.values.insert_or_assign(value.name, valueNew);
3997 parseCommandDataOption(this->optionsArgs.values, value);
3998 }
3999 for (auto& value: inputEventData.interactionData->data.applicationCommandData.options) {
4001 this->subCommandName = value.name;
4002 }
4004 this->subCommandGroupName = value.name;
4005 }
4006 }
4007 }
4008
4010 return *this->eventData.interactionData;
4011 }
4012
4014 return this->eventData.getGuildMemberData();
4015 }
4016
4018 return this->eventData.getChannelData();
4019 }
4020
4022 return this->eventData.getMessageData();
4023 }
4024
4026 return this->eventData.getGuildData();
4027 }
4028
4030 return this->eventData.getUserData();
4031 }
4032
4033 std::string CommandData::getCommandName() noexcept {
4034 return this->commandName;
4035 }
4036
4037 std::string CommandData::getSubCommandName() noexcept {
4038 return this->subCommandName;
4039 }
4040
4042 return this->subCommandGroupName;
4043 }
4044
4045 JsonifierValue CommandData::getCommandArguments() noexcept {
4046 return this->optionsArgs;
4047 }
4048
4050 return this->eventData;
4051 }
4052
4053 BaseFunctionArguments::BaseFunctionArguments(CommandData commanddataNew, DiscordCoreClient* discordCoreClientNew)
4054 : CommandData(commanddataNew) {
4055 this->discordCoreClient = discordCoreClientNew;
4056 }
4057
4058 MoveThroughMessagePagesData moveThroughMessagePages(const std::string& userID, InputEventData originalEvent, uint32_t currentPageIndex,
4059 const std::vector<EmbedData>& messageEmbeds, bool deleteAfter, uint32_t waitForMaxMs, bool returnResult) {
4060 MoveThroughMessagePagesData returnData{};
4061 uint32_t newCurrentPageIndex = currentPageIndex;
4062 StopWatch stopWatch{ Milliseconds{ waitForMaxMs } };
4063 auto createResponseData = std::make_unique<CreateInteractionResponseData>(originalEvent);
4064 auto interactionResponse = std::make_unique<RespondToInputEventData>(originalEvent);
4065 auto embedData = std::make_unique<EmbedData>();
4066 embedData->setColor("FEFEFE");
4067 embedData->setTitle("__**Permissions Issue:**__");
4068 embedData->setTimeStamp(getTimeAndDate());
4069 embedData->setDescription("Sorry, but that button can only be pressed by <@" + userID + ">!");
4070 createResponseData->addMessageEmbed(*embedData);
4071 createResponseData->setResponseType(InteractionCallbackType::Channel_Message_With_Source);
4072 if (messageEmbeds.size() > 0) {
4073 interactionResponse->addMessageEmbed(messageEmbeds[currentPageIndex]);
4074 }
4075 if (returnResult) {
4076 interactionResponse->addButton(false, "select", "Select", ButtonStyle::Success, "✅");
4077 }
4078 interactionResponse->addButton(false, "backwards", "Prev Page", ButtonStyle::Primary, "◀️");
4079 interactionResponse->addButton(false, "forwards", "Next Page", ButtonStyle::Primary, "▶️");
4080 interactionResponse->addButton(false, "exit", "Exit", ButtonStyle::Danger, "❌");
4081 interactionResponse->setResponseType(InputEventResponseType::Edit_Interaction_Response);
4082 originalEvent = InputEvents::respondToInputEventAsync(*interactionResponse).get();
4083 while (!stopWatch.hasTimePassed()) {
4084 std::this_thread::sleep_for(1ms);
4085 std::unique_ptr<ButtonCollector> button{ std::make_unique<ButtonCollector>(originalEvent) };
4086 std::vector<ButtonResponseData> buttonIntData{
4087 button->collectButtonData(false, waitForMaxMs, 1, *createResponseData, Snowflake{ stoull(userID) }).get()
4088 };
4089 std::unique_ptr<InteractionData> interactionData{ std::make_unique<InteractionData>() };
4090 if (buttonIntData.size() == 0 || buttonIntData.at(0).buttonId == "empty" || buttonIntData.at(0).buttonId == "exit") {
4091 std::unique_ptr<RespondToInputEventData> dataPackage02{ std::make_unique<RespondToInputEventData>(originalEvent) };
4092 if (buttonIntData.at(0).buttonId == "empty") {
4093 *dataPackage02 = originalEvent;
4094 } else {
4095 interactionData = std::make_unique<InteractionData>(buttonIntData.at(0));
4096 *dataPackage02 = RespondToInputEventData{ *interactionData };
4097 }
4098
4099 dataPackage02->addMessageEmbed(messageEmbeds[newCurrentPageIndex]);
4100 for (size_t x = 0; x < originalEvent.getMessageData().components.size(); ++x) {
4101 ActionRowData actionRow{};
4102 for (size_t y = 0; y < originalEvent.getMessageData().components[x].components.size(); ++y) {
4103 auto component = originalEvent.getMessageData().components[x].components[y];
4104 component.disabled = true;
4105 actionRow.components.push_back(component);
4106 }
4107 dataPackage02->addComponentRow(actionRow);
4108 }
4109 if (deleteAfter == true) {
4110 InputEventData dataPackage03{ originalEvent };
4112 } else {
4113 dataPackage02->setResponseType(InputEventResponseType::Edit_Interaction_Response);
4114 InputEvents::respondToInputEventAsync(*dataPackage02).get();
4115 }
4116 MoveThroughMessagePagesData dataPackage03{};
4117 dataPackage03.inputEventData = originalEvent;
4118 dataPackage03.buttonId = "exit";
4119 return dataPackage03;
4120 } else if (buttonIntData.at(0).buttonId == "forwards" || buttonIntData.at(0).buttonId == "backwards") {
4121 if (buttonIntData.at(0).buttonId == "forwards" && (newCurrentPageIndex == (messageEmbeds.size() - 1))) {
4122 newCurrentPageIndex = 0;
4123 } else if (buttonIntData.at(0).buttonId == "forwards" && (newCurrentPageIndex < messageEmbeds.size())) {
4124 ++newCurrentPageIndex;
4125 } else if (buttonIntData.at(0).buttonId == "backwards" && (newCurrentPageIndex > 0)) {
4126 --newCurrentPageIndex;
4127 } else if (buttonIntData.at(0).buttonId == "backwards" && (newCurrentPageIndex == 0)) {
4128 newCurrentPageIndex = static_cast<uint32_t>(messageEmbeds.size()) - 1;
4129 }
4130 interactionData = std::make_unique<InteractionData>(buttonIntData.at(0));
4131 auto dataPackage = RespondToInputEventData{ *interactionData };
4132 dataPackage.setResponseType(InputEventResponseType::Edit_Interaction_Response);
4133 for (size_t x = 0; x < originalEvent.getMessageData().components.size(); ++x) {
4134 ActionRowData actionRow{};
4135 for (size_t y = 0; y < originalEvent.getMessageData().components[x].components.size(); ++y) {
4136 auto component = originalEvent.getMessageData().components[x].components[y];
4137 component.disabled = false;
4138 actionRow.components.push_back(component);
4139 }
4140 dataPackage.addComponentRow(actionRow);
4141 }
4142 dataPackage.addMessageEmbed(messageEmbeds[newCurrentPageIndex]);
4143 InputEvents::respondToInputEventAsync(dataPackage).get();
4144 } else if (buttonIntData.at(0).buttonId == "select") {
4145 if (deleteAfter == true) {
4146 InputEventData dataPackage03{ originalEvent };
4148 } else {
4149 std::unique_ptr<InteractionData> interactionData = std::make_unique<InteractionData>(buttonIntData.at(0));
4150 auto dataPackage = RespondToInputEventData{ *interactionData };
4151 dataPackage.setResponseType(InputEventResponseType::Edit_Interaction_Response);
4152 dataPackage.addMessageEmbed(messageEmbeds[newCurrentPageIndex]);
4153 for (size_t x = 0; x < originalEvent.getMessageData().components.size(); ++x) {
4154 ActionRowData actionRow{};
4155 for (size_t y = 0; y < originalEvent.getMessageData().components[x].components.size(); ++y) {
4156 auto component = originalEvent.getMessageData().components[x].components[y];
4157 component.disabled = true;
4158 actionRow.components.push_back(component);
4159 }
4160 dataPackage.addComponentRow(actionRow);
4161 }
4162 originalEvent = InputEvents::respondToInputEventAsync(dataPackage).get();
4163 }
4164 returnData.currentPageIndex = newCurrentPageIndex;
4165 returnData.inputEventData = originalEvent;
4166 returnData.buttonId = buttonIntData.at(0).buttonId;
4167 return returnData;
4168 }
4169 };
4170 return returnData;
4171 };
4172};
TimeFormat
Time formatting methods.
Definition: Utilities.hpp:877
@ LongDateTime
"Tuesday, 20 April 2021 16:20" - Long Date/Time
ButtonStyle
Button styles.
GuildScheduledEventStatus
GuildScheduledEventStatus.
TriggerType
Trigger types for auto-moderation.
AuditLogEvent
Audit log events.
StickerFormatType
Sticker format types.
StageInstancePrivacyLevel
Stage instance privacy levels.
ApplicationCommandOptionType
Application command-option types.
GuildScheduledEventPrivacyLevel
Guild scheduled event privacy levels.
ComponentType
Component types.
SortOrderTypes
The sorting order, for Guild Forum channels.
InteractionType
Interaction types.
ChannelType
Channel types.
DiscordCoreAPI_Dll std::string getTimeAndDate()
Acquires a timeStamp with the current time and date - suitable for use in message-embeds.
Definition: Utilities.cpp:983
ApplicationCommandPermissionType
Application command permission-types.
PermissionOverwritesType
PermissionTypes overwrites types.
ActionType
Action types for auto-moderation.
ApplicationFlags
Application flags, for the ApplicationData structure.
GuildScheduledEventEntityType
Guild scheduled event entity types.
InputEventResponseType
Input event response types.
Definition: Utilities.hpp:455
EventType
Event types for auto-moderation.
ApplicationCommandType
Application command types.
ConnectionVisibilityTypes
Connection visibility types.
WebHookType
WebHook types.
MessageType
Message types.
MessageActivityType
Message activity types.
StickerType
Sticker types.
KeywordPresetType
Keyword preset types for auto-moderation.
StickerItemType
Sticker item types.
TextInputStyle
Text input style for modals.
@ Verified
Is it verified?
@ System
Is it a system integration?
@ MFAEnabled
Is MFA enabled?
@ Channel_Message_With_Source
Respond to an interaction with a message.
@ Role_Select
Select menu for roles.
@ Mentionable_Select
Select menu for mentionables (users and roles).
@ Channel_Select
Select menu for channels.
@ String_Select
Select menu for picking from defined text options.
@ User_Select
Select menu for users.
@ Text_Input
Text input object.
@ WidgetEnabled
Widget enabled.
@ Edit_Interaction_Response
Interaction response edit.
@ invisible
Invisible and shown as offline.
The main namespace for this library.
static ChannelData getCachedChannel(GetChannelData dataPackage)
Collects a Channel from the library's cache.
DiscordCoreClient - The main class for this library.
static BotUser getBotUser()
For collecting a copy of the current bot's User.
std::string getCreatedAtTimestamp(TimeFormat timeFormat)
Converts the snowflake-id into a time and date stamp.
std::string botId
What is the bot id?
std::string integrationId
What is the integration id?
Data structure representing a single User.
StringWrapper userName
The user's userName, not unique across the platform identify.
IconHash avatar
The user's avatar hash.
StringWrapper discriminator
The user's 4-digit discord-tag identify.
UserFlags flags
The public flags on a user' s account.
std::string proxyIconUrl
Proxy icon url.
std::string proxyIconUrl
Proxy icon url.
std::string value
The text on the field.
bool Inline
Is the field inline with the rest of them?
std::string name
The title of the field.
std::string url
Url for the embed.
EmbedData & setFooter(const std::string &footerText, const std::string &footerIconUrlText="")
Sets the footer's values for the embed.
EmbedData & setTitle(const std::string &titleNew)
Sets the title of the embed.
EmbedData & setImage(const std::string &imageUrl)
Sets the image of the embed.
EmbedProviderData provider
Embed provider data.
EmbedData & addField(const std::string &name, const std::string &value, bool Inline=true)
Adds a field to the embed.
std::string type
Type of the embed.
EmbedAuthorData author
Embed author data.
std::string description
Description of the embed.
EmbedThumbnailData thumbnail
Embed thumbnail data.
EmbedImageData image
Embed image data.
ColorValue hexColorValue
Hex color value of the embed.
std::string title
Title of the embed.
EmbedVideoData video
Embed video data.
EmbedData & setDescription(const std::string &descriptionNew)
Sets the description (the main contents) of the embed.
EmbedData & setColor(const std::string &hexColorValueNew)
Sets the color of the embed, by applying a hex-color value.
std::string timeStamp
Timestamp to be placed on the embed.
EmbedData & setThumbnail(const std::string &thumbnailUrl)
Sets the thumbnail of the embed.
EmbedData & setAuthor(const std::string &authorName, const std::string &authorAvatarUrl="")
Sets the author's name and avatar for the embed.
EmbedData & setTimeStamp(const std::string &timeStamp)
Sets the timeStamp on the embed.
std::vector< EmbedFieldData > fields
Array of embed fields.
EmbedFooterData footer
Embed footer data.
Snowflake guildId
Id of the Guild that the referenced Message was sent in.
Snowflake channelId
Id of the Channel that the referenced Message was sent in.
Snowflake messageId
Id of the Message to reference.
bool failIfNotExists
Fail if the Message doesn't exist?
Data representing a file to be sent via multipart-form data.
TimeStamp archiveTimestamp
(Where applicable) the time at which this Thread was archived.
int32_t autoArchiveDuration
How int64_t before archiving this Thread.
bool archived
Whether or not this Thread is currently archived.
bool invitable
The id of the individual who archived this Thread.
bool locked
Whether or not this Thread is currently locked.
TimeStamp joinTimestamp
The time at which the member joined this Thread.
Snowflake userId
The User id this voice state is for.
Snowflake channelId
The Channel id this User is connected to.
Snowflake guildId
The Guild id this voice state is for.
std::string sessionId
The session id for this voice state.
TimeStamp requestToSpeakTimestamp
The time at which the User requested to speak.
bool selfDeaf
Whether this User is locally deafened.
bool mute
Whether this User is muted by the server.
bool deaf
Whether this User is deafened by the server.
bool selfStream
Whether this User is streaming using "Go Live".
bool suppress
Whether this User is muted by the current User.
bool selfMute
Whether this User is locally muted.
bool selfVideo
Whether this User's camera is enabled.
Snowflake guildId
The id of the Guild that this Role is from.
Permissions permissions
The Role's base Guild Permissions.
StringWrapper name
The Role's name.
int16_t position
Its position amongst the rest of the Guild's roles.
ColorValue color
The Role's color.
StringWrapper unicodeEmoji
Emoji representing the Role.
RoleFlags flags
Role flags.
UserData user
User that created this emoji.
bool requireColons
Require colons to render it?
bool available
Is it available to be used?
std::vector< RoleData > roles
Roles that are allowed to use this emoji.
StringWrapper name
What is its name?
PresenceUpdateFlags theStatus
Current client status.
Snowflake guildId
Guild id for the current presence.
Data structure representing a single GuildMember.
GuildMemberFlags flags
GuildMember flags.
std::vector< Snowflake > roles
The Guild roles that they have.
IconHash avatar
This GuildMember's Guild Avatar.
TimeStamp joinedAt
When they joined the Guild.
StringWrapper nick
Their nick/display name.
Permissions permissions
Their base-level Permissions in the Guild.
Snowflake guildId
The current Guild's id.
uint64_t deny
Collection of Permissions to deny.
uint64_t allow
Collection of Permissions to allow.
PermissionOverwritesType type
Role or User type.
Data structure representing a single Channel.
std::vector< OverWriteData > permissionOverwrites
Permission overwrites.
uint16_t position
The position of the Channel, in the Guild's Channel list.
Snowflake ownerId
Id of the Channel's owner.
SortOrderTypes defaultSortOrder
Default sorting order for a forum thread.
Snowflake parentId
Id of the Channel's parent Channel/category.
ChannelFlags flags
Flags combined as a bitmask.
ChannelType type
The type of the Channel.
uint32_t memberCount
Count of members active in the Channel.
Snowflake guildId
Id of the Channel's Guild, if applicable.
StringWrapper name
Name of the Channel.
int64_t durationSeconds
Timeout duration in seconds.
Snowflake channelId
Channel to which user content should be logged.
int32_t mentionTotalLimit
Total number of unique role and user mentions allowed per message (Maximum of 50).
std::vector< std::string > allowList
Substrings which will be exempt from triggering the preset trigger type.
std::vector< std::string > keywordFilter
Substrings which will be searched for in content.keyword_filter array of strings.
std::vector< KeywordPresetType > presets
The internally pre-defined wordsets which will be searched for in content.
ActionType type
The type of action.
ActionMetaData metadata
Additional metadata needed during execution for this specific action type.
std::vector< Snowflake > exemptChannels
The channel ids that should not be affected by the rule(Maximum of 50).
EventType eventType
The rule event type.
TriggerMetaData triggerMetaData
The rule trigger metadata actions array of action objects the.
TriggerType triggerType
The rule trigger type.
std::vector< Snowflake > exemptRoles
The role ids that should not be affected by the rule(Maximum of 20).
Snowflake creatorId
The user which first created this rule.
std::vector< ActionData > actions
Actions which will execute when the rule is triggered.
Snowflake guildId
The guild which this rule belongs to.
bool enabled
Whether the rule is enabled.
ApplicationCommandPermissionType type
The type of PermissionTypes.
bool permission
Whether the PermissionTypes is active or not.
std::vector< ApplicationCommandPermissionData > permissions
The Permissions.
bool me
Whether or not I (The bot) placed it.
Snowflake messageId
The id of the Message upon which it was placed.
Snowflake guildId
The id of the Guild where it was placed.
EmojiData emoji
The emoji that was placed as a reaction.
Snowflake channelId
The id of the Channel where it was placed.
GuildMemberData member
The GuildMember who placed the reaction.
Snowflake userId
The id of the User who placed the reaction.
int32_t count
The number of times this particular emoji was placed as a reaction to the given Message.
bool optimal
True for a single server that is closest to the current User's client.
bool custom
Whether this is a custom voice region(used for events / etc).
bool deprecated
Whether this is a deprecated voice region(avoid switching to these).
std::string name
Name of the region.
MessageActivityType type
Message activity type.
std::string reason
Reason for the ban.
UserData user
User that was banned.
std::vector< Permissions > permissions
Permissions for the team.
UserData user
User data of the current User.
Snowflake teamId
Id of the current team.
std::vector< TeamMembersObjectData > members
Array of team members object data.
std::string icon
Icon for the team.
Snowflake ownerUserId
User id of the team owner.
std::vector< std::string > scopes
The scopes to add the application to the server with.
Permissions permissions
The permissions to request for the bot role.
std::string coverImage
The cover image.
InstallParamsData params
Settings for the application's default in-app authorization link, if enabled.
UserData owner
Application's owner.
std::vector< std::string > tags
Up to 5 tags describing the content and functionality of the application install_params.
TeamObjectData team
Team object data.
std::string icon
Application's icon.
std::string termsOfServiceUrl
Terms of service Url.
std::string privacyPolicyUrl
Privacy policy Url.
std::string verifyKey
The verification key.
bool botRequireCodeGrant
Does the bot require a code grant?
std::string primarySkuId
Primary SKU Id.
ApplicationFlags flags
Application flags.
std::string name
Application's name.
std::string description
Description of the application.
std::vector< std::string > rpcOrigins
Array of RPC origin strings.
std::string summary
Summary of the application.
std::string expires
When the access token expires.
std::vector< std::string > scopes
Array of strings - the scopes the User has authorized the application for.
AuthorizationInfoData() noexcept=default
The User who has authorized, if the User has authorized with the identify scope.
ApplicationData application
Partial application object the current application.
std::string name
Name of the account.
Snowflake channelId
The widget Channel id.
bool enabled
Whether the widget is enabled.
UserData user
User data for the integration.
int32_t subscriberCount
Number of current subscribers.
TimeStamp syncedAt
Time it was last synced at.
int32_t expireBehavior
What to do upon expiry.
ApplicationData application
Application data.
std::string type
Type of integration.
int32_t expireGracePeriod
How int64_t before the integration expires.
bool enableEmoticons
Emoticons enabled?
std::string name
Name of the integration.
std::string membersRemoved
Number of members that were removed upon a prune.
std::string deleteMemberDays
Number of days for which the member's Messages were deleted.
std::string key
The key of the audit log change.
OptionalAuditEntryInfoData options
Audit log entry info data.
Snowflake targetId
Id of the target User.
TimeStamp createdTimeStamp
Time at which this entry was created.
Snowflake userId
Id of the executing User.
AuditLogEvent actionType
Audit log action type.
std::string reason
The reason that was entered for the given change.
std::vector< AuditLogChangeData > changes
Array of audit log change data.
std::string description
Description of the welcome Channel.
Snowflake emojiId
Emoji id for the Channel.
Snowflake channelId
Id of the welcome Channel.
std::string emojiName
Emoji name for the Channel.
std::vector< WelcomeScreenChannelData > welcomeChannels
Welcome screen Channel data.
std::string description
Description of the welcome screen.
Snowflake guildId
The Guild id for which the Channel exists in.
bool discoverableDisabled
Is it discoverable?
std::string topic
The topic of the StageInstance.
StageInstancePrivacyLevel privacyLevel
Privacy level of the Channel.
Snowflake channelId
The Channel's id.
int32_t sortValue
Where in the stack of stickers it resides.
UserData user
The User that uploaded the Guild Sticker.
std::string packId
Pack id of the Sticker.
StickerType type
The type of Sticker.
std::string asset
Asset value for the Sticker.
StickerFormatType formatType
Format type.
Snowflake guildId
The Guild id for which the Sticker exists in.
std::string name
The Sticker's name.
std::string description
Description of the Sticker.
StickerFlags flags
Sticker flags.
Data structure representing a single Guild.
std::vector< Snowflake > stickers
Array of Guild channels.
StringWrapper name
The Guild's name.
std::vector< Snowflake > members
Array of GuildMembers.
std::vector< Snowflake > emoji
Array of Guild channels.
std::vector< PresenceUpdateData > presences
Presence states for each of the GuildMembers..
TimeStamp joinedAt
When the bot joined this Guild.
std::vector< Snowflake > guildScheduledEvents
Array of Guild channels.
IconHash icon
Url to the Guild's icon.
DiscordCoreClient * discordCoreClient
A pointer to the DiscordCoreClient.
std::vector< Snowflake > threads
Array of Guild channels.
uint32_t memberCount
Member count.
VoiceConnection * connectToVoice(const Snowflake guildMemberId, const Snowflake channelId=Snowflake{}, bool selfDeaf=false, bool selfMute=false, StreamInfo streamInfo=StreamInfo{})
For connecting to an individual voice channel.
Snowflake ownerId
User id of the Guild's owner.
std::vector< Snowflake > stageInstances
Array of Guild channels.
std::vector< Snowflake > channels
Array of Guild channels.
VoiceConnection * voiceConnectionPtr
A pointer to the VoiceConnection, if present.
GuildFlags flags
Guild flags.
std::vector< Snowflake > roles
Array of Guild roles.
Snowflake guildId
The Guild id which the scheduled event belongs to.
Snowflake channelId
The Channel id in which the scheduled event will be hosted, or null if scheduled entity type is Exter...
Snowflake creatorId
The id of the User that created the scheduled event *.
std::string description
The description of the scheduled event(1 - 1000 characters.
std::string scheduledEndTime
The time the scheduled event will end, required if entity_type is External.
Snowflake entityId
The id of an entity associated with a Guild scheduled event.
uint32_t userCount
The number of users subscribed to the scheduled event.
GuildScheduledEventPrivacyLevel privacyLevel
The privacy level of the scheduled event.
GuildScheduledEventEntityType entityType
The type of the scheduled event.
UserData creator
The User that created the scheduled event.
GuildScheduledEventStatus status
The status of the scheduled event.
std::string scheduledStartTime
The time the scheduled event will start.
std::string name
The name of the scheduled event(1 - 100 characters).
GuildScheduledEventMetadata entityMetadata
Additional metadata for the Guild scheduled event.
Snowflake guildScheduledEventId
The scheduled event id which the User subscribed to/.
UserData user
User which subscribed to an event.
GuildMemberData member
Guild member data for this User for the Guild which this event belongs to, if any.
GuildScheduledEventData guildScheduledEvent
Scheduled Guild event.
int32_t maxUses
Max number of uses.
int32_t maxAge
Maximum age of the invite.
StageInstanceData stageInstance
Stage instance data.
int32_t approximatePresenceCount
Approximate presence count.
ApplicationData targetApplication
Application data.
UserData inviter
The User who created the invite.
int32_t approximateMemberCount
Approximate member count.
GuildData guild
Guild data of the Channel that the invite is for.
TimeStamp expiresAt
When the invite expires.
Snowflake guildId
The Guild this invite is for.
UserData targetUser
Target User of the invite.
TimeStamp createdAt
Time it was created at.
std::string code
Unique invite code.
ChannelData channel
Channel data of the Channel that the invite is for.
int32_t uses
The current number of uses.
UserData creator
The User who created the template.
std::string description
The description for the template.
std::string code
The template code(unique ID).
std::string updatedAt
When this template was last synced to the source Guild.
GuildData serializedSourceGuild
The Guild snapshot this template contains.
uint32_t usageCount
Number of times this template has been used.
std::string createdAt
When this template was created.
std::string creatorId
The ID of the User who created the template.
bool isDirty
Whether the template has unsynced changes.
std::string sourceGuildId
The ID of the Guild this template is based on.
std::string name
Name of the WebHook.
WebHookType type
Type of WebHook.
GuildData sourceGuild
Source Guild id.
std::string url
Url of the WebHook.
Snowflake channelId
Channel id for which the WebHook was issued.
Snowflake applicationId
Application id.
std::string avatar
Avatar of the WebHook.
std::string token
Token of the WebHook.
Snowflake guildId
Guild id for which the WebHook was issued.
UserData user
User which create the WebHook.
ChannelData sourceChannel
Channel for which th WebHook was issued.
std::vector< IntegrationData > integrations
Array of partial integration objects.
std::vector< UserData > users
Array of user objects.
std::vector< AuditLogEntryData > auditLogEntries
Array of audit log entry objects.
std::vector< GuildScheduledEventData > guildScheduledEvents
Array of guild scheduled event objects.
std::vector< ChannelData > threads
Array of thread-specific channel objects.
std::vector< WebHookData > webhooks
Array of webhook objects.
std::vector< AutoModerationRuleData > autoModerationRules
List of auto moderation rules referenced in the audit log.
Data structure representing an ApplicationCommand's option choice.
std::unordered_map< std::string, std::string > nameLocalizations
Dictionary with keys in available locales Localization dictionary for the name field.
std::string name
The name of the current choice.
std::string name
Name of the current ApplicationCommand option.
std::unordered_map< std::string, std::string > nameLocalizations
Dictionary for the name localizations field.
int32_t maxValue
If the option is an INTEGER or NUMBER type, the maximum value permitted.
std::string description
A description of the current ApplicationCommand option.
bool autocomplete
If autocomplete interactions are enabled for this STRING, INTEGER, or NUMBER type option.
std::vector< ChannelType > channelTypes
Set when the ApplicationCommand option type is set to Channel.
int32_t minValue
If the option is an INTEGER or NUMBER type, the minimum value permitted.
bool required
If the parameter is required or optional– default false.
ApplicationCommandOptionType type
The type of command option.
std::vector< ApplicationCommandOptionData > options
A vector of possible options for the current ApplicationCommand option.
std::vector< ApplicationCommandOptionChoiceData > choices
A vector of possible choices for the current ApplicationCommand option.
std::unordered_map< std::string, std::string > descriptionLocalizations
Dictionary for the description localizations field.
ComponentType componentType
The type of component.
std::string customId
The custom id of the Interaction entity.
std::vector< std::string > values
The values of the components.
std::string customId
The custom id of the Interaction entity.
std::string customIdSmall
The custom id of a particular modal input.
std::string value
The input value of the modal.
Allowable mentions for a Message.
std::vector< std::string > users
Array of user_ids to mention (Max size of 100)
bool repliedUser
For replies, whether to mention the author of the Message being replied to (default false).
std::vector< std::string > parse
A vector of allowed mention types to parse from the content.
std::vector< std::string > roles
Array of role_ids to mention (Max size of 100)
std::string description
Description of the select-menu-option.
std::string value
A value for identifying the option.
EmojiData emoji
An optional emoji to put on it.
bool _default
Is it the default option?
std::string label
A visible label for the select-menu-option.
Represents a single Message-component.
int32_t style
One of ButtonStyle, or TextInputStyle.
bool required
Whether this component is required to be filled.
std::string label
The label for this component.
EmojiData emoji
Emoji name, id, and animated.
int32_t minLength
The minimum input length for a text input.
ComponentType type
Integer component type.
std::string title
Url, for url types.
bool disabled
Whether the component is disabled, default false.
int32_t maxLength
The maximum input length for a text input.
std::string placeholder
Custom placeholder text if nothing is selected, max 100 characters.
std::string url
Url, for url types.
std::string value
A pre-filled value for this component.
std::vector< ChannelType > channelTypes
Array of channel types List of channel types to include in the channel select component (type 8).
int32_t maxValues
The maximum number of items that can be chosen; default 1, max 25.
std::vector< SelectOptionData > options
Aray of select options the choices in the select, max 25.
int32_t minValues
The minimum number of items that must be chosen; default 1, min 0, max 25.
std::string customId
A developer-defined identifier for the component, max 100 characters.
Action row data of Message components.
std::vector< ComponentData > components
Array of components to make up the action-row.
std::string customId
A developer-defined identifier for the component, max 100 characters.
std::vector< ApplicationCommandOptionChoiceData > choices
Autocomplete choices(max of 25 choices).
std::vector< EmbedData > embeds
Message embeds.
std::vector< ActionRowData > components
Message components.
std::vector< File > files
Files for uploading.
AllowedMentionsData allowedMentions
Allowed mentions data.
std::string title
The title of the popup modal.
ApplicationCommandType type
The type of ApplicationCommand.
bool dmPermission
Indicates whether the command is available in DMs with the app, only for globally - scoped commands.
std::string description
A description of the current ApplicationCommand.
std::string version
An autoincremented version.
std::string name
Name of the current ApplicationCommand.
std::unordered_map< std::string, std::string > nameLocalizations
Dictionary with keys in available locales.
Snowflake applicationId
The current application id.
std::vector< ApplicationCommandOptionData > options
A vector of possible options for the current ApplicationCommand.
Permissions defaultMemberPermissions
Set of permissions represented as a bit set all.
std::unordered_map< std::string, std::string > descriptionLocalizations
Dictionary with keys in available locales.
std::string name
The name of the Channel that was mentioned.
Snowflake guildId
The id of the Guild where it took place.
ChannelType type
The type of Channel that was mentioned.
TimeStamp lastPinTimeStamp
The time of the last pinned Message.
Snowflake guildId
The id of the Guild within which the Message was pinned.
Snowflake channelId
The id of the Channel within which the Message was pinned.
Snowflake guildId
The id of the Guild for which the threads are being synced.
std::vector< ChannelData > threads
All active threads in the given channels that the current User can access.
std::vector< ThreadMemberData > members
Array of members that are a part of the Thread.
std::vector< std::string > channelIds
The parent Channel ids whose threads are being synced.
std::vector< ThreadMemberData > addedMembers
New members added to the Thread.
uint32_t memberCount
Number of Guild-members in the Thread.
Snowflake guildId
Guild id of the Thread.
std::vector< std::string > removedMemberIds
Members who have been removed.
std::string name
The name of the Sticker.
StickerItemType formatType
Message Sticker item type.
TimeStamp editedTimestamp
The time at which it was edited.
std::vector< std::string > mentionRoles
std::vector of "mention roles" ids.
std::vector< UserData > mentions
Array of User data, for individual's that were mentioned.
bool mentionEveryone
Does the Message mention everyone?
Snowflake webHookId
WebHook id of the Message, if applicable.
MessageInteractionData interaction
Message Interaction data.
MessageReferenceData messageReference
Message reference data.
ChannelData thread
The Thread that the Message was sent in, if applicable.
TimeStamp timeStamp
The timeStamp of when the Message was created.
GuildMemberData member
The author's Guild member data.
std::string content
The Message's content.
Snowflake channelId
The Channel it was sent in.
Snowflake guildId
The id of the Guild the Message was sent in.
std::vector< StickerItemData > stickerItems
Array of Message Sticker item data.
std::vector< ChannelMentionData > mentionChannels
array of Channel mention data.
UserData author
The author's User data.
std::vector< ActionRowData > components
Array of action row data.
std::vector< AttachmentData > attachments
Array of attachment data.
std::vector< EmbedData > embeds
Array of Message embeds.
std::vector< StickerData > stickers
Array of Message Sticker data.
Snowflake applicationId
Application id.
bool tts
Is it a text-to-speech Message?
ApplicationData application
Application data.
MessageActivityData activity
Message activity data.
Data structure representing a single Message.
std::unique_ptr< MessageDataOld > referencedMessage
The referenced Message, to reply to.
std::unordered_map< uint64_t, UserData > users
std::map full of UserData.
std::unordered_map< uint64_t, MessageData > messages
std::map full of messageData->
std::unordered_map< uint64_t, AttachmentData > attachments
std::map of Snowflakes to attachment objects the ids and attachment objects.
std::unordered_map< uint64_t, RoleData > roles
std::map full of RoleData.
std::unordered_map< uint64_t, ChannelData > channels
std::map full of ChannelData.
std::unordered_map< uint64_t, GuildMemberData > members
std::map full of GuildMemeberData.
std::string coverStickerId
Id of a Sticker in the pack which is shown as the pack's icon.
std::string name
Name of the Sticker pack.
std::string skuId
Id of the pack's SKU.
Snowflake Id
Id of the Sticker pack.
std::string description
Description of the Sticker pack.
std::vector< StickerData > stickers
Array of Sticker objects the stickers in the pack.
std::string bannerAssetId
Id of the Sticker pack's banner image.
std::vector< IntegrationData > integrations
An array of partial server integrations.
bool friendSync
Whether friend sync is enabled for this connection.
std::string name
The userName of the connection account.
std::string type
The service of the connection(twitch, youtube).
bool verified
Whether the connection is verified.
ConnectionVisibilityTypes visibility
Visibility of this connection.
bool revoked
Whether the connection is revoked.
bool showActivity
Whether activities related to this connection will be shown in presence updates.
std::vector< ApplicationCommandInteractionDataOption > options
ApplicationCommand Interaction data options.
ApplicationCommandOptionType type
The type of ApplicationCommand options.
std::string name
The name of the current option.
bool focused
True if this option is the currently focused option for autocomplete.
JsonStringValue value
The value if it's an int32_t.
Snowflake guildId
The guild that the command took place in.
std::vector< ApplicationCommandInteractionDataOption > options
ApplicationCommand Interaction data options.
ApplicationCommandType type
The type of ApplicationCommand.
ApplicationCommandInteractionData applicationCommandData
ApplicationCommand Interaction data.
MessageCommandInteractionData messageInteractionData
Message command Interaction data.
UserCommandInteractionData userInteractionData
User command Interaction data.
ComponentInteractionData componentData
Component Interaction data.
ModalInteractionData modalData
Modal Interaction data.
Snowflake guildId
The Guild id of the Guild it was sent in.
InteractionDataData data
The Interaction's data.
MessageData message
The Message that the Interaction came through on, if applicable.
Snowflake applicationId
The application's id.
std::string guildLocale
The guild's preferred locale, if invoked in a guild.
std::string token
The Interaction token.
UserData user
The User data of the sender of the Interaction.
InteractionType type
The type of Interaction.
int32_t version
The Interaction version.
std::string locale
The selected language of the invoking user.
GuildMemberData member
The data of the Guild member who sent the Interaction, if applicable.
Snowflake channelId
The Channel the Interaction was sent in.
Permissions appPermissions
Bitwise set of permissions the app or bot has within the channel the interaction was sent from.
uint32_t maxConcurrency
The number of identify requests allowed per 5 seconds.
uint32_t total
The total number of session starts the current User is allowed.
uint32_t resetAfter
The number of Milliseconds after which the limit resets.
uint32_t remaining
The remaining number of session starts the current User is allowed.
uint32_t shards
The recommended number of shards to use when connecting.
SessionStartData sessionStartLimit
Information on the current session start limit.
std::string url
The WSS Url that can be used for connecting to the gateway.
Data representing an input-event, which is any Message or Interaction that is coming into the bot as ...
GuildData getGuildData() const
Returns the Guild of this input-event.
MessageData getMessageData() const
Returns the Message data, if applicable, of this input-event.
UserData getUserData() const
Returns the User of this input-event.
ChannelData getChannelData() const
Returns the Channel of this input-event.
GuildMemberData getGuildMemberData() const
Returns the GuildMember of this input-event.
InteractionData getInteractionData() const
Returns the Interaction data, if appplicable, of this input-event.
Data for responding to an input-event.
RespondToInputEventData & addFile(File theFile)
Adds a file to the current collection of files for this message response.
RespondToInputEventData & setResponseType(InputEventResponseType typeNew)
For setting the type of response to make.
RespondToInputEventData & addSelectMenu(bool disabled, const std::string &customIdNew, std::vector< SelectOptionData > options, const std::string &placeholder, int32_t maxValues, int32_t minValues, SelectMenuType type, std::vector< ChannelType > channelTypes=std::vector< ChannelType >{})
Adds a select-menu to the response Message.
InputEventResponseType type
The type of response to make.
RespondToInputEventData & setTTSStatus(bool enabledTTs)
For setting the tts status of a response.
RespondToInputEventData & addContent(const std::string &dataPackage)
For setting the Message content in a response.
RespondToInputEventData & setTargetUserID(const Snowflake targetUserIdNew)
For setting the direct-Message User target of a response.
RespondToInputEventData & addAllowedMentions(AllowedMentionsData dataPackage)
For setting the allowable mentions in a response.
RespondToInputEventData & addComponentRow(ActionRowData dataPackage)
For setting the components in a response.
RespondToInputEventData & addModal(const std::string &topTitleNew, const std::string &topCustomIdNew, const std::string &titleNew, const std::string &customIdNew, bool required, int32_t minLength, int32_t maxLength, TextInputStyle inputStyle, const std::string &label="", const std::string &placeholder="")
Adds a modal to the response Message.
RespondToInputEventData & addMessageEmbed(EmbedData dataPackage)
For setting the embeds in a response.
RespondToInputEventData & addButton(bool disabled, const std::string &customIdNew, const std::string &buttonLabel, ButtonStyle buttonStyle, const std::string &emojiName="", Snowflake emojiId=Snowflake{}, const std::string &url="")
Adds a button to the response Message.
RespondToInputEventData & setAutoCompleteChoice(Serializer value, const std::string &theName, std::unordered_map< std::string, std::string > theNameLocalizations)
For setting the choices of an autocomplete response.
Message response base, for responding to messages.
MessageResponseBase & addContent(const std::string &dataPackage)
For setting the Message content in a response.
MessageResponseBase & addModal(const std::string &topTitleNew, const std::string &topCustomIdNew, const std::string &titleNew, const std::string &customIdNew, bool required, int32_t minLength, int32_t maxLength, TextInputStyle inputStyle, const std::string &label="", const std::string &placeholder="")
Adds a modal to the response Message.
MessageResponseBase & addMessageEmbed(EmbedData dataPackage)
For setting the embeds in a response.
MessageResponseBase & addFile(File theFile)
Adds a file to the current collection of files for this message response.
MessageResponseBase & setTTSStatus(bool enabledTTs)
For setting the tts status of a response.
MessageResponseBase & addAllowedMentions(AllowedMentionsData dataPackage)
For setting the allowable mentions in a response.
MessageResponseBase & addComponentRow(ActionRowData dataPackage)
For setting the components in a response.
MessageResponseBase & addButton(bool disabled, const std::string &customIdNew, const std::string &buttonLabel, ButtonStyle buttonStyle, const std::string &emojiName="", Snowflake emojiId=Snowflake{}, const std::string &url="")
Adds a button to the response Message.
MessageResponseBase & addSelectMenu(bool disabled, const std::string &customIdNew, std::vector< SelectOptionData > options, const std::string &placeholder, int32_t maxValues, int32_t minValues, SelectMenuType type, std::vector< ChannelType > channelTypes=std::vector< ChannelType >{})
Adds a select-menu to the response Message.
InteractionCallbackData data
Interaction ApplicationCommand callback data.
std::string thumbnailUrl
The Url of the thumbnail image of this Song.
std::string duration
The duration of the Song.
std::string viewUrl
The url for listening to this Song through a browser.
std::string description
A description of the Song.
std::string songTitle
The title of the Song.
Command data, for functions executed by the CommandController.
MessageData getMessageData() noexcept
Returns the Message data, if applicable, of this input-event.
std::string getCommandName() noexcept
Returns the name of this entered command.
GuildData getGuildData() noexcept
Returns the Guild of this input-event.
GuildMemberData getGuildMemberData() noexcept
Returns the GuildMember of this input-event.
InputEventData getInputEventData() noexcept
Returns the InputEventData for this command.
InteractionData getInteractionData() noexcept
Returns the Interaction data, if appplicable, of this input-event.
std::string getSubCommandName() noexcept
Returns the subcommand-name of this entered command.
ChannelData getChannelData() noexcept
Returns the Channel of this input-event.
UserData getUserData() noexcept
Returns the User of this input-event.
JsonifierValue getCommandArguments() noexcept
Returns the collection of command inputs/options for this command.
std::string getSubCommandGroupName() noexcept
Returns the subcommand-name of this entered command group.
static GuildData getCachedGuild(GetGuildData dataPackage)
Collects a Guild from the library's cache.
static GuildMemberData getCachedGuildMember(GetGuildMemberData dataPackage)
Collects a GuildMember from the library's cache.
static CoRoutine< void > deleteInputEventResponseAsync(InputEventData &dataPackage, int32_t timeDelayNew=0)
Deletes a previously sent "input-event-response".
static CoRoutine< InputEventData > respondToInputEventAsync(RespondToInputEventData dataPackage)
Responds to one of a number of types of "InputEvents".
Definition: InputEvents.cpp:32
void updateVoiceStatus(UpdateVoiceStateData &datdataPackageaPackage)
Updates the bot's current voice-status. Joins/leaves a Channel, and/or self deafens/mutes.
static UserData getCachedUser(GetUserData dataPackage)
Collects a given User from the library's cache.
For connecting two bots to stream the VC contents between the two.
Definition: Utilities.hpp:182
AudioFrameType type
The type of audio frame.
Definition: Utilities.hpp:833
std::basic_string< std::byte > data
The audio data.
Definition: Utilities.hpp:834
int64_t currentSize
The current size of the allocated memory.
Definition: Utilities.hpp:836
uint64_t guildMemberId
GuildMemberId for the sending GuildMember.
Definition: Utilities.hpp:835
For connecting to a voice-channel. "streamInfo" is used when a socket is created to connect this bot ...
Definition: Utilities.hpp:859
int32_t currentShard
The current websocket shard, if applicable.
Definition: Utilities.hpp:861
Class for representing a timeStamp, as well as working with time-related values.
Definition: Utilities.hpp:1125
VoiceConnection class - represents the connection to a given voice Channel.