33#include <discordcoreapi/Utilities/Base.hpp>
37#include <discordcoreapi/Utilities/UnboundedMessageBlock.hpp>
41namespace DiscordCoreAPI {
60 UnorderedSet<std::string> excludedKeys{};
82 namespace DiscordCoreInternal {
84 class SoundCloudRequestBuilder;
85 class YouTubeRequestBuilder;
86 class WebSocketClient;
87 class BaseSocketAgent;
93 struct OnVoiceServerUpdateData;
94 struct OnVoiceStateUpdateData;
97 class DiscordCoreClient;
98 class CommandController;
99 class VoiceConnection;
100 class GuildMemberData;
114 template<
typename ReturnType,
bool timeOut = true>
class CoRoutine;
123 enum class PresenceUpdateState { Online = 0, Do_Not_Disturb = 1,
Idle = 2, Invisible = 3, Offline = 4 };
127 template<
typename ValueType>
friend struct jsonifier::core;
128 UnorderedSet<std::string> excludedKeys{};
129 jsonifier::vector<ActivityData> activities{};
130 PresenceUpdateState status{};
137 operator DiscordCoreInternal::EtfSerializer();
140 std::string statusReal{};
143 std::basic_ostream<char>& operator<<(std::basic_ostream<char>& outputSttream,
const std::string& (*function)(
void ));
148 Deferred_Response = 1,
179 Auto_Moderation_Configuration = 1 << 20,
242 struct JsonStringValue {
244 jsonifier::raw_json_data value{};
247 class DiscordCoreAPI_Dll ConfigManager {
249 ConfigManager() =
default;
251 explicit ConfigManager(
const DiscordCoreClientConfig&);
253 bool doWePrintWebSocketSuccessMessages()
const;
255 bool doWePrintWebSocketErrorMessages()
const;
257 bool doWePrintHttpsSuccessMessages()
const;
259 bool doWePrintHttpsErrorMessages()
const;
261 bool doWePrintGeneralSuccessMessages()
const;
263 bool doWePrintGeneralErrorMessages()
const;
265 bool doWeCacheGuildMembers()
const;
267 bool doWeCacheChannels()
const;
269 bool doWeCacheUsers()
const;
271 bool doWeCacheGuilds()
const;
273 bool doWeCacheRoles()
const;
275 UpdatePresenceData getPresenceData()
const;
277 std::string getBotToken()
const;
279 uint32_t getTotalShardCount()
const;
281 uint32_t getStartingShard()
const;
283 uint32_t getShardCountForThisProcess()
const;
285 std::string getConnectionAddress()
const;
287 void setConnectionAddress(
const std::string& connectionAddressNew);
289 uint16_t getConnectionPort()
const;
291 void setConnectionPort(
const uint16_t connectionPortNew);
293 jsonifier::vector<RepeatedFunctionData> getFunctionsToExecute()
const;
300 DiscordCoreClientConfig config{};
305 const std::string_view
White{
"FFFFFF" },
369 jsonifier::vector<uint8_t> data{};
370 uint64_t guildMemberId{};
371 int64_t currentSize{};
405 template<
typename ReturnType>
inline ReturnType fromString(
const std::string&
string, std::ios_base& (*type)( std::ios_base& )) {
407 std::istringstream stream(
string);
408 stream >> type, stream >> value;
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;
418 class RGBColorValue {
425 using HexColorValue = std::string;
427 class DiscordCoreAPI_Dll ColorValue {
429 template<
typename ValueType>
friend struct jsonifier::core;
431 ColorValue(std::string hexColorValue);
433 ColorValue(uint32_t colorValue);
435 RGBColorValue getRgbColorValue();
437 HexColorValue getHexColorValue();
439 uint32_t getIntColorValue();
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 };
447 class DiscordCoreAPI_Dll IconHash {
449 IconHash() =
default;
451 IconHash& operator=(
const std::string&
string);
453 IconHash(
const std::string&
string);
455 bool operator==(
const std::string& rhs)
const;
457 bool operator==(
const IconHash& rhs)
const;
459 friend std::string operator+(
const IconHash& lhs, std::string rhs);
461 operator std::string()
const;
486 Stream = 0x0000000000000200,
498 Speak = 0x0000000000200000,
527 friend class jsonifier_internal::parser;
529 inline bool operator==(
const std::string& other)
const {
530 return *
static_cast<const ValueType*
>(
this) == other;
538 return computePermissions(guildMember, channel);
547 if ((stoull(computePermissions(guildMember, channel)) &
static_cast<uint64_t
>(permission)) ==
static_cast<uint64_t
>(permission)) {
559 return static_cast<ValueType*
>(setValue);
565 uint64_t permissionsInteger = *
static_cast<ValueType*
>(
this);
566 for (
auto valueNew: permissionsToRemove) {
567 permissionsInteger &= ~static_cast<uint64_t>(valueNew);
569 std::stringstream sstream{};
570 sstream << permissionsInteger;
571 *
static_cast<ValueType*
>(
this) = sstream.str();
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);
581 std::stringstream sstream{};
582 sstream << permissionsInteger;
583 *
static_cast<ValueType*
>(
this) = sstream.str();
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;
597 returnVector.emplace_back(
"Create Instant Invite");
600 returnVector.emplace_back(
"Kick Members");
603 returnVector.emplace_back(
"Ban Members");
606 returnVector.emplace_back(
"Administrator");
609 returnVector.emplace_back(
"Manage Channels");
612 returnVector.emplace_back(
"Manage Guild");
615 returnVector.emplace_back(
"Add Reactions");
618 returnVector.emplace_back(
"View Audit Log");
621 returnVector.emplace_back(
"Priority Speaker");
624 returnVector.emplace_back(
"Stream");
627 returnVector.emplace_back(
"View Channel");
630 returnVector.emplace_back(
"Send Messages");
633 returnVector.emplace_back(
"Send TTS Messages");
636 returnVector.emplace_back(
"Manage Messages");
639 returnVector.emplace_back(
"Embed Links");
642 returnVector.emplace_back(
"Attach Files");
645 returnVector.emplace_back(
"Read Message History");
648 returnVector.emplace_back(
"Mention Everyone");
651 returnVector.emplace_back(
"Use External Emoji");
654 returnVector.emplace_back(
"View Guild Insights");
657 returnVector.emplace_back(
"Connect");
660 returnVector.emplace_back(
"Speak");
663 returnVector.emplace_back(
"Mute Members");
666 returnVector.emplace_back(
"Deafen Members");
669 returnVector.emplace_back(
"Move Members");
672 returnVector.emplace_back(
"Use VAD");
675 returnVector.emplace_back(
"Change Nickname");
678 returnVector.emplace_back(
"Manage Nicknames");
681 returnVector.emplace_back(
"Manage Roles");
684 returnVector.emplace_back(
"Manage Webhooks");
687 returnVector.emplace_back(
"Manage Emojis And Stickers");
690 returnVector.emplace_back(
"Use Application Commands");
693 returnVector.emplace_back(
"Request To Speak");
696 returnVector.emplace_back(
"Manage Events");
699 returnVector.emplace_back(
"Manage Threads");
702 returnVector.emplace_back(
"Create Public Threads");
705 returnVector.emplace_back(
"Create Private Threads");
708 returnVector.emplace_back(
"Use External Stickers");
711 returnVector.emplace_back(
"Send Messages In Threads");
714 returnVector.emplace_back(
"Start Embedded Activities");
717 returnVector.emplace_back(
"Moderate Members");
720 returnVector.emplace_back(
"View Creator Monetization Analytics");
723 returnVector.emplace_back(
"Use Soundboard");
726 returnVector.emplace_back(
"Use External Sounds");
729 returnVector.emplace_back(
"Send Voice Messages");
737 std::string returnString = *
static_cast<ValueType*
>(
this);
745 for (int64_t x = 0; x < 46; ++x) {
746 allPerms |= 1ll << x;
748 std::stringstream stream{};
756 DiscordCoreAPI_Dll
static std::string computeOverwrites(
const std::string& basePermissions,
const GuildMemberData& guildMember,
const ChannelData& channel);
759 std::string permissions = computeBasePermissions(guildMember);
760 permissions = computeOverwrites(permissions, guildMember, channel);
764 DiscordCoreAPI_Dll
static std::string computeBasePermissions(
const GuildMemberData& guildMember);
767 class PermissionsParse :
public PermissionsBase<PermissionsParse>,
public std::string {
769 template<
typename ValueType>
friend class PermissionsBase;
771 inline PermissionsParse() =
default;
773 inline PermissionsParse& operator=(
const std::string& valueNew) {
774 resize(valueNew.size());
775 std::memcpy(data(), valueNew.data(), size());
779 inline PermissionsParse(
const std::string& valueNew) {
783 inline PermissionsParse& operator=(std::string&& valueNew) {
784 resize(valueNew.size());
785 std::memcpy(data(), valueNew.data(), size());
789 inline PermissionsParse(std::string&& valueNew) {
790 *
this = std::move(valueNew);
793 inline PermissionsParse& operator=(uint64_t valueNew) {
794 *
this = std::to_string(valueNew);
798 inline PermissionsParse(uint64_t valueNew) {
802 inline PermissionsParse substr(uint64_t offset, uint64_t count)
const {
803 return substr(offset, count);
806 inline uint64_t size()
const {
807 return std::string::size();
810 inline char* data() {
811 return std::string::data();
814 inline operator uint64_t()
const {
815 return std::stoull(*
this);
819 class Permissions :
public PermissionsBase<Permissions> {
821 template<
typename ValueType>
friend class PermissionsBase;
823 inline Permissions() =
default;
825 inline Permissions& operator=(
const PermissionsParse& other) {
826 value = other.operator uint64_t();
830 inline Permissions(
const PermissionsParse& other) {
834 inline Permissions& operator=(
const std::string& valueNew) {
835 value = stoull(valueNew);
839 inline Permissions(
const std::string& valueNew) {
843 inline Permissions& operator=(std::string&& valueNew) {
844 value = stoull(valueNew);
848 inline Permissions(std::string&& valueNew) {
849 *
this = std::move(valueNew);
852 inline Permissions& operator=(uint64_t valueNew) {
857 inline Permissions(uint64_t valueNew) {
861 inline operator uint64_t()
const {
865 inline operator std::string()
const {
866 return std::to_string(value);
873 DiscordCoreAPI_Dll std::string constructMultiPartData(
const std::string& data,
const jsonifier::vector<File>& files);
875 DiscordCoreAPI_Dll std::string convertToLowerCase(
const std::string& stringToConvert);
877 DiscordCoreAPI_Dll std::string base64Encode(
const std::string&,
bool =
false);
879 DiscordCoreAPI_Dll std::string loadFileContents(
const std::string& filePath);
881 DiscordCoreAPI_Dll std::string utf8MakeValid(
const std::string& inputString);
883 DiscordCoreAPI_Dll std::string urlEncode(
const std::string& inputString);
885 DiscordCoreAPI_Dll
void spinLock(uint64_t timeInNsToSpinLockFor);
887 DiscordCoreAPI_Dll std::string generateBase64EncodedKey();
889 DiscordCoreAPI_Dll
bool nanoSleep(int64_t ns);
901 template<
typename ReturnType,
bool timeOut = true>
class NewThreadAwaiter;
StreamType
For selecting the type of streamer that the given bot is, one must be one server and one of client pe...
AudioFrameType
Audio frame types.
@ 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...
ActivityType
Activity types.
GatewayIntents
Gateway intents.
DiscordCoreAPI_Dll std::string getTimeAndDate()
Acquires a timeStamp with the current time and date - suitable for use in message-embeds.
TextFormat
Represents which text format to use for websocket transfer.
InputEventResponseType
Input event response types.
Permission
Permission values, for a given Channel, by RoleData or GuildMemberData.
@ ChannelData
ChannelData.
@ 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.
const std::string_view SeaGreen
Sea green.
const std::string_view Cinnabar
Cinnabar.
const std::string_view BlueAquamarine
Blue aquamarine.
const std::string_view ScarletRed
Scarlet red.
const std::string_view MediumSeaGreen
Medium sea green.
const std::string_view Red
Red.
const std::string_view Orange
Orange.
const std::string_view BlueGreen
Blue green.
const std::string_view DeepLilac
Deep lilac.
const std::string_view LightSeaGreen
Light sea green.
const std::string_view MoonYellow
Moon yellow.
const std::string_view SummerSky
Summer skye.
const std::string_view Aquamarine
Aquamarine.
const std::string_view Raspberry
Raspberry.
const std::string_view Gray
Gray.
const std::string_view GrayChateau
Gray chateau.
const std::string_view Endeavour
Endeavor.
const std::string_view Cyan
Cyan.
const std::string_view DeepSea
Deep sea.
const std::string_view Ruby
Ruby.
const std::string_view LightGray
Light gray.
const std::string_view Bismark
Bismark.
const std::string_view ForestGreen
Forest green.
const std::string_view CadmiumGreen
Cadmium green.
const std::string_view DarkGoldenrod
Dark goldenrod.
const std::string_view DiscordBlack
Discord black.
const std::string_view White
White.
const std::string_view Black
Black.
const std::string_view Submarine
Submarine.
const std::string_view TahitiGold
Tahiti gold.
const std::string_view DiscordWhite
Discord white.
const std::string_view RalliArtCrimson
Ralliart crimson.
const std::string_view DarkGray
Dark gray.
const std::string_view Brown
Brown.
const std::string_view Pink
Pink.
const std::string_view VividViolet
Vivid violet.
const std::string_view Magenta
Magenta.
const std::string_view Rust
Rust.
const std::string_view Yellow
Yellow.
const std::string_view Green
Green.
const std::string_view Lime
Lime.
const std::string_view Blue
Blue.
const std::string_view WrxBlue
Wrx blue.
const std::string_view JazzberryJam
Jazzberry jam.
const std::string_view StiBlue
Sti blue.
An awaitable that can be used to launch the CoRoutine onto a new thread - as well as return the handl...
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.
A class representing a Snowflake identifier with various operations.
TimeStamp created_at
Unix timestamp(in milliseconds) of when the activity was added to the user's session.
std::string name
Name of the activity.
ActivityType type
Activity's type.
std::string url
Stream URL, is validated when type is 1.
Snowflake applicationId
Application ID for the game.
std::string details
What the player is currently doing.
std::string state
User's current party status, or text used for a custom status.
For connecting two bots to stream the VC contents between the two.
StreamType type
The type of streamer that this is. Set one to client and one to server.
bool streamBotAudio
Do we stream the audio coming from other bots?
uint16_t port
The port to connect to.
std::string address
The address to connect to.
For updating a User's presence.
Function data for repeated functions to be loaded.
std::function< void(DiscordCoreClient *)> function
The std::function char* to be loaded.
bool repeated
Whether or not the std::function is repeating.
uint32_t intervalInMs
The time interval at which to call the std::function.
Sharding options for the library.
uint32_t totalNumberOfShards
The total number of shards that will be launched across all processes.
uint32_t startingShard
The first shard to start on this process.
uint32_t numberOfShardsForThisProcess
The number of shards to launch on the current process.
Loggin options for the library.
bool logWebSocketErrorMessages
Do we log the websocket error messages to std::cout?
bool logGeneralErrorMessages
Do we log general error messages to std::cout?
bool logWebSocketSuccessMessages
Do we log the websocket success messages to std::cout?
bool logHttpsSuccessMessages
Do we log Https response success messages to std::cout?
bool logHttpsErrorMessages
Do we log Https response error messages to std::cout?
bool logGeneralSuccessMessages
Do we log general success messages to std::cout?
For selecting the caching style of the library.
bool cacheChannels
Do we cache Channels?
bool cacheRoles
Do we cache Roles?
bool cacheGuildMembers
Do we cache GuildMembers?
bool cacheGuilds
Do we cache Guilds?
bool cacheUsers
Do we cache Users?
Configuration data for the library's main class, DiscordCoreClient.
UpdatePresenceData presenceData
Presence data to initialize your bot with.
std::string botToken
Your bot's token.
uint16_t connectionPort
A potentially alternative connection port for the websocket.
TextFormat textFormat
Use ETF or JSON format for websocket transfer?
LoggingOptions logOptions
Options for the output/logging of the library.
jsonifier::vector< RepeatedFunctionData > functionsToExecute
Functions to execute after a timer, or on a repetition.
GatewayIntents intents
The gateway intents to be used for this instance.
CacheOptions cacheOptions
Options for the cache of the library.
ShardingOptions shardOptions
Options for the sharding of your bot.
std::string connectionAddress
A potentially alternative connection address for the websocket.
Represents a single frame of audio data.
int64_t currentSize
The current size of the allocated memory.
For connecting to a voice-channel. "streamInfo" is used when a socket is created to connect this bot ...
Snowflake guildId
The guild id to connect to.
int32_t currentShard
The current websocket shard, if applicable.
bool selfMute
Self-mute the bot?
bool selfDeaf
Self-deafen the bot?
Snowflake channelId
The channel id to connect to.
StreamInfo streamInfo
The info for the stream-socket, if applicable.
Snowflake userId
This bot's user id.
PermissionsBase class, for representing and manipulating Permission values.
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.
jsonifier::vector< std::string > displayPermissions()
Displays the currently present PermissionsBase in a string, and returns a vector with each of them st...
static std::string getAllPermissions()
Returns a string containing ALL of the possible PermissionsBase.
static std::string getCurrentGuildPermissions(const GuildMemberData &guildMember)
Returns a string containing the currently held PermissionsBase in a given Guild.
bool checkForPermission(const GuildMemberData &guildMember, const ChannelData &channel, Permission permission)
Checks for a given Permission in a chosen ChannelData, for a specific UserData.
void removePermissions(const jsonifier::vector< Permission > &permissionsToRemove)
Removes one or more PermissionsBase from the current PermissionsBase value.
void addPermissions(const jsonifier::vector< Permission > &permissionsToAdd)
Adds one or more PermissionsBase to the current PermissionsBase value.
std::string getCurrentPermissionString()
Returns a string containing the currently held PermissionsBase.