DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
Utilities.hpp
Go to the documentation of this file.
1/*
2 MIT License
3
4 DiscordCoreAPI, A bot library for Discord, written in C++, and featuring explicit multithreading through the usage of custom, asynchronous C++ CoRoutines.
5
6 Copyright 2022, 2023 Chris M. (RealTimeChris)
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in all
16 copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 SOFTWARE.
25*/
26/// Utilities.cpp - Header file for the Utilities.
27/// Jun 28, 2022
28/// https://discordcoreapi.com
29/// \file Utilities.hpp
30
31#pragma once
32
33#include <discordcoreapi/Utilities/Base.hpp>
37#include <discordcoreapi/Utilities/UnboundedMessageBlock.hpp>
39#include <coroutine>
40
41namespace DiscordCoreAPI {
42
43 /**
44 * \addtogroup foundation_entities
45 * @{
46 */
47
48 /// @brief Activity types.
49 enum class ActivityType : uint8_t {
50 Game = 0,///< Game.
51 Streaming = 1,///< Streaming.
52 Listening = 2,///< Listening.
53 Watching = 3,///< Watching.
54 Custom = 4,///< Custom.
55 Competing = 5///< Competing.
56 };
57
58 /// @brief Activity data.
59 struct ActivityData {
60 UnorderedSet<std::string> excludedKeys{};
61 Snowflake applicationId{};///< Application ID for the game.
62 TimeStamp created_at{};///< Unix timestamp(in milliseconds) of when the activity was added to the user's session.
63 std::string details{};///< What the player is currently doing.
64 ActivityType type{};///< Activity's type.
65 std::string state{};///< User's current party status, or text used for a custom status.
66 std::string name{};///< Name of the activity.
67 std::string url{};///< Stream URL, is validated when type is 1.
68
69 ActivityData() = default;
70
71 ~ActivityData() = default;
72 };
73
74 /// @brief For connecting two bots to stream the VC contents between the two.
75 struct StreamInfo {
76 bool streamBotAudio{};///< Do we stream the audio coming from other bots?
77 std::string address{};///< The address to connect to.
78 StreamType type{};///< The type of streamer that this is. Set one to client and one to server.
79 uint16_t port{};///< The port to connect to.
80 };
81
82 namespace DiscordCoreInternal {
83
84 class SoundCloudRequestBuilder;
85 class YouTubeRequestBuilder;
86 class WebSocketClient;
87 class BaseSocketAgent;
88 class SoundCloudAPI;
89 class YouTubeAPI;
90
91 }// namespace DiscordCoreInternal
92
93 struct OnVoiceServerUpdateData;
94 struct OnVoiceStateUpdateData;
95 struct File;
96
97 class DiscordCoreClient;
98 class CommandController;
99 class VoiceConnection;
100 class GuildMemberData;
101 class GuildMembers;
102 class ChannelData;
103 class Reactions;
104 class RoleData;
105 class BotUser;
106
107 /**@}*/
108
109 /**
110 * \addtogroup utilities
111 * @{
112 */
113
114 template<typename ReturnType, bool timeOut = true> class CoRoutine;
115
116 /**@}*/
117
118 /**
119 * \addtogroup foundation_entities
120 * @{
121 */
122
123 enum class PresenceUpdateState { Online = 0, Do_Not_Disturb = 1, Idle = 2, Invisible = 3, Offline = 4 };
124
125 /// @brief For updating a User's presence.
126 struct DiscordCoreAPI_Dll UpdatePresenceData {
127 template<typename ValueType> friend struct jsonifier::core;
128 UnorderedSet<std::string> excludedKeys{};
129 jsonifier::vector<ActivityData> activities{};///< A vector of activities.
130 PresenceUpdateState status{};///< Current status.
131 int64_t since{};///< When was the activity started?
132 bool afk{};///< Are we afk.
133
134 inline UpdatePresenceData() = default;
135 UpdatePresenceData(PresenceUpdateState updateState);
136
137 operator DiscordCoreInternal::EtfSerializer();
138
139 protected:
140 std::string statusReal{};
141 };
142
143 std::basic_ostream<char>& operator<<(std::basic_ostream<char>& outputSttream, const std::string& (*function)( void ));
144
145 /// @brief Input event response types.
146 enum class InputEventResponseType : uint8_t {
147 Unset = 0,///< Unset.
148 Deferred_Response = 1,
149 Ephemeral_Deferred_Response = 2,///< Deferred ephemeral response.
150 Interaction_Response = 3,///< Interaction response.
151 Ephemeral_Interaction_Response = 4,///< Ephemeral Interaction response.
152 Edit_Interaction_Response = 5,///< Interaction response edit.
153 Follow_Up_Message = 6,///< Follow-up MessageData.
154 Ephemeral_Follow_Up_Message = 7,///< Ephemeral follow-up MessageData.
155 Edit_Follow_Up_Message = 8,///< Follow-up Message edit.
156 Application_Command_AutoComplete_Result = 9,///< Respond to an autocomplete interaction with suggested choices.
157 Modal_Interaction_Response = 10,///< Respond to an interaction with a popup modal.
158 };
159
160 /// @brief Gateway intents.
161 enum class GatewayIntents : uint32_t {
162 Guilds = 1 << 0,///< Intent for receipt of Guild information.
163 Guild_Members = 1 << 1,///< Intent for receipt of Guild members.
164 Guild_Bans = 1 << 2,///< Intent for receipt of Guild bans.
165 Guild_Emojis = 1 << 3,///< Intent for receipt of Guild emojis.
166 Guild_Integrations = 1 << 4,///< Intent for receipt of Guild integrations.
167 Guild_Webhooks = 1 << 5,///< Intent for receipt of Guild webhooks.
168 Guild_Invites = 1 << 6,///< Intent for receipt of Guild invites.
169 Guild_VoiceStates = 1 << 7,///< Intent for receipt of Guild voice states.
170 Guild_Presences = 1 << 8,///< Intent for receipt of Guild presences.
171 Guild_Messages = 1 << 9,///< Intent for receipt of Guild messages.
172 Guild_Message_Reactions = 1 << 10,///< Intent for receipt of Guild message reactions.
173 Guild_Message_Typing = 1 << 11,///< Intent for receipt of Guild message typing notifications.
174 Direct_Messages = 1 << 12,///< Intent for receipt of direct messages (DMs).
175 Direct_Message_Reactions = 1 << 13,///< Intent for receipt of direct message reactions.
176 Direct_Message_Typing = 1 << 14,///< Intent for receipt of direct message typing notifications.
177 Message_Content = 1 << 15,///< Intent for receipt of message content.
178 Guild_Scheduled_Events = 1 << 16,///< Scheduled events.
179 Auto_Moderation_Configuration = 1 << 20,/// Auto moderation configuration.
180 Auto_Moderation_Execution = 1 << 21,///< Auto moderation execution.
183 Auto_Moderation_Execution,///< Default intents (all non-privileged intents).
184 Privileged_Intents = Guild_Members | Guild_Presences | Message_Content,///< Privileged intents requiring ID.
185 All_Intents = Default_Intents | Privileged_Intents///< Every single intent.
186 };
187
188 /// @brief Function data for repeated functions to be loaded.
190 std::function<void(DiscordCoreClient*)> function{};///< The std::function char* to be loaded.
191 uint32_t intervalInMs{};///< The time interval at which to call the std::function.
192 bool repeated{};///< Whether or not the std::function is repeating.
193 int64_t dummyArg{};
194 };
195
196 /// @brief Represents which text format to use for websocket transfer.
197 enum class TextFormat : uint8_t {
198 Etf = 0x00,///< Etf format.
199 Json = 0x01///< Json format.
200 };
201
202 /// @brief Sharding options for the library.
204 uint32_t numberOfShardsForThisProcess{ 1 };///< The number of shards to launch on the current process.
205 uint32_t totalNumberOfShards{ 1 };///< The total number of shards that will be launched across all processes.
206 uint32_t startingShard{};///< The first shard to start on this process.
207 };
208
209 /// @brief Loggin options for the library.
211 bool logWebSocketSuccessMessages{};///< Do we log the websocket success messages to std::cout?
212 bool logWebSocketErrorMessages{};///< Do we log the websocket error messages to std::cout?
213 bool logGeneralSuccessMessages{};///< Do we log general success messages to std::cout?
214 bool logGeneralErrorMessages{};///< Do we log general error messages to std::cout?
215 bool logHttpsSuccessMessages{};///< Do we log Https response success messages to std::cout?
216 bool logHttpsErrorMessages{};///< Do we log Https response error messages to std::cout?
217 };
218
219 /// @brief For selecting the caching style of the library.
221 bool cacheGuildMembers{ true };///< Do we cache GuildMembers?
222 bool cacheChannels{ true };///< Do we cache Channels?
223 bool cacheGuilds{ true };///< Do we cache Guilds?
224 bool cacheRoles{ true };///< Do we cache Roles?
225 bool cacheUsers{ true };///< Do we cache Users?
226 };
227
228 /// @brief Configuration data for the library's main class, DiscordCoreClient.
230 UpdatePresenceData presenceData{ PresenceUpdateState::Online };///< Presence data to initialize your bot with.
231 jsonifier::vector<RepeatedFunctionData> functionsToExecute{};///< Functions to execute after a timer, or on a repetition.
232 GatewayIntents intents{ GatewayIntents::All_Intents };///< The gateway intents to be used for this instance.
233 TextFormat textFormat{ TextFormat::Etf };///< Use ETF or JSON format for websocket transfer?
234 std::string connectionAddress{};///< A potentially alternative connection address for the websocket.
235 ShardingOptions shardOptions{};///< Options for the sharding of your bot.
236 LoggingOptions logOptions{};///< Options for the output/logging of the library.
237 CacheOptions cacheOptions{};///< Options for the cache of the library.
238 uint16_t connectionPort{};///< A potentially alternative connection port for the websocket.
239 std::string botToken{};///< Your bot's token.
240 };
241
242 struct JsonStringValue {
244 jsonifier::raw_json_data value{};
245 };
246
247 class DiscordCoreAPI_Dll ConfigManager {
248 public:
249 ConfigManager() = default;
250
251 explicit ConfigManager(const DiscordCoreClientConfig&);
252
253 bool doWePrintWebSocketSuccessMessages() const;
254
255 bool doWePrintWebSocketErrorMessages() const;
256
257 bool doWePrintHttpsSuccessMessages() const;
258
259 bool doWePrintHttpsErrorMessages() const;
260
261 bool doWePrintGeneralSuccessMessages() const;
262
263 bool doWePrintGeneralErrorMessages() const;
264
265 bool doWeCacheGuildMembers() const;
266
267 bool doWeCacheChannels() const;
268
269 bool doWeCacheUsers() const;
270
271 bool doWeCacheGuilds() const;
272
273 bool doWeCacheRoles() const;
274
275 UpdatePresenceData getPresenceData() const;
276
277 std::string getBotToken() const;
278
279 uint32_t getTotalShardCount() const;
280
281 uint32_t getStartingShard() const;
282
283 uint32_t getShardCountForThisProcess() const;
284
285 std::string getConnectionAddress() const;
286
287 void setConnectionAddress(const std::string& connectionAddressNew);
288
289 uint16_t getConnectionPort() const;
290
291 void setConnectionPort(const uint16_t connectionPortNew);
292
293 jsonifier::vector<RepeatedFunctionData> getFunctionsToExecute() const;
294
295 TextFormat getTextFormat() const;
296
297 GatewayIntents getGatewayIntents();
298
299 protected:
300 DiscordCoreClientConfig config{};
301 };
302
303 /// @brief Color constants for use in the EmbedData color values.
304 namespace Colors {
305 const std::string_view White{ "FFFFFF" },///< White.
306 DiscordWhite{ "FFFFFE" },///< Discord white.
307 LightGray{ "C0C0C0" },///< Light gray.
308 Gray{ "808080" },///< Gray.
309 DarkGray{ "404040" },///< Dark gray.
310 Black{ "000000" },///< Black.
311 DiscordBlack{ "000001" },///< Discord black.
312 Red{ "FF0000" },///< Red.
313 Pink{ "FFAFAF" },///< Pink.
314 Orange{ "FFC800" },///< Orange.
315 Yellow{ "FFFF00" },///< Yellow.
316 Green{ "00FF00" },///< Green.
317 Magenta{ "FF00FF" },///< Magenta.
318 Cyan{ "00FFFF" },///< Cyan.
319 Blue{ "0000FF" },///< Blue.
320 LightSeaGreen{ "1ABC9C" },///< Light sea green.
321 MediumSeaGreen{ "2ECC71" },///< Medium sea green.
322 SummerSky{ "3498DB" },///< Summer skye.
323 DeepLilac{ "9B59B6" },///< Deep lilac.
324 Ruby{ "E91E63" },///< Ruby.
325 MoonYellow{ "F1C40F" },///< Moon yellow.
326 TahitiGold{ "E67E22" },///< Tahiti gold.
327 Cinnabar{ "E74C3C" },///< Cinnabar.
328 Submarine{ "95A5A6" },///< Submarine.
329 BlueAquamarine{ "607D8B" },///< Blue aquamarine.
330 DeepSea{ "11806A" },///< Deep sea.
331 SeaGreen{ "1F8B4C" },///< Sea green.
332 Endeavour{ "206694" },///< Endeavor.
333 VividViolet{ "71368A" },///< Vivid violet.
334 JazzberryJam{ "AD1457" },///< Jazzberry jam.
335 DarkGoldenrod{ "C27C0E" },///< Dark goldenrod.
336 Rust{ "A84300" },///< Rust.
337 Brown{ "992D22" },///< Brown.
338 GrayChateau{ "979C9F" },///< Gray chateau.
339 Bismark{ "546E7A" },///< Bismark.
340 StiBlue{ "0E4BEF" },///< Sti blue.
341 WrxBlue{ "00247D" },///< Wrx blue.
342 RalliArtCrimson{ "E60012" },///< Ralliart crimson.
343 Lime{ "00FF00" },///< Lime.
344 ForestGreen{ "228B22" },///< Forest green.
345 CadmiumGreen{ "097969" },///< Cadmium green.
346 Aquamarine{ "7FFFD4" },///< Aquamarine.
347 BlueGreen{ "088F8F" },///< Blue green.
348 Raspberry{ "E30B5C" },///< Raspberry.
349 ScarletRed{ "FF2400" };///< Scarlet red.
350 };
351
352 /**@}*/
353
354 /**
355 * \addtogroup voice_connection
356 * @{
357 */
358
359 /// @brief Audio frame types.
360 enum class AudioFrameType : uint8_t {
361 Unset = 0,///< Unset.
362 RawPCM = 1,///< Raw PCM.
363 Encoded = 2,///< Encoded audio data.
364 };
365
366 /// @brief Represents a single frame of audio data.
367 struct DiscordCoreAPI_Dll AudioFrameData {
368 AudioFrameType type{ AudioFrameType::Unset };///< The type of audio frame.
369 jsonifier::vector<uint8_t> data{};///< The audio data.
370 uint64_t guildMemberId{};///< GuildMemberId for the sending GuildMemberData.
371 int64_t currentSize{};///< The current size of the allocated memory.
372
373 AudioFrameData() = default;
374
376
377 AudioFrameData& operator+=(std::basic_string_view<uint8_t>);
378
379 inline bool operator==(const AudioFrameData& rhs) const {
380 return currentSize == rhs.currentSize;
381 }
382
383 void clearData();
384 };
385
386 /// For connecting to a voice-channel. "streamInfo" is used when a socket is created to connect this bot to another bot, for transmitting audio back and forth.
387 /// @brief For connecting to a voice-channel. "streamInfo" is used when a socket is created to connect this bot to another bot, for transmitting audio back and forth.
389 StreamInfo streamInfo{};///< The info for the stream-socket, if applicable.
390 int32_t currentShard{};///< The current websocket shard, if applicable.
391 Snowflake channelId{};///< The channel id to connect to.
392 Snowflake guildId{};///< The guild id to connect to.
393 Snowflake userId{};///< This bot's user id.
394 bool selfDeaf{};///< Self-deafen the bot?
395 bool selfMute{};///< Self-mute the bot?
396 };
397
398 /**@}*/
399
400 /**
401 * \addtogroup utilities
402 * @{
403 */
404
405 template<typename ReturnType> inline ReturnType fromString(const std::string& string, std::ios_base& (*type)( std::ios_base& )) {
406 ReturnType value{};
407 std::istringstream stream(string);
408 stream >> type, stream >> value;
409 return value;
410 }
411
412 template<typename ReturnType> inline std::string toHex(ReturnType inputValue) {
413 std::stringstream stream{};
414 stream << std::setfill('0') << std::setw(sizeof(ReturnType) * 2) << std::hex << inputValue;
415 return stream.str();
416 }
417
418 class RGBColorValue {
419 public:
420 uint8_t green{};
421 uint8_t blue{};
422 uint8_t red{};
423 };
424
425 using HexColorValue = std::string;
426
427 class DiscordCoreAPI_Dll ColorValue {
428 public:
429 template<typename ValueType> friend struct jsonifier::core;
430
431 ColorValue(std::string hexColorValue);
432
433 ColorValue(uint32_t colorValue);
434
435 RGBColorValue getRgbColorValue();
436
437 HexColorValue getHexColorValue();
438
439 uint32_t getIntColorValue();
440
441 protected:
442 uint32_t color{};
443 };
444
445 enum class HashType { User_Avatar = 0, Channel_Icon = 1, GuildMember_Avatar = 2, Guild_Icon = 3, Guild_Splash = 4, Guild_Banner = 5, Guild_Discovery = 6 };
446
447 class DiscordCoreAPI_Dll IconHash {
448 public:
449 IconHash() = default;
450
451 IconHash& operator=(const std::string& string);
452
453 IconHash(const std::string& string);
454
455 bool operator==(const std::string& rhs) const;
456
457 bool operator==(const IconHash& rhs) const;
458
459 friend std::string operator+(const IconHash& lhs, std::string rhs);
460
461 operator std::string() const;
462
463 protected:
464 uint64_t highBits{};
465 uint64_t lowBits{};
466 };
467
468 /**@}*/
469
470 /**
471 * \addtogroup foundation_entities
472 * @{
473 */
474
475 /// @brief Permission values, for a given Channel, by RoleData or GuildMemberData.
476 enum class Permission : uint64_t {
477 Create_Instant_Invite = 0x0000000000000001,///< Allows creation of instant invites.
478 Kick_Members = 0x0000000000000002,///< Allows kicking members.
479 Ban_Members = 0x0000000000000004,///< Allows banning members.
480 Administrator = 0x0000000000000008,///< Allows all permissions and bypasses channel permission overwrites.
481 Manage_Channels = 0x0000000000000010,///< Allows management and editing of channels.
482 Manage_Guild = 0x0000000000000020,///< Allows management and editing of the guild.
483 Add_Reactions = 0x0000000000000040,///< Allows for the addition of reactions to messages.
484 View_Audit_Log = 0x0000000000000080,///< Allows for viewing of audit logs.
485 Priority_Speaker = 0x0000000000000100,///< Allows for using priority speaker in a voice channel.
486 Stream = 0x0000000000000200,///< Allows the user to go live.
487 View_Channel = 0x0000000000000400,///< Allows guild members to view a channel, which includes reading messages in text channels.
488 Send_Messages = 0x0000000000000800,///< Allows for sending messages in a channel and creating threads in a forum.
489 Send_TTS_Messages = 0x0000000000001000,///< Allows for sending of /tts messages.
490 Manage_Messages = 0x0000000000002000,///< Allows for deletion of other users messages.
491 Embed_Links = 0x0000000000004000,///< Links sent by users with this permission will be auto-embedded.
492 Attach_Files = 0x0000000000008000,///< Allows for uploading images and files.
493 Read_Message_History = 0x0000000000010000,///< Allows for reading of message history.
494 Mention_Everyone = 0x0000000000020000,///< Allows for using the AT-everyone tag to notify all users in a channel.
495 Use_External_Emojis = 0x0000000000040000,///< Allows the usage of custom emojis from other servers.
496 View_Guild_Insights = 0x0000000000080000,///< Allows for viewing guild insights.
497 Connect = 0x0000000000100000,///< Allows for joining of a voice channel.
498 Speak = 0x0000000000200000,///< Allows for speaking in a voice channel.
499 Mute_Members = 0x0000000000400000,///< Allows for muting members in a voice channel.
500 Deafen_Members = 0x0000000000800000,///< Allows for deafening of members in a voice channel.
501 Move_Members = 0x0000000001000000,///< Allows for moving of members between voice channels.
502 Use_VAD = 0x0000000002000000,///< Allows for using voice-activity-detection in a voice channel.
503 Change_Nickname = 0x0000000004000000,///< Allows for modification of own nickname.
504 Manage_Nicknames = 0x0000000008000000,///< Allows for modification of other users nicknames.
505 Manage_Roles = 0x0000000010000000,///< Allows management and editing of roles.
506 Manage_Webhooks = 0x0000000020000000,///< Allows management and editing of webhooks.
507 Manage_Guild_Expressions = 0x0000000040000000,///< Allows management and editing of emojis, stickers, and soundboard sounds.
508 Use_Application_Commands = 0x0000000080000000,///< Allows members to use application commands, including slash commands and context menu.
509 Request_to_Speak = 0x0000000100000000,///< Allows for requesting to speak in stage channels. (This permission is under active development).
510 Manage_Events = 0x0000000200000000,///< Allows for creating, editing, and deleting scheduled events.
511 Manage_Threads = 0x0000000400000000,///< Allows for deleting and archiving threads, and viewing all protected threads.
512 Create_Public_Threads = 0x0000000800000000,///< Allows for creating public and announcement threads.
513 Create_Private_Threads = 0x0000001000000000,///< Allows for creating protected threads.
514 Use_External_Stickers = 0x0000002000000000,///< Allows the usage of custom stickers from other servers.
515 Send_Messages_in_Threads = 0x0000004000000000,///< Allows for sending messages in threads.
516 Use_Embedded_Activities = 0x0000008000000000,///< Allows for using Activities (applications with the EMBEDDED flag) in a voice channel.
517 Moderate_Members = 0x0000010000000000,///< Allows for timing out users to prevent them from sending or reacting to messages in chat.
518 View_Creator_Monetization_Analytics = 0x0000020000000000,///< Allows for viewing role subscription insights.
519 Use_Soundboard = 0x0000040000000000,///< Allows for using soundboard in a voice channel.
520 Use_External_Sounds = 0x0000200000000000,///< Allows the usage of custom soundboard sounds from other servers.
521 Send_Voice_Messages = 0x0000400000000000,///< Allows sending voice messages.
522 };
523
524 /// @brief PermissionsBase class, for representing and manipulating Permission values.
525 template<typename ValueType> class PermissionsBase {
526 public:
527 friend class jsonifier_internal::parser;
528
529 inline bool operator==(const std::string& other) const {
530 return *static_cast<const ValueType*>(this) == other;
531 }
532
533 /// @brief Returns a string containing all of a given User's PermissionsBase for a given Channel.
534 /// @param guildMember The GuildMemberData who's PermissionsBase to analyze.
535 /// @param channel The ChannelData withint which to check for PermissionsBase.
536 /// @return std::string A string containing the final Permission's value for a given Channel.
537 static inline std::string getCurrentChannelPermissions(const GuildMemberData& guildMember, const ChannelData& channel) {
538 return computePermissions(guildMember, channel);
539 }
540
541 /// @brief Checks for a given Permission in a chosen ChannelData, for a specific UserData.
542 /// @param guildMember The GuildMemberData who to check the PermissionsBase of.
543 /// @param channel The ChannelData within which to check for the Permission's presence.
544 /// @param permission A Permission to check the current ChannelData for.
545 /// @return bool A bool suggesting the presence of the chosen Permission.
546 inline bool checkForPermission(const GuildMemberData& guildMember, const ChannelData& channel, Permission permission) {
547 if ((stoull(computePermissions(guildMember, channel)) & static_cast<uint64_t>(permission)) == static_cast<uint64_t>(permission)) {
548 return true;
549 } else {
550 return false;
551 }
552 }
553
554 /// @brief Returns a string containing the currently held PermissionsBase in a given Guild.
555 /// @param guildMember The GuildMemberData who's PermissionsBase are to be evaluated.
556 /// @return std::string A string containing the current PermissionsBase.
557 static inline std::string getCurrentGuildPermissions(const GuildMemberData& guildMember) {
558 PermissionsBase setValue(computeBasePermissions(guildMember));
559 return static_cast<ValueType*>(setValue);
560 }
561
562 /// @brief Removes one or more PermissionsBase from the current PermissionsBase value.
563 /// @param permissionsToRemove A vector containing the PermissionsBase you wish to remove.
564 inline void removePermissions(const jsonifier::vector<Permission>& permissionsToRemove) {
565 uint64_t permissionsInteger = *static_cast<ValueType*>(this);
566 for (auto valueNew: permissionsToRemove) {
567 permissionsInteger &= ~static_cast<uint64_t>(valueNew);
568 }
569 std::stringstream sstream{};
570 sstream << permissionsInteger;
571 *static_cast<ValueType*>(this) = sstream.str();
572 }
573
574 /// @brief Adds one or more PermissionsBase to the current PermissionsBase value.
575 /// @param permissionsToAdd A vector containing the PermissionsBase you wish to add.
576 inline void addPermissions(const jsonifier::vector<Permission>& permissionsToAdd) {
577 uint64_t permissionsInteger = *static_cast<ValueType*>(this);
578 for (auto valueNew: permissionsToAdd) {
579 permissionsInteger |= static_cast<uint64_t>(valueNew);
580 }
581 std::stringstream sstream{};
582 sstream << permissionsInteger;
583 *static_cast<ValueType*>(this) = sstream.str();
584 }
585
586 /// @brief Displays the currently present PermissionsBase in a string, and returns a vector with each of them stored in string format.
587 /// @return jsonifier::vector A vector full of strings of the PermissionsBase that are in the input std::string's value.
588 inline jsonifier::vector<std::string> displayPermissions() {
589 jsonifier::vector<std::string> returnVector{};
590 uint64_t permissionsInteger = *static_cast<ValueType*>(this);
591 if (permissionsInteger & (1ll << 3)) {
592 for (int64_t x = 0; x < 46; ++x) {
593 permissionsInteger |= 1ll << x;
594 }
595 }
596 if (permissionsInteger & static_cast<uint64_t>(Permission::Create_Instant_Invite)) {
597 returnVector.emplace_back("Create Instant Invite");
598 }
599 if (permissionsInteger & static_cast<uint64_t>(Permission::Kick_Members)) {
600 returnVector.emplace_back("Kick Members");
601 }
602 if (permissionsInteger & static_cast<uint64_t>(Permission::Ban_Members)) {
603 returnVector.emplace_back("Ban Members");
604 }
605 if (permissionsInteger & static_cast<uint64_t>(Permission::Administrator)) {
606 returnVector.emplace_back("Administrator");
607 }
608 if (permissionsInteger & static_cast<uint64_t>(Permission::Manage_Channels)) {
609 returnVector.emplace_back("Manage Channels");
610 }
611 if (permissionsInteger & static_cast<uint64_t>(Permission::Manage_Guild)) {
612 returnVector.emplace_back("Manage Guild");
613 }
614 if (permissionsInteger & static_cast<uint64_t>(Permission::Add_Reactions)) {
615 returnVector.emplace_back("Add Reactions");
616 }
617 if (permissionsInteger & static_cast<uint64_t>(Permission::View_Audit_Log)) {
618 returnVector.emplace_back("View Audit Log");
619 }
620 if (permissionsInteger & static_cast<uint64_t>(Permission::Priority_Speaker)) {
621 returnVector.emplace_back("Priority Speaker");
622 }
623 if (permissionsInteger & static_cast<uint64_t>(Permission::Stream)) {
624 returnVector.emplace_back("Stream");
625 }
626 if (permissionsInteger & static_cast<uint64_t>(Permission::View_Channel)) {
627 returnVector.emplace_back("View Channel");
628 }
629 if (permissionsInteger & static_cast<uint64_t>(Permission::Send_Messages)) {
630 returnVector.emplace_back("Send Messages");
631 }
632 if (permissionsInteger & static_cast<uint64_t>(Permission::Send_TTS_Messages)) {
633 returnVector.emplace_back("Send TTS Messages");
634 }
635 if (permissionsInteger & static_cast<uint64_t>(Permission::Manage_Messages)) {
636 returnVector.emplace_back("Manage Messages");
637 }
638 if (permissionsInteger & static_cast<uint64_t>(Permission::Embed_Links)) {
639 returnVector.emplace_back("Embed Links");
640 }
641 if (permissionsInteger & static_cast<uint64_t>(Permission::Attach_Files)) {
642 returnVector.emplace_back("Attach Files");
643 }
644 if (permissionsInteger & static_cast<uint64_t>(Permission::Read_Message_History)) {
645 returnVector.emplace_back("Read Message History");
646 }
647 if (permissionsInteger & static_cast<uint64_t>(Permission::Mention_Everyone)) {
648 returnVector.emplace_back("Mention Everyone");
649 }
650 if (permissionsInteger & static_cast<uint64_t>(Permission::Use_External_Emojis)) {
651 returnVector.emplace_back("Use External Emoji");
652 }
653 if (permissionsInteger & static_cast<uint64_t>(Permission::View_Guild_Insights)) {
654 returnVector.emplace_back("View Guild Insights");
655 }
656 if (permissionsInteger & static_cast<uint64_t>(Permission::Connect)) {
657 returnVector.emplace_back("Connect");
658 }
659 if (permissionsInteger & static_cast<uint64_t>(Permission::Speak)) {
660 returnVector.emplace_back("Speak");
661 }
662 if (permissionsInteger & static_cast<uint64_t>(Permission::Mute_Members)) {
663 returnVector.emplace_back("Mute Members");
664 }
665 if (permissionsInteger & static_cast<uint64_t>(Permission::Deafen_Members)) {
666 returnVector.emplace_back("Deafen Members");
667 }
668 if (permissionsInteger & static_cast<uint64_t>(Permission::Move_Members)) {
669 returnVector.emplace_back("Move Members");
670 }
671 if (permissionsInteger & static_cast<uint64_t>(Permission::Use_VAD)) {
672 returnVector.emplace_back("Use VAD");
673 }
674 if (permissionsInteger & static_cast<uint64_t>(Permission::Change_Nickname)) {
675 returnVector.emplace_back("Change Nickname");
676 }
677 if (permissionsInteger & static_cast<uint64_t>(Permission::Manage_Nicknames)) {
678 returnVector.emplace_back("Manage Nicknames");
679 }
680 if (permissionsInteger & static_cast<uint64_t>(Permission::Manage_Roles)) {
681 returnVector.emplace_back("Manage Roles");
682 }
683 if (permissionsInteger & static_cast<uint64_t>(Permission::Manage_Webhooks)) {
684 returnVector.emplace_back("Manage Webhooks");
685 }
686 if (permissionsInteger & static_cast<uint64_t>(Permission::Manage_Guild_Expressions)) {
687 returnVector.emplace_back("Manage Emojis And Stickers");
688 }
689 if (permissionsInteger & static_cast<uint64_t>(Permission::Use_Application_Commands)) {
690 returnVector.emplace_back("Use Application Commands");
691 }
692 if (permissionsInteger & static_cast<uint64_t>(Permission::Request_to_Speak)) {
693 returnVector.emplace_back("Request To Speak");
694 }
695 if (permissionsInteger & static_cast<uint64_t>(Permission::Manage_Events)) {
696 returnVector.emplace_back("Manage Events");
697 }
698 if (permissionsInteger & static_cast<uint64_t>(Permission::Manage_Threads)) {
699 returnVector.emplace_back("Manage Threads");
700 }
701 if (permissionsInteger & static_cast<uint64_t>(Permission::Create_Public_Threads)) {
702 returnVector.emplace_back("Create Public Threads");
703 }
704 if (permissionsInteger & static_cast<uint64_t>(Permission::Create_Private_Threads)) {
705 returnVector.emplace_back("Create Private Threads");
706 }
707 if (permissionsInteger & static_cast<uint64_t>(Permission::Use_External_Stickers)) {
708 returnVector.emplace_back("Use External Stickers");
709 }
710 if (permissionsInteger & static_cast<uint64_t>(Permission::Send_Messages_in_Threads)) {
711 returnVector.emplace_back("Send Messages In Threads");
712 }
713 if (permissionsInteger & static_cast<uint64_t>(Permission::Use_Embedded_Activities)) {
714 returnVector.emplace_back("Start Embedded Activities");
715 }
716 if (permissionsInteger & static_cast<uint64_t>(Permission::Moderate_Members)) {
717 returnVector.emplace_back("Moderate Members");
718 }
719 if (permissionsInteger & static_cast<uint64_t>(Permission::View_Creator_Monetization_Analytics)) {
720 returnVector.emplace_back("View Creator Monetization Analytics");
721 }
722 if (permissionsInteger & static_cast<uint64_t>(Permission::Use_Soundboard)) {
723 returnVector.emplace_back("Use Soundboard");
724 }
725 if (permissionsInteger & static_cast<uint64_t>(Permission::Use_External_Sounds)) {
726 returnVector.emplace_back("Use External Sounds");
727 }
728 if (permissionsInteger & static_cast<uint64_t>(Permission::Send_Voice_Messages)) {
729 returnVector.emplace_back("Send Voice Messages");
730 }
731 return returnVector;
732 }
733
734 /// @brief Returns a string containing the currently held PermissionsBase.
735 /// @return std::string A string containing the current PermissionsBase.
736 inline std::string getCurrentPermissionString() {
737 std::string returnString = *static_cast<ValueType*>(this);
738 return returnString;
739 }
740
741 /// @brief Returns a string containing ALL of the possible PermissionsBase.
742 /// @return std::string A string containing all of the possible PermissionsBase.
743 static inline std::string getAllPermissions() {
744 uint64_t allPerms{};
745 for (int64_t x = 0; x < 46; ++x) {
746 allPerms |= 1ll << x;
747 }
748 std::stringstream stream{};
749 stream << allPerms;
750 return stream.str();
751 }
752
753 protected:
754 inline PermissionsBase() = default;
755
756 DiscordCoreAPI_Dll static std::string computeOverwrites(const std::string& basePermissions, const GuildMemberData& guildMember, const ChannelData& channel);
757
758 static inline std::string computePermissions(const GuildMemberData& guildMember, const ChannelData& channel) {
759 std::string permissions = computeBasePermissions(guildMember);
760 permissions = computeOverwrites(permissions, guildMember, channel);
761 return permissions;
762 }
763
764 DiscordCoreAPI_Dll static std::string computeBasePermissions(const GuildMemberData& guildMember);
765 };
766
767 class PermissionsParse : public PermissionsBase<PermissionsParse>, public std::string {
768 public:
769 template<typename ValueType> friend class PermissionsBase;
770
771 inline PermissionsParse() = default;
772
773 inline PermissionsParse& operator=(const std::string& valueNew) {
774 resize(valueNew.size());
775 std::memcpy(data(), valueNew.data(), size());
776 return *this;
777 }
778
779 inline PermissionsParse(const std::string& valueNew) {
780 *this = valueNew;
781 }
782
783 inline PermissionsParse& operator=(std::string&& valueNew) {
784 resize(valueNew.size());
785 std::memcpy(data(), valueNew.data(), size());
786 return *this;
787 }
788
789 inline PermissionsParse(std::string&& valueNew) {
790 *this = std::move(valueNew);
791 }
792
793 inline PermissionsParse& operator=(uint64_t valueNew) {
794 *this = std::to_string(valueNew);
795 return *this;
796 }
797
798 inline PermissionsParse(uint64_t valueNew) {
799 *this = valueNew;
800 }
801
802 inline PermissionsParse substr(uint64_t offset, uint64_t count) const {
803 return substr(offset, count);
804 }
805
806 inline uint64_t size() const {
807 return std::string::size();
808 }
809
810 inline char* data() {
811 return std::string::data();
812 }
813
814 inline operator uint64_t() const {
815 return std::stoull(*this);
816 }
817 };
818
819 class Permissions : public PermissionsBase<Permissions> {
820 public:
821 template<typename ValueType> friend class PermissionsBase;
822
823 inline Permissions() = default;
824
825 inline Permissions& operator=(const PermissionsParse& other) {
826 value = other.operator uint64_t();
827 return *this;
828 }
829
830 inline Permissions(const PermissionsParse& other) {
831 *this = other;
832 }
833
834 inline Permissions& operator=(const std::string& valueNew) {
835 value = stoull(valueNew);
836 return *this;
837 }
838
839 inline Permissions(const std::string& valueNew) {
840 *this = valueNew;
841 }
842
843 inline Permissions& operator=(std::string&& valueNew) {
844 value = stoull(valueNew);
845 return *this;
846 }
847
848 inline Permissions(std::string&& valueNew) {
849 *this = std::move(valueNew);
850 }
851
852 inline Permissions& operator=(uint64_t valueNew) {
853 value = valueNew;
854 return *this;
855 }
856
857 inline Permissions(uint64_t valueNew) {
858 *this = valueNew;
859 }
860
861 inline operator uint64_t() const {
862 return value;
863 }
864
865 inline operator std::string() const {
866 return std::to_string(value);
867 }
868
869 protected:
870 uint64_t value{};
871 };
872
873 DiscordCoreAPI_Dll std::string constructMultiPartData(const std::string& data, const jsonifier::vector<File>& files);
874
875 DiscordCoreAPI_Dll std::string convertToLowerCase(const std::string& stringToConvert);
876
877 DiscordCoreAPI_Dll std::string base64Encode(const std::string&, bool = false);
878
879 DiscordCoreAPI_Dll std::string loadFileContents(const std::string& filePath);
880
881 DiscordCoreAPI_Dll std::string utf8MakeValid(const std::string& inputString);
882
883 DiscordCoreAPI_Dll std::string urlEncode(const std::string& inputString);
884
885 DiscordCoreAPI_Dll void spinLock(uint64_t timeInNsToSpinLockFor);
886
887 DiscordCoreAPI_Dll std::string generateBase64EncodedKey();
888
889 DiscordCoreAPI_Dll bool nanoSleep(int64_t ns);
890
891 /// @brief Acquires a timeStamp with the current time and date - suitable for use in message-embeds.
892 /// @return std::string A string containing the current date-time stamp.
893 DiscordCoreAPI_Dll std::string getTimeAndDate();
894
895 /**@}*/
896
897 /**
898 * \addtogroup utilities
899 * @{
900 */
901 template<typename ReturnType, bool timeOut = true> class NewThreadAwaiter;
902
903 /// @brief An awaitable that can be used to launch the CoRoutine onto a new thread - as well as return the handle for stoppping its execution.
904 /// @tparam ReturnType The type of value returned by the containing CoRoutine.
905 /// @tparam timeOut Whether or not to time out the CoRoutine's execution after a period of time.
906 /// @return NewThreadAwaiter<ReturnType, timeOut> A NewThreadAwaiter for suspendint the current CoRoutine's execution.
907 template<typename ReturnType, bool timeOut = true> inline auto NewThreadAwaitable() {
909 }
910
911 /**@}*/
912};
StreamType
For selecting the type of streamer that the given bot is, one must be one server and one of client pe...
Definition: Base.hpp:896
AudioFrameType
Audio frame types.
Definition: Utilities.hpp:360
@ Encoded
Encoded audio data.
auto NewThreadAwaitable()
An awaitable that can be used to launch the CoRoutine onto a new thread - as well as return the handl...
Definition: Utilities.hpp:907
ActivityType
Activity types.
Definition: Utilities.hpp:49
GatewayIntents
Gateway intents.
Definition: Utilities.hpp:161
DiscordCoreAPI_Dll std::string getTimeAndDate()
Acquires a timeStamp with the current time and date - suitable for use in message-embeds.
Definition: Utilities.cpp:598
TextFormat
Represents which text format to use for websocket transfer.
Definition: Utilities.hpp:197
InputEventResponseType
Input event response types.
Definition: Utilities.hpp:146
Permission
Permission values, for a given Channel, by RoleData or GuildMemberData.
Definition: Utilities.hpp:476
@ Guild_Scheduled_Events
Scheduled events.
@ Privileged_Intents
Privileged intents requiring ID.
@ Guild_Integrations
Intent for receipt of Guild integrations.
@ Guild_Message_Typing
Intent for receipt of Guild message typing notifications.
@ Message_Content
Intent for receipt of message content.
@ All_Intents
Every single intent.
@ Default_Intents
Default intents (all non-privileged intents).
@ Guild_Bans
Intent for receipt of Guild bans.
@ Guild_Message_Reactions
Intent for receipt of Guild message reactions.
@ Direct_Message_Typing
Intent for receipt of direct message typing notifications.
@ Guild_Invites
Intent for receipt of Guild invites.
@ Guild_Emojis
Intent for receipt of Guild emojis.
@ Guild_Presences
Intent for receipt of Guild presences.
@ Guild_Webhooks
Intent for receipt of Guild webhooks.
@ Guild_VoiceStates
Intent for receipt of Guild voice states.
@ Direct_Message_Reactions
Intent for receipt of direct message reactions.
@ Guild_Messages
Intent for receipt of Guild messages.
@ Guild_Members
Intent for receipt of Guild members.
@ Auto_Moderation_Execution
Auto moderation configuration.
@ Direct_Messages
Intent for receipt of direct messages (DMs).
@ Ephemeral_Interaction_Response
Ephemeral Interaction response.
@ Ephemeral_Deferred_Response
Deferred ephemeral response.
@ Interaction_Response
Interaction response.
@ Modal_Interaction_Response
Respond to an interaction with a popup modal.
@ Edit_Interaction_Response
Interaction response edit.
@ Application_Command_AutoComplete_Result
Respond to an autocomplete interaction with suggested choices.
@ Edit_Follow_Up_Message
Follow-up Message edit.
@ Ephemeral_Follow_Up_Message
Ephemeral follow-up MessageData.
@ Follow_Up_Message
Follow-up MessageData.
@ Send_Voice_Messages
Allows sending voice messages.
@ View_Channel
Allows guild members to view a channel, which includes reading messages in text channels.
@ Use_External_Sounds
Allows the usage of custom soundboard sounds from other servers.
@ Manage_Events
Allows for creating, editing, and deleting scheduled events.
@ View_Creator_Monetization_Analytics
Allows for viewing role subscription insights.
@ Use_Application_Commands
Allows members to use application commands, including slash commands and context menu.
@ Manage_Messages
Allows for deletion of other users messages.
@ Use_VAD
Allows for using voice-activity-detection in a voice channel.
@ Connect
Allows for joining of a voice channel.
@ Manage_Nicknames
Allows for modification of other users nicknames.
@ Change_Nickname
Allows for modification of own nickname.
@ Create_Instant_Invite
Allows creation of instant invites.
@ Use_Soundboard
Allows for using soundboard in a voice channel.
@ Move_Members
Allows for moving of members between voice channels.
@ Send_Messages_in_Threads
Allows for sending messages in threads.
@ Priority_Speaker
Allows for using priority speaker in a voice channel.
@ Administrator
Allows all permissions and bypasses channel permission overwrites.
@ Read_Message_History
Allows for reading of message history.
@ Manage_Guild_Expressions
Allows management and editing of emojis, stickers, and soundboard sounds.
@ Speak
Allows for speaking in a voice channel.
@ Use_Embedded_Activities
Allows for using Activities (applications with the EMBEDDED flag) in a voice channel.
@ Manage_Webhooks
Allows management and editing of webhooks.
@ Mute_Members
Allows for muting members in a voice channel.
@ Manage_Roles
Allows management and editing of roles.
@ Create_Private_Threads
Allows for creating protected threads.
@ Use_External_Emojis
Allows the usage of custom emojis from other servers.
@ Kick_Members
Allows kicking members.
@ View_Audit_Log
Allows for viewing of audit logs.
@ Manage_Threads
Allows for deleting and archiving threads, and viewing all protected threads.
@ Create_Public_Threads
Allows for creating public and announcement threads.
@ Use_External_Stickers
Allows the usage of custom stickers from other servers.
@ Send_TTS_Messages
Allows for sending of /tts messages.
@ Manage_Channels
Allows management and editing of channels.
@ Ban_Members
Allows banning members.
@ Mention_Everyone
Allows for using the AT-everyone tag to notify all users in a channel.
@ Attach_Files
Allows for uploading images and files.
@ Manage_Guild
Allows management and editing of the guild.
@ Moderate_Members
Allows for timing out users to prevent them from sending or reacting to messages in chat.
@ Request_to_Speak
Allows for requesting to speak in stage channels. (This permission is under active development).
@ Add_Reactions
Allows for the addition of reactions to messages.
@ Send_Messages
Allows for sending messages in a channel and creating threads in a forum.
@ Stream
Allows the user to go live.
@ Embed_Links
Links sent by users with this permission will be auto-embedded.
@ View_Guild_Insights
Allows for viewing guild insights.
@ Deafen_Members
Allows for deafening of members in a voice channel.
JsonType
Enumeration for different JSON value types.
Definition: Etf.hpp:442
const std::string_view SeaGreen
Sea green.
Definition: Utilities.hpp:331
const std::string_view Cinnabar
Cinnabar.
Definition: Utilities.hpp:327
const std::string_view BlueAquamarine
Blue aquamarine.
Definition: Utilities.hpp:329
const std::string_view ScarletRed
Scarlet red.
Definition: Utilities.hpp:349
const std::string_view MediumSeaGreen
Medium sea green.
Definition: Utilities.hpp:321
const std::string_view Red
Red.
Definition: Utilities.hpp:312
const std::string_view Orange
Orange.
Definition: Utilities.hpp:314
const std::string_view BlueGreen
Blue green.
Definition: Utilities.hpp:347
const std::string_view DeepLilac
Deep lilac.
Definition: Utilities.hpp:323
const std::string_view LightSeaGreen
Light sea green.
Definition: Utilities.hpp:320
const std::string_view MoonYellow
Moon yellow.
Definition: Utilities.hpp:325
const std::string_view SummerSky
Summer skye.
Definition: Utilities.hpp:322
const std::string_view Aquamarine
Aquamarine.
Definition: Utilities.hpp:346
const std::string_view Raspberry
Raspberry.
Definition: Utilities.hpp:348
const std::string_view Gray
Gray.
Definition: Utilities.hpp:308
const std::string_view GrayChateau
Gray chateau.
Definition: Utilities.hpp:338
const std::string_view Endeavour
Endeavor.
Definition: Utilities.hpp:332
const std::string_view Cyan
Cyan.
Definition: Utilities.hpp:318
const std::string_view DeepSea
Deep sea.
Definition: Utilities.hpp:330
const std::string_view Ruby
Ruby.
Definition: Utilities.hpp:324
const std::string_view LightGray
Light gray.
Definition: Utilities.hpp:307
const std::string_view Bismark
Bismark.
Definition: Utilities.hpp:339
const std::string_view ForestGreen
Forest green.
Definition: Utilities.hpp:344
const std::string_view CadmiumGreen
Cadmium green.
Definition: Utilities.hpp:345
const std::string_view DarkGoldenrod
Dark goldenrod.
Definition: Utilities.hpp:335
const std::string_view DiscordBlack
Discord black.
Definition: Utilities.hpp:311
const std::string_view White
White.
Definition: Utilities.hpp:305
const std::string_view Black
Black.
Definition: Utilities.hpp:310
const std::string_view Submarine
Submarine.
Definition: Utilities.hpp:328
const std::string_view TahitiGold
Tahiti gold.
Definition: Utilities.hpp:326
const std::string_view DiscordWhite
Discord white.
Definition: Utilities.hpp:306
const std::string_view RalliArtCrimson
Ralliart crimson.
Definition: Utilities.hpp:342
const std::string_view DarkGray
Dark gray.
Definition: Utilities.hpp:309
const std::string_view Brown
Brown.
Definition: Utilities.hpp:337
const std::string_view Pink
Pink.
Definition: Utilities.hpp:313
const std::string_view VividViolet
Vivid violet.
Definition: Utilities.hpp:333
const std::string_view Magenta
Magenta.
Definition: Utilities.hpp:317
const std::string_view Rust
Rust.
Definition: Utilities.hpp:336
const std::string_view Yellow
Yellow.
Definition: Utilities.hpp:315
const std::string_view Green
Green.
Definition: Utilities.hpp:316
const std::string_view Lime
Lime.
Definition: Utilities.hpp:343
const std::string_view Blue
Blue.
Definition: Utilities.hpp:319
const std::string_view WrxBlue
Wrx blue.
Definition: Utilities.hpp:341
const std::string_view JazzberryJam
Jazzberry jam.
Definition: Utilities.hpp:334
const std::string_view StiBlue
Sti blue.
Definition: Utilities.hpp:340
An awaitable that can be used to launch the CoRoutine onto a new thread - as well as return the handl...
Definition: CoRoutine.hpp:437
DiscordCoreClient - The main class for this library.
Data structure representing a single GuildMemberData.
An interface class for the Guild related Discord endpoints.
A class that extends TimeStampBase to provide additional functionality.
Definition: Base.hpp:688
A class representing a Snowflake identifier with various operations.
Definition: Base.hpp:771
TimeStamp created_at
Unix timestamp(in milliseconds) of when the activity was added to the user's session.
Definition: Utilities.hpp:62
std::string name
Name of the activity.
Definition: Utilities.hpp:66
ActivityType type
Activity's type.
Definition: Utilities.hpp:64
std::string url
Stream URL, is validated when type is 1.
Definition: Utilities.hpp:67
Snowflake applicationId
Application ID for the game.
Definition: Utilities.hpp:61
std::string details
What the player is currently doing.
Definition: Utilities.hpp:63
std::string state
User's current party status, or text used for a custom status.
Definition: Utilities.hpp:65
For connecting two bots to stream the VC contents between the two.
Definition: Utilities.hpp:75
StreamType type
The type of streamer that this is. Set one to client and one to server.
Definition: Utilities.hpp:78
bool streamBotAudio
Do we stream the audio coming from other bots?
Definition: Utilities.hpp:76
uint16_t port
The port to connect to.
Definition: Utilities.hpp:79
std::string address
The address to connect to.
Definition: Utilities.hpp:77
For updating a User's presence.
Definition: Utilities.hpp:126
Function data for repeated functions to be loaded.
Definition: Utilities.hpp:189
std::function< void(DiscordCoreClient *)> function
The std::function char* to be loaded.
Definition: Utilities.hpp:190
bool repeated
Whether or not the std::function is repeating.
Definition: Utilities.hpp:192
uint32_t intervalInMs
The time interval at which to call the std::function.
Definition: Utilities.hpp:191
Sharding options for the library.
Definition: Utilities.hpp:203
uint32_t totalNumberOfShards
The total number of shards that will be launched across all processes.
Definition: Utilities.hpp:205
uint32_t startingShard
The first shard to start on this process.
Definition: Utilities.hpp:206
uint32_t numberOfShardsForThisProcess
The number of shards to launch on the current process.
Definition: Utilities.hpp:204
Loggin options for the library.
Definition: Utilities.hpp:210
bool logWebSocketErrorMessages
Do we log the websocket error messages to std::cout?
Definition: Utilities.hpp:212
bool logGeneralErrorMessages
Do we log general error messages to std::cout?
Definition: Utilities.hpp:214
bool logWebSocketSuccessMessages
Do we log the websocket success messages to std::cout?
Definition: Utilities.hpp:211
bool logHttpsSuccessMessages
Do we log Https response success messages to std::cout?
Definition: Utilities.hpp:215
bool logHttpsErrorMessages
Do we log Https response error messages to std::cout?
Definition: Utilities.hpp:216
bool logGeneralSuccessMessages
Do we log general success messages to std::cout?
Definition: Utilities.hpp:213
For selecting the caching style of the library.
Definition: Utilities.hpp:220
bool cacheChannels
Do we cache Channels?
Definition: Utilities.hpp:222
bool cacheRoles
Do we cache Roles?
Definition: Utilities.hpp:224
bool cacheGuildMembers
Do we cache GuildMembers?
Definition: Utilities.hpp:221
bool cacheGuilds
Do we cache Guilds?
Definition: Utilities.hpp:223
bool cacheUsers
Do we cache Users?
Definition: Utilities.hpp:225
Configuration data for the library's main class, DiscordCoreClient.
Definition: Utilities.hpp:229
UpdatePresenceData presenceData
Presence data to initialize your bot with.
Definition: Utilities.hpp:230
std::string botToken
Your bot's token.
Definition: Utilities.hpp:239
uint16_t connectionPort
A potentially alternative connection port for the websocket.
Definition: Utilities.hpp:238
TextFormat textFormat
Use ETF or JSON format for websocket transfer?
Definition: Utilities.hpp:233
LoggingOptions logOptions
Options for the output/logging of the library.
Definition: Utilities.hpp:236
jsonifier::vector< RepeatedFunctionData > functionsToExecute
Functions to execute after a timer, or on a repetition.
Definition: Utilities.hpp:231
GatewayIntents intents
The gateway intents to be used for this instance.
Definition: Utilities.hpp:232
CacheOptions cacheOptions
Options for the cache of the library.
Definition: Utilities.hpp:237
ShardingOptions shardOptions
Options for the sharding of your bot.
Definition: Utilities.hpp:235
std::string connectionAddress
A potentially alternative connection address for the websocket.
Definition: Utilities.hpp:234
Represents a single frame of audio data.
Definition: Utilities.hpp:367
int64_t currentSize
The current size of the allocated memory.
Definition: Utilities.hpp:371
For connecting to a voice-channel. "streamInfo" is used when a socket is created to connect this bot ...
Definition: Utilities.hpp:388
Snowflake guildId
The guild id to connect to.
Definition: Utilities.hpp:392
int32_t currentShard
The current websocket shard, if applicable.
Definition: Utilities.hpp:390
bool selfMute
Self-mute the bot?
Definition: Utilities.hpp:395
bool selfDeaf
Self-deafen the bot?
Definition: Utilities.hpp:394
Snowflake channelId
The channel id to connect to.
Definition: Utilities.hpp:391
StreamInfo streamInfo
The info for the stream-socket, if applicable.
Definition: Utilities.hpp:389
Snowflake userId
This bot's user id.
Definition: Utilities.hpp:393
PermissionsBase class, for representing and manipulating Permission values.
Definition: Utilities.hpp:525
static std::string getCurrentChannelPermissions(const GuildMemberData &guildMember, const ChannelData &channel)
Returns a string containing all of a given User's PermissionsBase for a given Channel.
Definition: Utilities.hpp:537
jsonifier::vector< std::string > displayPermissions()
Displays the currently present PermissionsBase in a string, and returns a vector with each of them st...
Definition: Utilities.hpp:588
static std::string getAllPermissions()
Returns a string containing ALL of the possible PermissionsBase.
Definition: Utilities.hpp:743
static std::string getCurrentGuildPermissions(const GuildMemberData &guildMember)
Returns a string containing the currently held PermissionsBase in a given Guild.
Definition: Utilities.hpp:557
bool checkForPermission(const GuildMemberData &guildMember, const ChannelData &channel, Permission permission)
Checks for a given Permission in a chosen ChannelData, for a specific UserData.
Definition: Utilities.hpp:546
void removePermissions(const jsonifier::vector< Permission > &permissionsToRemove)
Removes one or more PermissionsBase from the current PermissionsBase value.
Definition: Utilities.hpp:564
void addPermissions(const jsonifier::vector< Permission > &permissionsToAdd)
Adds one or more PermissionsBase to the current PermissionsBase value.
Definition: Utilities.hpp:576
std::string getCurrentPermissionString()
Returns a string containing the currently held PermissionsBase.
Definition: Utilities.hpp:736