Skip to content

Commit 9edfba7

Browse files
committed
Fix defining client in global causing a crash
1 parent 08bb4b3 commit 9edfba7

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

include/sleepy_discord/client.h

+6
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,12 @@ namespace SleepyDiscord {
596596
inline std::string getToken() { return *token.get(); }
597597
inline void setToken(const std::string& value) { token = std::unique_ptr<std::string>(new std::string(value)); }
598598
void start(const std::string _token, const char maxNumOfThreads = DEFAULT_THREADS, int _shardID = 0, int _shardCount = 0);
599+
inline void connect() {
600+
postTask([this]() {
601+
getTheGateway();
602+
connect(theGateway, this, connection);
603+
});
604+
}
599605
virtual bool connect(
600606
const std::string & /*uri*/, //IN
601607
GenericMessageReceiver* /*messageProcessor*/, //IN When a message is receved, this will process it

include/sleepy_discord/json_wrapper.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ namespace SleepyDiscord {
110110
static const auto getter = [&](DocType& doc) {
111111
value = get<Container>(doc);
112112
};
113-
if (!Base::getDoc(getter))
114-
return false;
115-
return true;
113+
return Base::getDoc(getter);
116114
}
117115

118116
template<template<class...> class Container, typename Type = TypeToConvertTo>

sleepy_discord/client.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ namespace SleepyDiscord {
3131
setShardID(_shardID, _shardCount);
3232

3333
messagesRemaining = 4;
34-
postTask(
35-
[this]() {
36-
getTheGateway();
37-
connect(theGateway, this, connection);
38-
}
39-
);
4034
}
4135

4236
BaseDiscordClient::~BaseDiscordClient() {

sleepy_discord/websocketpp_websocket.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ namespace SleepyDiscord {
9595
}
9696

9797
void WebsocketppDiscordClient::run() {
98+
BaseDiscordClient::connect();
9899
this_client.run();
99100
}
100101

0 commit comments

Comments
 (0)