Skip to content

Commit

Permalink
Been on a refactor binge (#941)
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis authored Oct 11, 2023
2 parents 947bceb + a338fe2 commit 2cfaeb5
Show file tree
Hide file tree
Showing 65 changed files with 74 additions and 215 deletions.
36 changes: 31 additions & 5 deletions include/dpp/dispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -830,8 +830,17 @@ struct DPP_EXPORT guild_delete_t : public event_dispatch_t {
using event_dispatch_t::event_dispatch_t;
using event_dispatch_t::operator=;

/** Deleted guild */
guild* deleted = nullptr;
/**
* @brief Deleted guild
*
*/
guild deleted;

/**
* @brief Guild ID deleted
*
*/
snowflake guild_id{0};
};

/** @brief Update guild stickers */
Expand Down Expand Up @@ -875,7 +884,7 @@ struct DPP_EXPORT channel_delete_t : public event_dispatch_t {
/**
* @brief channel being deleted
*/
channel* deleted = nullptr;
channel deleted;
};

/** @brief Update channel */
Expand Down Expand Up @@ -918,7 +927,19 @@ struct DPP_EXPORT message_delete_t : public event_dispatch_t {
/**
* @brief message being deleted
*/
message* deleted = nullptr;
snowflake id{0};

/**
* @brief Channel the message was deleted on
*
*/
snowflake channel_id{0};

/**
* @brief Guild the message was deleted on
*/
snowflake guild_id{0};

};

/** @brief Guild member remove */
Expand All @@ -931,10 +952,15 @@ struct DPP_EXPORT guild_member_remove_t : public event_dispatch_t {
*/
guild* removing_guild = nullptr;

/**
* @brief Guild ID removed from
*/
snowflake guild_id{0};

/**
* @brief user being removed
*/
user* removed = nullptr;
user removed;
};

/** @brief Session resumed */
Expand Down
1 change: 1 addition & 0 deletions src/dpp/discordevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ const std::map<std::string, dpp::events::event*> eventmap = {
{ "EMBEDDED_ACTIVITY_UPDATE", nullptr },
{ "GUILD_APPLICATION_COMMAND_INDEX_UPDATE", nullptr },
{ "CHANNEL_TOPIC_UPDATE", nullptr },
{ "VOICE_CHANNEL_STATUS_UPDATE", nullptr },
{ "GUILD_SCHEDULED_EVENT_CREATE", new dpp::events::guild_scheduled_event_create() },
{ "GUILD_SCHEDULED_EVENT_UPDATE", new dpp::events::guild_scheduled_event_update() },
{ "GUILD_SCHEDULED_EVENT_DELETE", new dpp::events::guild_scheduled_event_delete() },
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/automod_rule_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
Expand Down
4 changes: 0 additions & 4 deletions src/dpp/events/automod_rule_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@


namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
*
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/automod_rule_execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/automod_rule_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/channel_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
Expand Down
23 changes: 9 additions & 14 deletions src/dpp/events/channel_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
Expand All @@ -40,20 +38,17 @@ using namespace dpp;
*/
void channel_delete::handle(discord_client* client, json &j, const std::string &raw) {
json& d = j["d"];
dpp::guild* g = nullptr;
dpp::channel* c = dpp::find_channel(snowflake_not_null(&d, "id"));
if (c) {
g = dpp::find_guild(c->guild_id);
if (g) {
auto gc = std::find(g->channels.begin(), g->channels.end(), c->id);
if (gc != g->channels.end()) {
g->channels.erase(gc);
}
}
dpp::get_channel_cache()->remove(c);
const channel c = channel().fill_from_json(&d);
guild* g = find_guild(c.guild_id);
if (g) {
g->channels.erase(std::remove(g->channels.begin(), g->channels.end(), c.id), g->channels.end());
}
if (client->creator->cache_policy.channel_policy != cp_none) {
/* We must only pass pointers found by find_channel into here, any other ptr is an invalid non-op */
get_channel_cache()->remove(find_channel(c.id));
}
if (!client->creator->on_channel_delete.empty()) {
dpp::channel_delete_t cd(client, raw);
channel_delete_t cd(client, raw);
cd.deleted = c;
cd.deleting_guild = g;
client->creator->on_channel_delete.call(cd);
Expand Down
4 changes: 0 additions & 4 deletions src/dpp/events/channel_pins_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@


namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
*
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/channel_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/guild_audit_log_entry_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;


/**
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/guild_ban_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;


/**
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/guild_ban_remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;


/**
Expand Down
4 changes: 0 additions & 4 deletions src/dpp/events/guild_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@


namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
*
Expand Down
13 changes: 7 additions & 6 deletions src/dpp/events/guild_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@


namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
*
Expand All @@ -43,7 +39,11 @@ using namespace dpp;
void guild_delete::handle(discord_client* client, json &j, const std::string &raw) {
json& d = j["d"];
dpp::guild* g = dpp::find_guild(snowflake_not_null(&d, "id"));
if (g) {
dpp::guild guild_del;
if (!g) {
guild_del.fill_from_json(&d);
} else {
guild_del = *g;
if (!bool_not_null(&d, "unavailable")) {
dpp::get_guild_cache()->remove(g);
if (client->creator->cache_policy.emoji_policy != dpp::cp_none) {
Expand Down Expand Up @@ -88,7 +88,8 @@ void guild_delete::handle(discord_client* client, json &j, const std::string &ra

if (!client->creator->on_guild_delete.empty()) {
dpp::guild_delete_t gd(client, raw);
gd.deleted = g;
gd.deleted = guild_del;
gd.guild_id = guild_del.id;
client->creator->on_guild_delete.call(gd);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/guild_emojis_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;


/**
Expand Down
4 changes: 0 additions & 4 deletions src/dpp/events/guild_integrations_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@


namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
*
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/guild_join_request_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/guild_member_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
Expand Down
44 changes: 15 additions & 29 deletions src/dpp/events/guild_member_remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
Expand All @@ -42,37 +40,25 @@ void guild_member_remove::handle(discord_client* client, json &j, const std::str
json d = j["d"];

dpp::guild_member_remove_t gmr(client, raw);
gmr.removed.fill_from_json(&(d["user"]));
gmr.guild_id = snowflake_not_null(&d, "guild_id");
gmr.removing_guild = dpp::find_guild(gmr.guild_id);

gmr.removing_guild = dpp::find_guild(snowflake_not_null(&d, "guild_id"));

if (client->creator->cache_policy.user_policy == dpp::cp_none) {
dpp::user u;
u.fill_from_json(&(d["user"]));
gmr.removed = &u;
if (!client->creator->on_guild_member_remove.empty()) {
client->creator->on_guild_member_remove.call(gmr);
}
} else {

gmr.removed = dpp::find_user(snowflake_not_null(&(d["user"]), "id"));

if (!client->creator->on_guild_member_remove.empty()) {
client->creator->on_guild_member_remove.call(gmr);
}
if (!client->creator->on_guild_member_remove.empty()) {
client->creator->on_guild_member_remove.call(gmr);
}

if (gmr.removing_guild && gmr.removed) {
auto i = gmr.removing_guild->members.find(gmr.removed->id);
if (i != gmr.removing_guild->members.end()) {
dpp::user* u = dpp::find_user(gmr.removed->id);
if (u) {
u->refcount--;
if (u->refcount < 1) {
dpp::get_user_cache()->remove(u);
}
if (client->creator->cache_policy.user_policy != dpp::cp_none && gmr.removing_guild) {
auto i = gmr.removing_guild->members.find(gmr.removed.id);
if (i != gmr.removing_guild->members.end()) {
dpp::user* u = dpp::find_user(gmr.removed.id);
if (u) {
u->refcount--;
if (u->refcount < 1) {
dpp::get_user_cache()->remove(u);
}
gmr.removing_guild->members.erase(i);
}

gmr.removing_guild->members.erase(i);
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/guild_member_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/guild_members_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
Expand Down
2 changes: 0 additions & 2 deletions src/dpp/events/guild_role_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@

namespace dpp::events {

using json = nlohmann::json;
using namespace dpp;

/**
* @brief Handle event
Expand Down
Loading

0 comments on commit 2cfaeb5

Please sign in to comment.