mirror of
https://gitlab.com/niansa/dpplogger.git
synced 2025-03-06 20:48:29 +01:00
Minor fixes to previous commit
This commit is contained in:
parent
108853c190
commit
13b372714d
2 changed files with 26 additions and 9 deletions
2
dcboost
2
dcboost
|
@ -1 +1 @@
|
||||||
Subproject commit 9c225be66bdec7a509efb32f40b3d45ec592709b
|
Subproject commit 15489b816b4d70a927e920fb9327c7ba122644ee
|
33
main.cpp
33
main.cpp
|
@ -11,6 +11,8 @@
|
||||||
#include <dcboost/discord.hpp>
|
#include <dcboost/discord.hpp>
|
||||||
#include <dcboost/snowflake.hpp>
|
#include <dcboost/snowflake.hpp>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
using namespace ChatFuse;
|
using namespace ChatFuse;
|
||||||
using namespace QLog;
|
using namespace QLog;
|
||||||
|
|
||||||
|
@ -223,7 +225,7 @@ protected:
|
||||||
// since it's safe to assume it's already been cached
|
// since it's safe to assume it's already been cached
|
||||||
|
|
||||||
// Make sure data is actually incomplete
|
// Make sure data is actually incomplete
|
||||||
if (incomplete_data["name"].isString() && incomplete_data["channels"].isArray()) {
|
if ((incomplete_data["name"].isString() && incomplete_data["channels"].isArray()) || incomplete_data["properties"].isObject()) {
|
||||||
// It's not, so we'll just use it as-is
|
// It's not, so we'll just use it as-is
|
||||||
processGuild(std::move(incomplete_data));
|
processGuild(std::move(incomplete_data));
|
||||||
continue;
|
continue;
|
||||||
|
@ -236,7 +238,20 @@ protected:
|
||||||
co_await asyncSleep(rng.getUInt(6000, 15000));
|
co_await asyncSleep(rng.getUInt(6000, 15000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void fixGuild(Json::Value& data) {
|
||||||
|
if (!settings.is_bot) {
|
||||||
|
auto& props = data["properties"];
|
||||||
|
for (const auto& prop_name : props.getMemberNames()) {
|
||||||
|
data[prop_name] = std::move(props[prop_name]);
|
||||||
|
}
|
||||||
|
data.removeMember("properties");
|
||||||
|
}
|
||||||
|
}
|
||||||
Cache::StoreResult processGuild(Json::Value&& data) {
|
Cache::StoreResult processGuild(Json::Value&& data) {
|
||||||
|
// Fix guild
|
||||||
|
fixGuild(data);
|
||||||
|
|
||||||
|
// Get guild ID
|
||||||
const auto& id = data["id"];
|
const auto& id = data["id"];
|
||||||
|
|
||||||
// Insert into database
|
// Insert into database
|
||||||
|
@ -407,18 +422,20 @@ protected:
|
||||||
* Intent handler
|
* Intent handler
|
||||||
*/
|
*/
|
||||||
virtual boost::asio::awaitable<void> intentHandler(std::string intent, Json::Value data) override {
|
virtual boost::asio::awaitable<void> intentHandler(std::string intent, Json::Value data) override {
|
||||||
|
std::ofstream(intent+".json") << data;
|
||||||
if (intent == "READY") [[unlikely]] {
|
if (intent == "READY") [[unlikely]] {
|
||||||
const auto& user = cache.store(std::move(data["user"])).data;
|
const auto& user = cache.store(std::move(data["user"])).data;
|
||||||
logger.log(Loglevel::info, "Connected to Discord as: "+user["username"].asString()+'#'+user["discriminator"].asString());
|
logger.log(Loglevel::info, "Connected to Discord as: "+user["username"].asString()+'#'+user["discriminator"].asString());
|
||||||
settings.is_bot = GetJSONAsOptionalInt(user["bot"]).value_or(false);
|
|
||||||
co_await fetchAllGuilds(std::move(data["guilds"]));
|
co_await fetchAllGuilds(std::move(data["guilds"]));
|
||||||
}
|
}
|
||||||
else if (intent == "GUILD_CREATE") [[unlikely]] {
|
else if (intent == "GUILD_CREATE") [[unlikely]] {
|
||||||
|
fixGuild(data);
|
||||||
processGuild(std::move(data));
|
processGuild(std::move(data));
|
||||||
} else if (intent == "GUILD_UPDATE") [[unlikely]] {
|
} else if (intent == "GUILD_UPDATE") [[unlikely]] {
|
||||||
insertGuildUpdate(data, false);
|
fixGuild(data);
|
||||||
cache.store(std::move(data));
|
if (cache.store(data).changed) insertGuildUpdate(data, false);
|
||||||
} else if (intent == "GUILD_DELETE") [[unlikely]] {
|
} else if (intent == "GUILD_DELETE") [[unlikely]] {
|
||||||
|
fixGuild(data);
|
||||||
insertGuildDelete(data["id"]);
|
insertGuildDelete(data["id"]);
|
||||||
}
|
}
|
||||||
else if (intent == "MESSAGE_CREATE") [[likely]] {
|
else if (intent == "MESSAGE_CREATE") [[likely]] {
|
||||||
|
@ -436,8 +453,7 @@ protected:
|
||||||
insertChannelUpdate(data, true);
|
insertChannelUpdate(data, true);
|
||||||
cache.store(std::move(data));
|
cache.store(std::move(data));
|
||||||
} else if (intent == "CHANNEL_UPDATE") [[unlikely]] {
|
} else if (intent == "CHANNEL_UPDATE") [[unlikely]] {
|
||||||
insertChannelUpdate(data, false);
|
if (cache.store(data).changed) cache.store(std::move(data));
|
||||||
cache.store(std::move(data));
|
|
||||||
} else if (intent == "CHANNEL_DELETE") [[unlikely]] {
|
} else if (intent == "CHANNEL_DELETE") [[unlikely]] {
|
||||||
insertChannelDelete(data["id"]);
|
insertChannelDelete(data["id"]);
|
||||||
}
|
}
|
||||||
|
@ -464,9 +480,10 @@ int main(int argc, char **argv) {
|
||||||
boost::asio::io_service io;
|
boost::asio::io_service io;
|
||||||
|
|
||||||
// Set up client
|
// Set up client
|
||||||
auto client = std::make_shared<MyClient>(io, ChatFuse::Discord::Settings{
|
auto client = std::make_shared<MyClient>(io, Discord::Settings{
|
||||||
.bot_token = argv[1],
|
.bot_token = argv[1],
|
||||||
.intents = ChatFuse::Discord::intents::all
|
.intents = Discord::intents::all,
|
||||||
|
.is_bot = false
|
||||||
});
|
});
|
||||||
client->detach();
|
client->detach();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue