Skip to content

Commit 64a9c6d

Browse files
committed
Updates! (Fixed the caches)
1 parent edc2e3c commit 64a9c6d

File tree

10 files changed

+43
-36
lines changed

10 files changed

+43
-36
lines changed

Include/discordcoreapi/FoundationEntities.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ namespace DiscordCoreAPI {
17451745
String asset{};///< Asset value for the Sticker.
17461746
String name{};///< The Sticker's name.
17471747
String tags{};///< Tags for the Sticker to use.
1748-
1748+
17491749
UserData user{};///< The User that uploaded the Guild Sticker.
17501750

17511751
StickerData() noexcept = default;
@@ -1924,7 +1924,7 @@ namespace DiscordCoreAPI {
19241924
GuildScheduledEventStatus status{};///< The status of the scheduled event.
19251925
String scheduledStartTime{};///< The time the scheduled event will start.
19261926
String scheduledEndTime{};///< The time the scheduled event will end, required if entity_type is External.
1927-
Uint32 userCount{ 0 };///< The number of users subscribed to the scheduled event.
1927+
Uint32 userCount{ 0 };///< The number of users subscribed to the scheduled event.
19281928
Snowflake channelId{};///< The Channel id in which the scheduled event will be hosted, or null if scheduled entity type is External.
19291929
String description{};///< The description of the scheduled event(1 - 1000 characters.
19301930
Snowflake guildId{};///< The Guild id which the scheduled event belongs to.
@@ -2163,9 +2163,9 @@ namespace DiscordCoreAPI {
21632163
class DiscordCoreAPI_Dll ApplicationCommandOptionChoiceData {
21642164
public:
21652165
UMap<String, String> nameLocalizations{};///< Dictionary with keys in available locales Localization dictionary for the name field.
2166+
JsonObject value{};
21662167
JsonType type{};///< The value of the option.
2167-
String value{};
2168-
String name{};///< The name of the current choice.
2168+
String name{};///< The name of the current choice.
21692169

21702170
ApplicationCommandOptionChoiceData() noexcept = default;
21712171

Include/discordcoreapi/Utilities.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ namespace DiscordCoreAPI {
163163
template<typename TheType>
164164
concept IsString = std::same_as<TheType, String>;
165165

166-
struct EnumConverter {
166+
struct DiscordCoreAPI_Dll EnumConverter {
167167
template<IsEnum EnumType> EnumConverter& operator=(EnumType other) {
168168
this->theUint = static_cast<Uint64>(other);
169169
return *this;
@@ -190,12 +190,8 @@ namespace DiscordCoreAPI {
190190

191191
operator Vector<Uint64>() const noexcept;
192192

193-
operator Vector<Uint64>() noexcept;
194-
195193
explicit operator Uint64() const noexcept;
196194

197-
explicit operator Uint64() noexcept;
198-
199195
bool isItAVector() const noexcept;
200196
bool isItAVector() noexcept;
201197

@@ -205,7 +201,7 @@ namespace DiscordCoreAPI {
205201
Uint64 theUint{};
206202
};
207203

208-
class JsonObject {
204+
class DiscordCoreAPI_Dll JsonObject {
209205
public:
210206
using ObjectType = std::map<String, JsonObject, std::less<>, std::allocator<std::pair<const String, JsonObject>>>;
211207
template<typename Type> using AllocatorType = std::allocator<Type>;
@@ -1052,8 +1048,8 @@ namespace DiscordCoreAPI {
10521048
Int32 secondsPerMonth{ secondsPerDay * daysPerMonth };
10531049
Int32 daysPerYear{ 365 };
10541050
Int32 secondsPerYear{ secondsPerDay * daysPerYear };
1055-
Int32 secondsToAdd =
1056-
(yearsToAdd * secondsPerYear) + (monthsToAdd * secondsPerMonth) + (daysToAdd * secondsPerDay) + (hoursToAdd * secondsPerHour) + (minutesToAdd * secondsPerMinute);
1051+
Int32 secondsToAdd = (yearsToAdd * secondsPerYear) + (monthsToAdd * secondsPerMonth) + (daysToAdd * secondsPerDay) + ((hoursToAdd + 8) * secondsPerHour) +
1052+
(minutesToAdd * secondsPerMinute);
10571053
result += secondsToAdd;
10581054
auto resultTwo = std::localtime(&result);
10591055
String theReturnString{};

Source/ChannelEntities.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,11 @@ namespace DiscordCoreAPI {
464464
return;
465465
}
466466
if (Channels::doWeCacheChannels) {
467-
Channels::cache.emplace(std::move(channel));
467+
if (!Channels::cache.contains(channel)) {
468+
Channels::cache.emplace(std::move(channel));
469+
} else {
470+
Channels::cache[channel] = std::move(channel);
471+
}
468472
if (Channels::cache.size() % 1000 == 0) {
469473
std::cout << "CHANNEL COUNT: " << Channels::cache.size() << std::endl;
470474
}

Source/FoundationEntities.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,9 @@ namespace DiscordCoreAPI {
12601260
voiceConnectInitData.selfMute = selfMute;
12611261
StopWatch theStopWatch{ 10000ms };
12621262
DiscordCoreClient::getVoiceConnection(this->id)->connect(voiceConnectInitData);
1263+
while (!DiscordCoreClient::getVoiceConnection(this->id)->areWeConnected()) {
1264+
std::this_thread::sleep_for(1ms);
1265+
}
12631266
this->voiceConnectionPtr = DiscordCoreClient::getVoiceConnection(this->id);
12641267
return this->voiceConnectionPtr;
12651268
} else {
@@ -3115,23 +3118,23 @@ namespace DiscordCoreAPI {
31153118
theData["name_localizations"] = this->nameLocalizations;
31163119
switch (this->type) {
31173120
case JsonType::Integer: {
3118-
theData["value"] = Uint64{ stoull(this->value) };
3121+
theData["value"] = Uint64{ this->value.theValue.numberUint };
31193122
break;
31203123
}
31213124
case JsonType::Float: {
3122-
theData["value"] = Double{ stod(this->value) };
3125+
theData["value"] = Double{ this->value.theValue.numberDouble };
31233126
break;
31243127
}
31253128
case JsonType::Boolean: {
3126-
if (this->value == "false") {
3129+
if (this->value.theValue.boolean == false) {
31273130
theData["value"] = Bool{ false };
31283131
} else {
31293132
theData["value"] = Bool{ true };
31303133
}
31313134
break;
31323135
}
31333136
case JsonType::String: {
3134-
theData["value"] = this->value;
3137+
theData["value"] = *this->value.theValue.string;
31353138
break;
31363139
}
31373140
}
@@ -3571,7 +3574,7 @@ namespace DiscordCoreAPI {
35713574
choiceData.name = theName;
35723575
StringView theString{};
35733576
if (theValue["value"].get(theString) == simdjson::error_code::SUCCESS) {
3574-
choiceData.value = theString;
3577+
choiceData.value.theValue = static_cast<String>(theString);
35753578
this->choices.emplace_back(choiceData);
35763579
return *this;
35773580
}

Source/GuildEntities.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,11 @@ namespace DiscordCoreAPI {
10651065
}
10661066
if (Guilds::doWeCacheGuilds) {
10671067
guild.discordCoreClient = Guilds::discordCoreClient;
1068-
Guilds::cache.emplace(std::move(guild));
1068+
if (!Guilds::cache.contains(guild)) {
1069+
Guilds::cache.emplace(std::move(guild));
1070+
} else {
1071+
Guilds::cache[guild] = std::move(guild);
1072+
}
10691073
if (Guilds::cache.size() % 100 == 0) {
10701074
std::cout << "THE GUILD COUNT: " << Guilds::cache.size() << ", TOTAL TIME: " << theStopWatch.totalTimePassed() << std::endl;
10711075
}

Source/GuildMemberEntities.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,11 @@ namespace DiscordCoreAPI {
338338
return;
339339
}
340340
if (GuildMembers::doWeCacheGuildMembers) {
341-
GuildMembers::cache.emplace(std::move(guildMember));
341+
if (!GuildMembers::cache.contains(guildMember)) {
342+
GuildMembers::cache.emplace(std::move(guildMember));
343+
} else {
344+
GuildMembers::cache[guildMember] = std::move(guildMember);
345+
}
342346
if (GuildMembers::cache.size() % 1000 == 0) {
343347
std::cout << "THE GUILDMEMBER COUNT: " << GuildMembers::cache.size() << std::endl;
344348
}

Source/RoleEntities.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ namespace DiscordCoreAPI {
351351
return;
352352
}
353353
if (Roles::doWeCacheRoles) {
354-
Roles::cache.emplace(std::move(role));
354+
if (!Roles::cache.contains(role)) {
355+
Roles::cache.emplace(std::move(role));
356+
} else {
357+
Roles::cache[role] = std::move(role);
358+
}
355359
if (Roles::cache.size() % 1000 == 0) {
356360
std::cout << "ROLE COUNT: " << Roles::cache.size() << ", AFTER: " << theStopWatchNew.totalTimePassed() << "s" << std::endl;
357361
}

Source/UserEntities.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ namespace DiscordCoreAPI {
272272
return;
273273
}
274274
if (Users::doWeCacheUsers) {
275-
Users::cache.emplace(std::move(user));
275+
if (!Users::cache.contains(user)) {
276+
Users::cache.emplace(std::move(user));
277+
} else {
278+
Users::cache[user] = std::move(user);
279+
}
276280
if (Users::cache.size() % 1000 == 0) {
277281
std::cout << "USERS COUNT: " << Users::cache.size() << std::endl;
278282
}

Source/Utilities.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,10 @@ namespace DiscordCoreAPI {
8282
return theObject;
8383
}
8484

85-
EnumConverter::operator Vector<Uint64>() noexcept {
86-
Vector<Uint64> theObject{};
87-
for (auto& value: this->theVector) {
88-
theObject.emplace_back(value);
89-
}
90-
return theObject;
91-
}
92-
9385
EnumConverter::operator Uint64() const noexcept {
9486
return this->theUint;
9587
}
9688

97-
EnumConverter::operator Uint64() noexcept {
98-
return this->theUint;
99-
}
100-
10189
bool EnumConverter::isItAVector() const noexcept {
10290
return this->vectorType;
10391
}

Source/VoiceConnection.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ namespace DiscordCoreAPI {
932932
if (this->taskThread01) {
933933
this->taskThread01->request_stop();
934934
if (this->taskThread01->joinable()) {
935-
this->taskThread01->join();
935+
this->taskThread01->detach();
936936
}
937937
this->taskThread01.reset(nullptr);
938938
}
@@ -942,7 +942,7 @@ namespace DiscordCoreAPI {
942942
}
943943
this->taskThread02->request_stop();
944944
if (this->taskThread02->joinable()) {
945-
this->taskThread02->join();
945+
this->taskThread02->detach();
946946
}
947947
this->taskThread02.reset(nullptr);
948948
}

0 commit comments

Comments
 (0)