66 DCA_INLINE sigtermerror(jsonifier::string_view message, std::source_location location = std::source_location::current()) :
dca_exception{ message, location } {};
71 DCA_INLINE sigsegverror(jsonifier::string_view message, std::source_location location = std::source_location::current()) :
dca_exception{ message, location } {};
76 DCA_INLINE siginterror(jsonifier::string_view message, std::source_location location = std::source_location::current()) :
dca_exception{ message, location } {};
81 DCA_INLINE sigillerror(jsonifier::string_view message, std::source_location location = std::source_location::current()) :
dca_exception{ message, location } {};
86 DCA_INLINE sigabrterror(jsonifier::string_view message, std::source_location location = std::source_location::current()) :
dca_exception{ message, location } {};
91 DCA_INLINE sigfpeerror(jsonifier::string_view message, std::source_location location = std::source_location::current()) :
dca_exception{ message, location } {};
94 using sound_cloud_api_map = unordered_map<uint64_t, unique_ptr<discord_core_internal::sound_cloud_api>>;
96 using you_tube_api_map = unordered_map<uint64_t, unique_ptr<discord_core_internal::you_tube_api>>;
98 using voice_connections_map = unordered_map<uint64_t, unique_ptr<voice_connection>>;
100 using song_api_map = unordered_map<uint64_t, unique_ptr<song_api>>;
102 template<
typename... arg_types>
using time_elapsed_handler = std::function<void(arg_types...)>;
104 template<
typename... arg_types,
typename function_type>
105 DCA_INLINE
static co_routine<void, false> threadFunction(function_type timeElapsedHandler,
bool repeated, int64_t timeInterval, arg_types... args) {
107 stop_watch<milliseconds> stopWatch{ milliseconds{ timeInterval } };
110 std::this_thread::sleep_for(milliseconds{
static_cast<int64_t
>(std::ceil(
static_cast<float>(timeInterval) * 10.0f / 100.0f)) });
111 while (!stopWatch.hasTimeElapsed() && !threadHandle.promise().stopRequested()) {
112 std::this_thread::sleep_for(1ms);
115 if (threadHandle.promise().stopRequested()) {
119 timeElapsedHandler(args...);
123 if (threadHandle.promise().stopRequested()) {
126 std::this_thread::sleep_for(1ms);
131 template<
typename... arg_types,
typename function_type> DCA_INLINE
static void executeFunctionAfterTimePeriod(function_type timeElapsedHandler,
132 int64_t timeDelay,
bool repeated,
bool blockForCompletion, arg_types... args) {
133 auto newThread = threadFunction(timeElapsedHandler, repeated, timeDelay, args...);
134 if (blockForCompletion) {
146 friend class discord_core_internal::websocket_client;
147 friend class discord_core_internal::base_socket_agent;
148 friend class discord_core_internal::websocket_core;
149 friend class voice_connection;
150 friend class guild_data;
151 friend class bot_user;
154 static discord_core_internal::sound_cloud_api& getSoundCloudAPI(snowflake guildId);
156 static discord_core_internal::you_tube_api& getYouTubeAPI(snowflake guildId);
158 static voice_connection& getVoiceConnection(snowflake guildId);
160 static song_api& getSongAPI(snowflake guildId);
162 static discord_core_client* getInstance();
166 discord_core_client(
const discord_core_client_config& configData);
174 void registerFunction(
const jsonifier::vector<jsonifier::string>& functionNames, unique_ptr<base_function>&& baseFunction,
175 const create_application_command_data& commandData,
bool alwaysRegister =
false);
179 command_controller& getCommandController();
183 const config_manager& getConfigManager()
const;
187 event_manager& getEventManager();
191 milliseconds getTotalUpTime();
195 static bot_user getBotUser();
200 ~discord_core_client();
203 DCA_INLINE
static unique_ptr<discord_core_client> instancePtr{};
204 static bot_user currentUser;
206 discord_core_client& operator=(discord_core_client&&) =
delete;
207 discord_core_client(discord_core_client&&) =
delete;
209 discord_core_client& operator=(
const discord_core_client&) =
delete;
210 discord_core_client(
const discord_core_client&) =
delete;
212 unordered_map<uint64_t, unique_ptr<discord_core_internal::base_socket_agent>> baseSocketAgentsMap{};
213 std::deque<create_application_command_data> commandsToRegister{};
214 unique_ptr<discord_core_internal::https_client> httpsClient{};
215 stop_watch<milliseconds> connectionStopWatch01{ 5000ms };
217 discord_core_internal::wsadata_wrapper theWSAData{};
219 std::atomic_uint64_t currentlyConnectingShard{};
220 std::atomic_bool areWeReadyToConnect{
false };
221 command_controller commandController{};
222 milliseconds startupTimeSinceEpoch{};
223 config_manager configManager{};
224 event_manager eventManager{};
226 bool areWeFullyConnected();
228 void registerFunctionsInternal();
230 gateway_bot_data getGateWayBot();
232 bool instantiateWebSockets();
A co_routine - representing a potentially asynchronous operation/function.
discord_core_client - the main class for this library.
static DCA_INLINE void printError(const string_type &what, std::source_location where=std::source_location::current())
Print an error message of the specified type.
@ guilds
Intent for receipt of guild information.
DCA_INLINE auto newThreadAwaitable()
An awaitable that can be used to launch the co_routine onto a new thread - as well as return the hand...
The main namespace for the forward-facing interfaces.
An exception class derived from std::runtime_error for dca-related exceptions.
DCA_INLINE dca_exception(jsonifier::string_view error, std::source_location location=std::source_location::current())
Constructor to create a dca_exception with an error message and optional source location.