From 67dc0b703e6255483b587cfd4e8cdac89f999d19 Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Sat, 16 Nov 2024 14:04:58 +0000 Subject: [PATCH] put websocket events into the work queue --- src/dpp/events/guild_role_update.cpp | 8 +++-- .../events/guild_scheduled_event_create.cpp | 4 ++- .../events/guild_scheduled_event_delete.cpp | 4 ++- .../events/guild_scheduled_event_update.cpp | 4 ++- .../events/guild_scheduled_event_user_add.cpp | 4 ++- .../guild_scheduled_event_user_remove.cpp | 4 ++- src/dpp/events/guild_stickers_update.cpp | 4 ++- src/dpp/events/guild_update.cpp | 4 ++- src/dpp/events/integration_create.cpp | 4 ++- src/dpp/events/integration_delete.cpp | 4 ++- src/dpp/events/integration_update.cpp | 4 ++- src/dpp/events/interaction_create.cpp | 32 ++++++++++++++----- src/dpp/events/invite_create.cpp | 4 ++- src/dpp/events/invite_delete.cpp | 4 ++- src/dpp/events/message_create.cpp | 4 ++- src/dpp/events/message_delete.cpp | 4 ++- src/dpp/events/message_delete_bulk.cpp | 4 ++- src/dpp/events/message_poll_vote_add.cpp | 4 ++- src/dpp/events/message_poll_vote_remove.cpp | 4 ++- src/dpp/events/message_reaction_add.cpp | 4 ++- src/dpp/events/message_reaction_remove.cpp | 4 ++- .../events/message_reaction_remove_all.cpp | 4 ++- .../events/message_reaction_remove_emoji.cpp | 4 ++- src/dpp/events/message_update.cpp | 4 ++- src/dpp/events/presence_update.cpp | 4 ++- src/dpp/events/ready.cpp | 4 ++- src/dpp/events/resumed.cpp | 4 ++- src/dpp/events/stage_instance_create.cpp | 4 ++- src/dpp/events/stage_instance_delete.cpp | 4 ++- src/dpp/events/stage_instance_update.cpp | 4 ++- src/dpp/events/thread_create.cpp | 4 ++- src/dpp/events/thread_delete.cpp | 4 ++- src/dpp/events/thread_list_sync.cpp | 4 ++- src/dpp/events/thread_member_update.cpp | 4 ++- src/dpp/events/thread_members_update.cpp | 4 ++- src/dpp/events/thread_update.cpp | 4 ++- src/dpp/events/typing_start.cpp | 4 ++- src/dpp/events/user_update.cpp | 8 +++-- src/dpp/events/voice_server_update.cpp | 4 ++- src/dpp/events/voice_state_update.cpp | 4 ++- src/dpp/events/webhooks_update.cpp | 4 ++- 41 files changed, 150 insertions(+), 50 deletions(-) diff --git a/src/dpp/events/guild_role_update.cpp b/src/dpp/events/guild_role_update.cpp index 83a348e271..6f8ca5a691 100644 --- a/src/dpp/events/guild_role_update.cpp +++ b/src/dpp/events/guild_role_update.cpp @@ -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"]; @@ -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); + }); } } } diff --git a/src/dpp/events/guild_scheduled_event_create.cpp b/src/dpp/events/guild_scheduled_event_create.cpp index 15414756a9..0ada5b1c3e 100644 --- a/src/dpp/events/guild_scheduled_event_create.cpp +++ b/src/dpp/events/guild_scheduled_event_create.cpp @@ -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); + }); } } diff --git a/src/dpp/events/guild_scheduled_event_delete.cpp b/src/dpp/events/guild_scheduled_event_delete.cpp index 4552743d86..0db680efbf 100644 --- a/src/dpp/events/guild_scheduled_event_delete.cpp +++ b/src/dpp/events/guild_scheduled_event_delete.cpp @@ -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); + }); } } diff --git a/src/dpp/events/guild_scheduled_event_update.cpp b/src/dpp/events/guild_scheduled_event_update.cpp index 7f297879a7..87affe33fc 100644 --- a/src/dpp/events/guild_scheduled_event_update.cpp +++ b/src/dpp/events/guild_scheduled_event_update.cpp @@ -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); + }); } } diff --git a/src/dpp/events/guild_scheduled_event_user_add.cpp b/src/dpp/events/guild_scheduled_event_user_add.cpp index deecd3ff3f..714d4f4c1a 100644 --- a/src/dpp/events/guild_scheduled_event_user_add.cpp +++ b/src/dpp/events/guild_scheduled_event_user_add.cpp @@ -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); + }); } } diff --git a/src/dpp/events/guild_scheduled_event_user_remove.cpp b/src/dpp/events/guild_scheduled_event_user_remove.cpp index 64e4d31106..685bd5cfcc 100644 --- a/src/dpp/events/guild_scheduled_event_user_remove.cpp +++ b/src/dpp/events/guild_scheduled_event_user_remove.cpp @@ -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); + }); } } diff --git a/src/dpp/events/guild_stickers_update.cpp b/src/dpp/events/guild_stickers_update.cpp index d6b4e16237..5bf7831c0b 100644 --- a/src/dpp/events/guild_stickers_update.cpp +++ b/src/dpp/events/guild_stickers_update.cpp @@ -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); + }); } } diff --git a/src/dpp/events/guild_update.cpp b/src/dpp/events/guild_update.cpp index 4f96fa698e..0b75360076 100644 --- a/src/dpp/events/guild_update.cpp +++ b/src/dpp/events/guild_update.cpp @@ -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); + }); } } diff --git a/src/dpp/events/integration_create.cpp b/src/dpp/events/integration_create.cpp index 13b475ab9d..b7101482a7 100644 --- a/src/dpp/events/integration_create.cpp +++ b/src/dpp/events/integration_create.cpp @@ -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); + }); } } diff --git a/src/dpp/events/integration_delete.cpp b/src/dpp/events/integration_delete.cpp index 8dce94a072..94a6acde24 100644 --- a/src/dpp/events/integration_delete.cpp +++ b/src/dpp/events/integration_delete.cpp @@ -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); + }); } } diff --git a/src/dpp/events/integration_update.cpp b/src/dpp/events/integration_update.cpp index aad1ab66c8..9fed3bb708 100644 --- a/src/dpp/events/integration_update.cpp +++ b/src/dpp/events/integration_update.cpp @@ -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); + }); } } diff --git a/src/dpp/events/interaction_create.cpp b/src/dpp/events/interaction_create.cpp index 37919206ce..6c46349a7f 100644 --- a/src/dpp/events/interaction_create.cpp +++ b/src/dpp/events/interaction_create.cpp @@ -102,7 +102,9 @@ 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()) { @@ -110,12 +112,16 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri 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 @@ -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()) { @@ -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} @@ -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(i.data); @@ -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 || @@ -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); + }); } } } diff --git a/src/dpp/events/invite_create.cpp b/src/dpp/events/invite_create.cpp index 626ac857e8..dccdcf377d 100644 --- a/src/dpp/events/invite_create.cpp +++ b/src/dpp/events/invite_create.cpp @@ -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); + }); } } diff --git a/src/dpp/events/invite_delete.cpp b/src/dpp/events/invite_delete.cpp index bd121f6105..cb9eb5acf2 100644 --- a/src/dpp/events/invite_delete.cpp +++ b/src/dpp/events/invite_delete.cpp @@ -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); + }); } } diff --git a/src/dpp/events/message_create.cpp b/src/dpp/events/message_create.cpp index a1ce729b7b..e017438ab8 100644 --- a/src/dpp/events/message_create.cpp +++ b/src/dpp/events/message_create.cpp @@ -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); + }); } } diff --git a/src/dpp/events/message_delete.cpp b/src/dpp/events/message_delete.cpp index 60f0e97d81..c76f5fc5a1 100644 --- a/src/dpp/events/message_delete.cpp +++ b/src/dpp/events/message_delete.cpp @@ -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); + }); } } diff --git a/src/dpp/events/message_delete_bulk.cpp b/src/dpp/events/message_delete_bulk.cpp index 394d408fb2..554d4f6f59 100644 --- a/src/dpp/events/message_delete_bulk.cpp +++ b/src/dpp/events/message_delete_bulk.cpp @@ -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(m.get())); } - client->creator->on_message_delete_bulk.call(msg); + client->creator->queue_work(1, [client, msg]() { + client->creator->on_message_delete_bulk.call(msg); + }); } } diff --git a/src/dpp/events/message_poll_vote_add.cpp b/src/dpp/events/message_poll_vote_add.cpp index 319d809e9c..de957e9f41 100644 --- a/src/dpp/events/message_poll_vote_add.cpp +++ b/src/dpp/events/message_poll_vote_add.cpp @@ -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); + }); } } diff --git a/src/dpp/events/message_poll_vote_remove.cpp b/src/dpp/events/message_poll_vote_remove.cpp index 55c243e767..3d4cb0eb13 100644 --- a/src/dpp/events/message_poll_vote_remove.cpp +++ b/src/dpp/events/message_poll_vote_remove.cpp @@ -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); + }); } } diff --git a/src/dpp/events/message_reaction_add.cpp b/src/dpp/events/message_reaction_add.cpp index 88a2d05608..ccb28ace04 100644 --- a/src/dpp/events/message_reaction_add.cpp +++ b/src/dpp/events/message_reaction_add.cpp @@ -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); + }); } } } diff --git a/src/dpp/events/message_reaction_remove.cpp b/src/dpp/events/message_reaction_remove.cpp index 36b367c9cb..794f84c583 100644 --- a/src/dpp/events/message_reaction_remove.cpp +++ b/src/dpp/events/message_reaction_remove.cpp @@ -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); + }); } } } diff --git a/src/dpp/events/message_reaction_remove_all.cpp b/src/dpp/events/message_reaction_remove_all.cpp index 71fa31b873..dd0ae2de61 100644 --- a/src/dpp/events/message_reaction_remove_all.cpp +++ b/src/dpp/events/message_reaction_remove_all.cpp @@ -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); + }); } } } diff --git a/src/dpp/events/message_reaction_remove_emoji.cpp b/src/dpp/events/message_reaction_remove_emoji.cpp index 97002b4992..4de8ae7326 100644 --- a/src/dpp/events/message_reaction_remove_emoji.cpp +++ b/src/dpp/events/message_reaction_remove_emoji.cpp @@ -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); + }); } } diff --git a/src/dpp/events/message_update.cpp b/src/dpp/events/message_update.cpp index 4b6490a1f2..9f3408dba0 100644 --- a/src/dpp/events/message_update.cpp +++ b/src/dpp/events/message_update.cpp @@ -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); + }); } } diff --git a/src/dpp/events/presence_update.cpp b/src/dpp/events/presence_update.cpp index 4238efb378..24ab26d111 100644 --- a/src/dpp/events/presence_update.cpp +++ b/src/dpp/events/presence_update.cpp @@ -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); + }); } } diff --git a/src/dpp/events/ready.cpp b/src/dpp/events/ready.cpp index 7990293d98..b319b91f69 100644 --- a/src/dpp/events/ready.cpp +++ b/src/dpp/events/ready.cpp @@ -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); + }); } } diff --git a/src/dpp/events/resumed.cpp b/src/dpp/events/resumed.cpp index b70db335ef..4fbe77023a 100644 --- a/src/dpp/events/resumed.cpp +++ b/src/dpp/events/resumed.cpp @@ -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); + }); } } diff --git a/src/dpp/events/stage_instance_create.cpp b/src/dpp/events/stage_instance_create.cpp index fbbc3099e5..47f50382a5 100644 --- a/src/dpp/events/stage_instance_create.cpp +++ b/src/dpp/events/stage_instance_create.cpp @@ -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); + }); } } diff --git a/src/dpp/events/stage_instance_delete.cpp b/src/dpp/events/stage_instance_delete.cpp index 54d8459dd5..c5f6dbb26e 100644 --- a/src/dpp/events/stage_instance_delete.cpp +++ b/src/dpp/events/stage_instance_delete.cpp @@ -39,7 +39,9 @@ void stage_instance_delete::handle(discord_client* client, json &j, const std::s json& d = j["d"]; dpp::stage_instance_delete_t sid(client, raw); sid.deleted.fill_from_json(&d); - client->creator->on_stage_instance_delete.call(sid); + client->creator->queue_work(1, [client, sid]() { + client->creator->on_stage_instance_delete.call(sid); + }); } } diff --git a/src/dpp/events/stage_instance_update.cpp b/src/dpp/events/stage_instance_update.cpp index 8b2188f998..29b4cf066d 100644 --- a/src/dpp/events/stage_instance_update.cpp +++ b/src/dpp/events/stage_instance_update.cpp @@ -41,7 +41,9 @@ void stage_instance_update::handle(discord_client* client, json &j, const std::s json& d = j["d"]; dpp::stage_instance_update_t siu(client, raw); siu.updated.fill_from_json(&d); - client->creator->on_stage_instance_update.call(siu); + client->creator->queue_work(1, [client, siu]() { + client->creator->on_stage_instance_update.call(siu); + }); } } diff --git a/src/dpp/events/thread_create.cpp b/src/dpp/events/thread_create.cpp index 7e1993a6ee..51a59779e5 100644 --- a/src/dpp/events/thread_create.cpp +++ b/src/dpp/events/thread_create.cpp @@ -42,7 +42,9 @@ void thread_create::handle(discord_client* client, json& j, const std::string& r dpp::thread_create_t tc(client, raw); tc.created = t; tc.creating_guild = g; - client->creator->on_thread_create.call(tc); + client->creator->queue_work(1, [client, tc]() { + client->creator->on_thread_create.call(tc); + }); } } }; diff --git a/src/dpp/events/thread_delete.cpp b/src/dpp/events/thread_delete.cpp index b4bfc45710..f9fd5cd2b8 100644 --- a/src/dpp/events/thread_delete.cpp +++ b/src/dpp/events/thread_delete.cpp @@ -42,7 +42,9 @@ void thread_delete::handle(discord_client* client, json& j, const std::string& r dpp::thread_delete_t td(client, raw); td.deleted = t; td.deleting_guild = g; - client->creator->on_thread_delete.call(td); + client->creator->queue_work(1, [client, td]() { + client->creator->on_thread_delete.call(td); + }); } } }; diff --git a/src/dpp/events/thread_list_sync.cpp b/src/dpp/events/thread_list_sync.cpp index 3f850f7950..45dbbd1b9e 100644 --- a/src/dpp/events/thread_list_sync.cpp +++ b/src/dpp/events/thread_list_sync.cpp @@ -52,7 +52,9 @@ void thread_list_sync::handle(discord_client* client, json& j, const std::string tls.members.push_back(thread_member().fill_from_json(&tm)); } } - client->creator->on_thread_list_sync.call(tls); + client->creator->queue_work(1, [client, tls]() { + client->creator->on_thread_list_sync.call(tls); + }); } } }; diff --git a/src/dpp/events/thread_member_update.cpp b/src/dpp/events/thread_member_update.cpp index e4407b425b..84a97e5603 100644 --- a/src/dpp/events/thread_member_update.cpp +++ b/src/dpp/events/thread_member_update.cpp @@ -34,7 +34,9 @@ void thread_member_update::handle(discord_client* client, json& j, const std::st json& d = j["d"]; dpp::thread_member_update_t tm(client, raw); tm.updated = thread_member().fill_from_json(&d); - client->creator->on_thread_member_update.call(tm); + client->creator->queue_work(1, [client, tm]() { + client->creator->on_thread_member_update.call(tm); + }); } } }; diff --git a/src/dpp/events/thread_members_update.cpp b/src/dpp/events/thread_members_update.cpp index 90d2fa5cb1..aba9bedf98 100644 --- a/src/dpp/events/thread_members_update.cpp +++ b/src/dpp/events/thread_members_update.cpp @@ -52,7 +52,9 @@ void thread_members_update::handle(discord_client* client, json& j, const std::s client->creator->log(dpp::ll_error, std::string("thread_members_update: {}") + e.what()); } } - client->creator->on_thread_members_update.call(tms); + client->creator->queue_work(1, [client, tms]() { + client->creator->on_thread_members_update.call(tms); + }); } } }; diff --git a/src/dpp/events/thread_update.cpp b/src/dpp/events/thread_update.cpp index 7d92c9fd4e..e6fa3bec80 100644 --- a/src/dpp/events/thread_update.cpp +++ b/src/dpp/events/thread_update.cpp @@ -38,7 +38,9 @@ void thread_update::handle(discord_client* client, json& j, const std::string& r dpp::thread_update_t tu(client, raw); tu.updated = t; tu.updating_guild = g; - client->creator->on_thread_update.call(tu); + client->creator->queue_work(1, [client, tu]() { + client->creator->on_thread_update.call(tu); + }); } } }; diff --git a/src/dpp/events/typing_start.cpp b/src/dpp/events/typing_start.cpp index b5334c9f54..4ffc231e8f 100644 --- a/src/dpp/events/typing_start.cpp +++ b/src/dpp/events/typing_start.cpp @@ -43,7 +43,9 @@ void typing_start::handle(discord_client* client, json &j, const std::string &ra ts.user_id = snowflake_not_null(&d, "user_id"); ts.typing_user = dpp::find_user(ts.user_id); ts.timestamp = ts_not_null(&d, "timestamp"); - client->creator->on_typing_start.call(ts); + client->creator->queue_work(1, [client, ts]() { + client->creator->on_typing_start.call(ts); + }); } } diff --git a/src/dpp/events/user_update.cpp b/src/dpp/events/user_update.cpp index b954b55c27..d018825c87 100644 --- a/src/dpp/events/user_update.cpp +++ b/src/dpp/events/user_update.cpp @@ -49,7 +49,9 @@ void user_update::handle(discord_client* client, json &j, const std::string &raw if (!client->creator->on_user_update.empty()) { dpp::user_update_t uu(client, raw); uu.updated = *u; - client->creator->on_user_update.call(uu); + client->creator->queue_work(1, [client, uu]() { + client->creator->on_user_update.call(uu); + }); } } else { if (!client->creator->on_user_update.empty()) { @@ -57,7 +59,9 @@ void user_update::handle(discord_client* client, json &j, const std::string &raw u.fill_from_json(&d); dpp::user_update_t uu(client, raw); uu.updated = u; - client->creator->on_user_update.call(uu); + client->creator->queue_work(1, [client, uu]() { + client->creator->on_user_update.call(uu); + }); } } } diff --git a/src/dpp/events/voice_server_update.cpp b/src/dpp/events/voice_server_update.cpp index 14cf9f77b8..ea1c8e07d5 100644 --- a/src/dpp/events/voice_server_update.cpp +++ b/src/dpp/events/voice_server_update.cpp @@ -60,7 +60,9 @@ void voice_server_update::handle(discord_client* client, json &j, const std::str } if (!client->creator->on_voice_server_update.empty()) { - client->creator->on_voice_server_update.call(vsu); + client->creator->queue_work(1, [client, vsu]() { + client->creator->on_voice_server_update.call(vsu); + }); } } diff --git a/src/dpp/events/voice_state_update.cpp b/src/dpp/events/voice_state_update.cpp index 7be7b18515..7831564b7f 100644 --- a/src/dpp/events/voice_state_update.cpp +++ b/src/dpp/events/voice_state_update.cpp @@ -84,7 +84,9 @@ void voice_state_update::handle(discord_client* client, json &j, const std::stri } if (!client->creator->on_voice_state_update.empty()) { - client->creator->on_voice_state_update.call(vsu); + client->creator->queue_work(1, [client, vsu]() { + client->creator->on_voice_state_update.call(vsu); + }); } } diff --git a/src/dpp/events/webhooks_update.cpp b/src/dpp/events/webhooks_update.cpp index 4f676eeade..bf4ea4ae96 100644 --- a/src/dpp/events/webhooks_update.cpp +++ b/src/dpp/events/webhooks_update.cpp @@ -41,7 +41,9 @@ void webhooks_update::handle(discord_client* client, json &j, const std::string dpp::webhooks_update_t wu(client, raw); wu.webhook_guild = dpp::find_guild(snowflake_not_null(&d, "guild_id")); wu.webhook_channel = dpp::find_channel(snowflake_not_null(&d, "channel_id")); - client->creator->on_webhooks_update.call(wu); + client->creator->queue_work(1, [client, wu]() { + client->creator->on_webhooks_update.call(wu); + }); } }