Skip to content

Commit

Permalink
put websocket events into the work queue
Browse files Browse the repository at this point in the history
  • Loading branch information
braindigitalis committed Nov 16, 2024
1 parent 3917ec7 commit 67dc0b7
Show file tree
Hide file tree
Showing 41 changed files with 150 additions and 50 deletions.
8 changes: 6 additions & 2 deletions src/dpp/events/guild_role_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ void guild_role_update::handle(discord_client* client, json &j, const std::strin
dpp::guild_role_update_t gru(client, raw);
gru.updating_guild = g;
gru.updated = &r;
client->creator->on_guild_role_update.call(gru);
client->creator->queue_work(1, [client, gru]() {
client->creator->on_guild_role_update.call(gru);
});
}
} else {
json& role = d["role"];
Expand All @@ -58,7 +60,9 @@ void guild_role_update::handle(discord_client* client, json &j, const std::strin
dpp::guild_role_update_t gru(client, raw);
gru.updating_guild = g;
gru.updated = r;
client->creator->on_guild_role_update.call(gru);
client->creator->queue_work(1, [client, gru]() {
client->creator->on_guild_role_update.call(gru);
});
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/guild_scheduled_event_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ void guild_scheduled_event_create::handle(discord_client* client, json &j, const
if (!client->creator->on_guild_scheduled_event_create.empty()) {
dpp::guild_scheduled_event_create_t ec(client, raw);
ec.created.fill_from_json(&d);
client->creator->on_guild_scheduled_event_create.call(ec);
client->creator->queue_work(1, [client, ec]() {
client->creator->on_guild_scheduled_event_create.call(ec);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/guild_scheduled_event_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ void guild_scheduled_event_delete::handle(discord_client* client, json &j, const
if (!client->creator->on_guild_scheduled_event_delete.empty()) {
dpp::guild_scheduled_event_delete_t ed(client, raw);
ed.deleted.fill_from_json(&d);
client->creator->on_guild_scheduled_event_delete.call(ed);
client->creator->queue_work(1, [client, ed]() {
client->creator->on_guild_scheduled_event_delete.call(ed);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/guild_scheduled_event_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ void guild_scheduled_event_update::handle(discord_client* client, json &j, const
if (!client->creator->on_guild_scheduled_event_update.empty()) {
dpp::guild_scheduled_event_update_t eu(client, raw);
eu.updated.fill_from_json(&d);
client->creator->on_guild_scheduled_event_update.call(eu);
client->creator->queue_work(1, [client, eu]() {
client->creator->on_guild_scheduled_event_update.call(eu);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/guild_scheduled_event_user_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ void guild_scheduled_event_user_add::handle(discord_client* client, json &j, con
eua.guild_id = snowflake_not_null(&d, "guild_id");
eua.user_id = snowflake_not_null(&d, "user_id");
eua.event_id = snowflake_not_null(&d, "guild_scheduled_event_id");
client->creator->on_guild_scheduled_event_user_add.call(eua);
client->creator->queue_work(1, [client, eua]() {
client->creator->on_guild_scheduled_event_user_add.call(eua);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/guild_scheduled_event_user_remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ void guild_scheduled_event_user_remove::handle(discord_client* client, json &j,
eur.guild_id = snowflake_not_null(&d, "guild_id");
eur.user_id = snowflake_not_null(&d, "user_id");
eur.event_id = snowflake_not_null(&d, "guild_scheduled_event_id");
client->creator->on_guild_scheduled_event_user_remove.call(eur);
client->creator->queue_work(1, [client, eur]() {
client->creator->on_guild_scheduled_event_user_remove.call(eur);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/guild_stickers_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ void guild_stickers_update::handle(discord_client* client, json &j, const std::s
gsu.stickers.emplace_back(s);
}
gsu.updating_guild = g;
client->creator->on_guild_stickers_update.call(gsu);
client->creator->queue_work(1, [client, gsu]() {
client->creator->on_guild_stickers_update.call(gsu);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/guild_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ void guild_update::handle(discord_client* client, json &j, const std::string &ra
if (!client->creator->on_guild_update.empty()) {
dpp::guild_update_t gu(client, raw);
gu.updated = g;
client->creator->on_guild_update.call(gu);
client->creator->queue_work(1, [client, gu]() {
client->creator->on_guild_update.call(gu);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/integration_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ void integration_create::handle(discord_client* client, json &j, const std::stri
json& d = j["d"];
dpp::integration_create_t ic(client, raw);
ic.created_integration = dpp::integration().fill_from_json(&d);
client->creator->on_integration_create.call(ic);
client->creator->queue_work(1, [client, ic]() {
client->creator->on_integration_create.call(ic);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/integration_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ void integration_delete::handle(discord_client* client, json &j, const std::stri
json& d = j["d"];
dpp::integration_delete_t id(client, raw);
id.deleted_integration = dpp::integration().fill_from_json(&d);
client->creator->on_integration_delete.call(id);
client->creator->queue_work(1, [client, id]() {
client->creator->on_integration_delete.call(id);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/integration_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ void integration_update::handle(discord_client* client, json &j, const std::stri
json& d = j["d"];
dpp::integration_update_t iu(client, raw);
iu.updated_integration = dpp::integration().fill_from_json(&d);
client->creator->on_integration_update.call(iu);
client->creator->queue_work(1, [client, iu]() {
client->creator->on_integration_update.call(iu);
});
}
}

Expand Down
32 changes: 24 additions & 8 deletions src/dpp/events/interaction_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,26 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri
message_context_menu_t mcm(client, raw);
mcm.command = i;
mcm.set_message(i.resolved.messages.begin()->second);
client->creator->on_message_context_menu.call(mcm);
client->creator->queue_work(1, [client, mcm]() {
client->creator->on_message_context_menu.call(mcm);
});
}
} else if (cmd_data.type == ctxm_user && !client->creator->on_user_context_menu.empty()) {
if (i.resolved.users.size()) {
/* User right-click context menu */
user_context_menu_t ucm(client, raw);
ucm.command = i;
ucm.set_user(i.resolved.users.begin()->second);
client->creator->on_user_context_menu.call(ucm);
client->creator->queue_work(1, [client, ucm]() {
client->creator->on_user_context_menu.call(ucm);
});
}
} else if (cmd_data.type == ctxm_chat_input && !client->creator->on_slashcommand.empty()) {
dpp::slashcommand_t sc(client, raw);
sc.command = i;
client->creator->on_slashcommand.call(sc);
client->creator->queue_work(1, [client, sc]() {
client->creator->on_slashcommand.call(sc);
});
}
if (!client->creator->on_interaction_create.empty()) {
/* Standard chat input. Note that for backwards compatibility, context menu
Expand All @@ -124,7 +130,9 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri
*/
dpp::interaction_create_t ic(client, raw);
ic.command = i;
client->creator->on_interaction_create.call(ic);
client->creator->queue_work(1, [client, ic]() {
client->creator->on_interaction_create.call(ic);
});
}
} else if (i.type == it_modal_submit) {
if (!client->creator->on_form_submit.empty()) {
Expand All @@ -134,7 +142,9 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri
for (auto & c : d["data"]["components"]) {
fs.components.push_back(dpp::component().fill_from_json(&c));
}
client->creator->on_form_submit.call(fs);
client->creator->queue_work(1, [client, fs]() {
client->creator->on_form_submit.call(fs);
});
}
} else if (i.type == it_autocomplete) {
// "data":{"id":"903319628816728104","name":"blep","options":[{"focused":true,"name":"animal","type":3,"value":"a"}],"type":1}
Expand All @@ -144,7 +154,9 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri
ac.name = string_not_null(&(d["data"]), "name");
fill_options(d["data"]["options"], ac.options);
ac.command = i;
client->creator->on_autocomplete.call(ac);
client->creator->queue_work(1, [client, ac]() {
client->creator->on_autocomplete.call(ac);
});
}
} else if (i.type == it_component_button) {
dpp::component_interaction bi = std::get<component_interaction>(i.data);
Expand All @@ -154,7 +166,9 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri
ic.command = i;
ic.custom_id = bi.custom_id;
ic.component_type = bi.component_type;
client->creator->on_button_click.call(ic);
client->creator->queue_work(1, [client, ic]() {
client->creator->on_button_click.call(ic);
});
}
} else if (bi.component_type == cot_selectmenu || bi.component_type == cot_user_selectmenu ||
bi.component_type == cot_role_selectmenu || bi.component_type == cot_mentionable_selectmenu ||
Expand All @@ -165,7 +179,9 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri
ic.custom_id = bi.custom_id;
ic.component_type = bi.component_type;
ic.values = bi.values;
client->creator->on_select_click.call(ic);
client->creator->queue_work(1, [client, ic]() {
client->creator->on_select_click.call(ic);
});
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/invite_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ void invite_create::handle(discord_client* client, json &j, const std::string &r
json& d = j["d"];
dpp::invite_create_t ci(client, raw);
ci.created_invite = dpp::invite().fill_from_json(&d);
client->creator->on_invite_create.call(ci);
client->creator->queue_work(1, [client, ci]() {
client->creator->on_invite_create.call(ci);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/invite_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ void invite_delete::handle(discord_client* client, json &j, const std::string &r
json& d = j["d"];
dpp::invite_delete_t cd(client, raw);
cd.deleted_invite = dpp::invite().fill_from_json(&d);
client->creator->on_invite_delete.call(cd);
client->creator->queue_work(1, [client, cd]() {
client->creator->on_invite_delete.call(cd);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/message_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ void message_create::handle(discord_client* client, json &j, const std::string &
dpp::message_create_t msg(client, raw);
msg.msg.fill_from_json(&d, client->creator->cache_policy);
msg.msg.owner = client->creator;
client->creator->on_message_create.call(msg);
client->creator->queue_work(1, [client, msg]() {
client->creator->on_message_create.call(msg);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/message_delete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ void message_delete::handle(discord_client* client, json &j, const std::string &
msg.id = snowflake_not_null(&d, "id");
msg.guild_id = snowflake_not_null(&d, "guild_id");
msg.channel_id = snowflake_not_null(&d, "channel_id");
client->creator->on_message_delete.call(msg);
client->creator->queue_work(1, [client, msg]() {
client->creator->on_message_delete.call(msg);
});
}

}
Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/message_delete_bulk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ void message_delete_bulk::handle(discord_client* client, json &j, const std::str
for (auto& m : d["ids"]) {
msg.deleted.push_back(from_string<uint64_t>(m.get<std::string>()));
}
client->creator->on_message_delete_bulk.call(msg);
client->creator->queue_work(1, [client, msg]() {
client->creator->on_message_delete_bulk.call(msg);
});
}

}
Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/message_poll_vote_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ void message_poll_vote_add::handle(discord_client* client, json &j, const std::s
vote.channel_id = snowflake_not_null(&j, "channel_id");
vote.guild_id = snowflake_not_null(&j, "guild_id");
vote.answer_id = int32_not_null(&j, "answer_id");
client->creator->on_message_poll_vote_add.call(vote);
client->creator->queue_work(1, [client, vote]() {
client->creator->on_message_poll_vote_add.call(vote);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/message_poll_vote_remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ void message_poll_vote_remove::handle(discord_client* client, json &j, const std
vote.channel_id = snowflake_not_null(&j, "channel_id");
vote.guild_id = snowflake_not_null(&j, "guild_id");
vote.answer_id = int32_not_null(&j, "answer_id");
client->creator->on_message_poll_vote_remove.call(vote);
client->creator->queue_work(1, [client, vote]() {
client->creator->on_message_poll_vote_remove.call(vote);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/message_reaction_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ void message_reaction_add::handle(discord_client* client, json &j, const std::st
mra.message_author_id = snowflake_not_null(&d, "message_author_id");
mra.reacting_emoji = dpp::emoji().fill_from_json(&(d["emoji"]));
if (mra.channel_id && mra.message_id) {
client->creator->on_message_reaction_add.call(mra);
client->creator->queue_work(1, [client, mra]() {
client->creator->on_message_reaction_add.call(mra);
});
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/message_reaction_remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ void message_reaction_remove::handle(discord_client* client, json &j, const std:
mrr.message_id = snowflake_not_null(&d, "message_id");
mrr.reacting_emoji = dpp::emoji().fill_from_json(&(d["emoji"]));
if (mrr.channel_id && mrr.message_id) {
client->creator->on_message_reaction_remove.call(mrr);
client->creator->queue_work(1, [client, mrr]() {
client->creator->on_message_reaction_remove.call(mrr);
});
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/message_reaction_remove_all.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ void message_reaction_remove_all::handle(discord_client* client, json &j, const
mrra.reacting_channel = dpp::find_channel(mrra.channel_id);
mrra.message_id = snowflake_not_null(&d, "message_id");
if (mrra.channel_id && mrra.message_id) {
client->creator->on_message_reaction_remove_all.call(mrra);
client->creator->queue_work(1, [client, mrra]() {
client->creator->on_message_reaction_remove_all.call(mrra);
});
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/message_reaction_remove_emoji.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ void message_reaction_remove_emoji::handle(discord_client* client, json &j, cons
mrre.message_id = snowflake_not_null(&d, "message_id");
mrre.reacting_emoji = dpp::emoji().fill_from_json(&(d["emoji"]));
if (mrre.channel_id && mrre.message_id) {
client->creator->on_message_reaction_remove_emoji.call(mrre);
client->creator->queue_work(1, [client, mrre]() {
client->creator->on_message_reaction_remove_emoji.call(mrre);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/message_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ void message_update::handle(discord_client* client, json &j, const std::string &
dpp::message m(client->creator);
m.fill_from_json(&d);
msg.msg = m;
client->creator->on_message_update.call(msg);
client->creator->queue_work(1, [client, msg]() {
client->creator->on_message_update.call(msg);
});
}

}
Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/presence_update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ void presence_update::handle(discord_client* client, json &j, const std::string
json& d = j["d"];
dpp::presence_update_t pu(client, raw);
pu.rich_presence = dpp::presence().fill_from_json(&d);
client->creator->on_presence_update.call(pu);
client->creator->queue_work(1, [client, pu]() {
client->creator->on_presence_update.call(pu);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/ready.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ void ready::handle(discord_client* client, json &j, const std::string &raw) {
r.guilds.emplace_back(snowflake_not_null(&guild, "id"));
}
r.guild_count = r.guilds.size();
client->creator->on_ready.call(r);
client->creator->queue_work(1, [client, r]() {
client->creator->on_ready.call(r);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/resumed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ void resumed::handle(discord_client* client, json &j, const std::string &raw) {
dpp::resumed_t r(client, raw);
r.session_id = client->sessionid;
r.shard_id = client->shard_id;
client->creator->on_resumed.call(r);
client->creator->queue_work(1, [client, r]() {
client->creator->on_resumed.call(r);
});
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/dpp/events/stage_instance_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ void stage_instance_create::handle(discord_client* client, json &j, const std::s
json& d = j["d"];
dpp::stage_instance_create_t sic(client, raw);
sic.created.fill_from_json(&d);
client->creator->on_stage_instance_create.call(sic);
client->creator->queue_work(1, [client, sic]() {
client->creator->on_stage_instance_create.call(sic);
});
}
}

Expand Down
Loading

0 comments on commit 67dc0b7

Please sign in to comment.