DiscordCoreAPI
A Discord bot library written in C++, with custom asynchronous coroutines.
Loading...
Searching...
No Matches
DiscordCoreClient.hpp
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/// DiscordCoreClient01.hpp - Header file for the main/exposed DiscordCoreClient class.
22/// May 12, 2021 Chris M.
23/// https://discordcoreapi.com
24/// \file DiscordCoreClient.hpp
25
26#pragma once
27
28#ifndef DISCORD_CORE_CLIENT
29 #define DISCORD_CORE_CLIENT
30
60
61namespace DiscordCoreAPI {
62
63 class DiscordCoreAPI_Dll SIGTERMError : public std::runtime_error {
64 public:
65 SIGTERMError(String theString);
66 };
67
68 class DiscordCoreAPI_Dll SIGSEGVError : public std::runtime_error {
69 public:
70 SIGSEGVError(String theString);
71 };
72
73 class DiscordCoreAPI_Dll SIGINTError : public std::runtime_error {
74 public:
75 SIGINTError(String theString);
76 };
77
78 class DiscordCoreAPI_Dll SIGILLError : public std::runtime_error {
79 public:
80 SIGILLError(String theString);
81 };
82
83 class DiscordCoreAPI_Dll SIGABRTError : public std::runtime_error {
84 public:
85 SIGABRTError(String theString);
86 };
87
88 class DiscordCoreAPI_Dll SIGFPEError : public std::runtime_error {
89 public:
90 SIGFPEError(String theString);
91 };
92
93 using SoundCloudAPIMap = std::unordered_map<Uint64, std::unique_ptr<DiscordCoreInternal::SoundCloudAPI>>;
94
95 using YouTubeAPIMap = std::unordered_map<Uint64, std::unique_ptr<DiscordCoreInternal::YouTubeAPI>>;
96
97 using VoiceConnectionMap = std::unordered_map<Uint64, std::unique_ptr<VoiceConnection>>;
98
99 using SongAPIMap = std::unordered_map<Uint64, std::unique_ptr<SongAPI>>;
100
101 /**
102 * \addtogroup main_endpoints
103 * @{
104 */
105 /// DiscordCoreClient - The main class for this library. \brief DiscordCoreClient - The main class for this library.
106 class DiscordCoreAPI_Dll DiscordCoreClient {
107 public:
108 friend DiscordCoreAPI_Dll DiscordCoreInternal::SoundCloudAPI* getSoundCloudAPI(Snowflake guildId);
109 friend DiscordCoreAPI_Dll DiscordCoreInternal::YouTubeAPI* getYouTubeAPI(Snowflake guildId);
110 friend DiscordCoreAPI_Dll VoiceConnection* getVoiceConnection(Snowflake guildId);
111 friend DiscordCoreAPI_Dll SongAPI* getSongAPI(Snowflake guildId);
112 friend class DiscordCoreInternal::WebSocketMessageHandler;
113 friend class DiscordCoreInternal::WebSocketSSLShard;
114 friend class DiscordCoreInternal::BaseSocketAgent;
115 friend class VoiceConnection;
116 friend class GuildData;
117 friend class BotUser;
118 friend class Guilds;
119
120 static DiscordCoreInternal::SoundCloudAPI* getSoundCloudAPI(Snowflake guildId);
121
122 static DiscordCoreInternal::YouTubeAPI* getYouTubeAPI(Snowflake guildId);
123
124 static VoiceConnection* getVoiceConnection(Snowflake guildId);
125
126 static SongAPI* getSongAPI(Snowflake guildId);
127
128 /// DiscordCoreClient constructor. \brief DiscordCoreClient constructor.
129 /// \param configData A DiscordCoreClientConfig structure to select various library options.
131
132 /// For registering a function with the CommandController. \brief For registering a function with the CommandController.
133 /// \param functionNames A vector containing the possible names for activating this command/function.
134 /// \param baseFunction A unique_ptr to the command to be registered.
135 /// \param commandData A CreateApplicationCommandData structure describing the current function.
136 /// \param alwaysRegister Whether or not it gets registered every time the bot boots up, or only when it's missing from the bot's list of registered commands.
137 void registerFunction(const std::vector<String>& functionNames, std::unique_ptr<BaseFunction> baseFunction, CreateApplicationCommandData commandData,
138 Bool alwaysRegister = false);
139
140 /// For collecting a reference to the CommandController. \brief For collecting a reference to the CommandController.
141 /// \returns CommandController& A reference to the CommandController.
142 CommandController& getCommandController();
143
144 /// For collecting a reference to the EventManager. \brief For collecting a reference to the EventManager.
145 /// \returns EventManager& A reference to the EventManager.
146 EventManager& getEventManager();
147
148 /// For collecting a copy of the current bot's User. \brief For collecting a copy of the current bot's User.
149 /// \returns BotUser An instance of BotUser.
150 BotUser getBotUser();
151
152 /// Executes the library, and waits for completion. \brief Executes the library, and waits for completion.
153 void runBot();
154
155 ~DiscordCoreClient() noexcept;
156
157 protected:
158 std::unordered_map<Uint32, std::unique_ptr<DiscordCoreInternal::BaseSocketAgent>> baseSocketAgentMap{};
159 std::unique_ptr<DiscordCoreInternal::HttpsClient> httpsClient{ nullptr };
160 StopWatch<std::chrono::milliseconds> theConnectionStopWatch{ 5300ms };
161 std::deque<CreateApplicationCommandData> commandsToRegister{};
162 #ifdef _WIN32
163 DiscordCoreInternal::WSADataWrapper theWSAData{};
164 #endif
165 std::deque<ConnectionPackage> theConnections{};
166 CommandController commandController{ this };
167 Bool didWeStartCorrectly{ false };
168 ConfigManager configManager{};
169 EventManager eventManager{};
170 BotUser currentUser{};
171
172 void registerFunctionsInternal();
173
174 GatewayBotData getGateWayBot();
175
176 Bool instantiateWebSockets();
177 };
178 /**@}*/
179}// namespace DiscordCoreAPI
180#endif
The main namespace for this library.
A class for handling commands from user input.
DiscordCoreClient - The main class for this library.
Class for handling the assignment of event-handling functions.
Data structure representing a single Guild.
Data from the GetGatewayBot endpoint.
An interface class for the Guild related Discord endpoints.
A class representing the Song APIs.
Definition: SongAPI.hpp:43
A type of User, to represent the Bot and some of its associated endpoints.
Configuration data for the library's main class, DiscordCoreClient.
Definition: Utilities.hpp:635
VoiceConnection class - represents the connection to a given voice Channel.