From 2190cf64b0bb1e446abe68716db05ee64fef25c4 Mon Sep 17 00:00:00 2001 From: Craig Edwards Date: Sat, 14 Dec 2024 00:30:58 +0000 Subject: [PATCH] make event.from safe in threads --- include/dpp/dispatcher.h | 34 ++++++++++------ src/dpp/cluster.cpp | 2 +- src/dpp/discordclient.cpp | 2 +- src/dpp/dispatcher.cpp | 40 ++++++++++--------- src/dpp/events/automod_rule_create.cpp | 2 +- src/dpp/events/automod_rule_delete.cpp | 2 +- src/dpp/events/automod_rule_execute.cpp | 2 +- src/dpp/events/automod_rule_update.cpp | 2 +- src/dpp/events/channel_create.cpp | 2 +- src/dpp/events/channel_delete.cpp | 2 +- src/dpp/events/channel_pins_update.cpp | 2 +- src/dpp/events/channel_update.cpp | 2 +- src/dpp/events/entitlement_create.cpp | 2 +- src/dpp/events/entitlement_delete.cpp | 2 +- src/dpp/events/entitlement_update.cpp | 2 +- .../events/guild_audit_log_entry_create.cpp | 2 +- src/dpp/events/guild_ban_add.cpp | 2 +- src/dpp/events/guild_ban_remove.cpp | 2 +- src/dpp/events/guild_create.cpp | 2 +- src/dpp/events/guild_delete.cpp | 2 +- src/dpp/events/guild_emojis_update.cpp | 2 +- src/dpp/events/guild_integrations_update.cpp | 2 +- src/dpp/events/guild_join_request_delete.cpp | 2 +- src/dpp/events/guild_member_add.cpp | 2 +- src/dpp/events/guild_member_remove.cpp | 2 +- src/dpp/events/guild_member_update.cpp | 4 +- src/dpp/events/guild_members_chunk.cpp | 2 +- src/dpp/events/guild_role_create.cpp | 4 +- src/dpp/events/guild_role_delete.cpp | 4 +- src/dpp/events/guild_role_update.cpp | 4 +- .../events/guild_scheduled_event_create.cpp | 2 +- .../events/guild_scheduled_event_delete.cpp | 2 +- .../events/guild_scheduled_event_update.cpp | 2 +- .../events/guild_scheduled_event_user_add.cpp | 2 +- .../guild_scheduled_event_user_remove.cpp | 2 +- src/dpp/events/guild_stickers_update.cpp | 2 +- src/dpp/events/guild_update.cpp | 2 +- src/dpp/events/integration_create.cpp | 2 +- src/dpp/events/integration_delete.cpp | 2 +- src/dpp/events/integration_update.cpp | 2 +- src/dpp/events/interaction_create.cpp | 16 ++++---- src/dpp/events/invite_create.cpp | 2 +- src/dpp/events/invite_delete.cpp | 2 +- src/dpp/events/logger.cpp | 4 +- src/dpp/events/message_create.cpp | 9 ++--- src/dpp/events/message_delete.cpp | 2 +- src/dpp/events/message_delete_bulk.cpp | 2 +- src/dpp/events/message_poll_vote_add.cpp | 2 +- src/dpp/events/message_poll_vote_remove.cpp | 2 +- src/dpp/events/message_reaction_add.cpp | 2 +- src/dpp/events/message_reaction_remove.cpp | 2 +- .../events/message_reaction_remove_all.cpp | 2 +- .../events/message_reaction_remove_emoji.cpp | 2 +- src/dpp/events/message_update.cpp | 2 +- src/dpp/events/presence_update.cpp | 2 +- src/dpp/events/ready.cpp | 2 +- src/dpp/events/resumed.cpp | 2 +- src/dpp/events/stage_instance_create.cpp | 2 +- src/dpp/events/stage_instance_delete.cpp | 2 +- src/dpp/events/stage_instance_update.cpp | 2 +- src/dpp/events/thread_create.cpp | 2 +- src/dpp/events/thread_delete.cpp | 2 +- src/dpp/events/thread_list_sync.cpp | 2 +- src/dpp/events/thread_member_update.cpp | 2 +- src/dpp/events/thread_members_update.cpp | 2 +- src/dpp/events/thread_update.cpp | 2 +- src/dpp/events/typing_start.cpp | 2 +- src/dpp/events/user_update.cpp | 4 +- src/dpp/events/voice_server_update.cpp | 2 +- src/dpp/events/voice_state_update.cpp | 2 +- src/dpp/events/webhooks_update.cpp | 2 +- src/dpp/voice/enabled/courier_loop.cpp | 4 +- src/dpp/voice/enabled/handle_frame.cpp | 10 ++--- src/dpp/voice/enabled/read_ready.cpp | 2 +- src/dpp/voice/enabled/write_ready.cpp | 4 +- src/unittest/coro.cpp | 2 +- src/unittest/test.cpp | 2 +- 77 files changed, 141 insertions(+), 128 deletions(-) diff --git a/include/dpp/dispatcher.h b/include/dpp/dispatcher.h index be08488b7b..dad53f509c 100644 --- a/include/dpp/dispatcher.h +++ b/include/dpp/dispatcher.h @@ -85,9 +85,13 @@ struct DPP_EXPORT event_dispatch_t { /** * @brief Shard the event came from. - * Note that for some events, notably voice events, this may be nullptr. */ - discord_client* from = nullptr; + uint32_t shard = 0; + + /** + * @brief Cluster owning the event dispatch + */ + dpp::cluster* owner = nullptr; /** * @brief Whether the event was cancelled using cancel_event(). @@ -116,18 +120,24 @@ struct DPP_EXPORT event_dispatch_t { /** * @brief Construct a new event_dispatch_t object * - * @param client The shard the event originated on. May be a nullptr, e.g. for voice events + * @param shard_id The shard the event originated on. * @param raw Raw event data as JSON or ETF */ - event_dispatch_t(discord_client* client, const std::string& raw); + event_dispatch_t(dpp::cluster* creator, uint32_t shard_id, const std::string& raw); + + /** + * @brief Returns the shard object for the events shard id + * @return discord client object + */ + discord_client* from() const; /** * @brief Construct a new event_dispatch_t object * - * @param client The shard the event originated on. May be a nullptr, e.g. for voice events + * @param shard_id The shard the event originated on. * @param raw Raw event data as JSON or ETF */ - event_dispatch_t(discord_client* client, std::string&& raw); + event_dispatch_t(dpp::cluster* creator, uint32_t shard_id, std::string&& raw); /** * @brief Copy another event_dispatch_t object @@ -2018,28 +2028,28 @@ struct DPP_EXPORT voice_receive_t : public event_dispatch_t { /** * @brief Construct a new voice receive t object * - * @param client The shard the event originated on. - * WILL ALWAYS be NULL. + * @param creator The creating cluster + * @param shard_id Shard the voice channel exists on * @param raw Raw event text as UDP packet. * @param vc owning voice client pointer * @param _user_id user id who is speaking, 0 for a mix of all user audio * @param pcm user audio to set * @param length length of user audio in bytes */ - voice_receive_t(discord_client* client, const std::string& raw, class discord_voice_client* vc, snowflake _user_id, const uint8_t* pcm, size_t length); + voice_receive_t(dpp::cluster* creator, uint32_t shard_id, const std::string& raw, class discord_voice_client* vc, snowflake _user_id, const uint8_t* pcm, size_t length); /** * @brief Construct a new voice receive t object * - * @param client The shard the event originated on. - * WILL ALWAYS be NULL. + * @param creator The creating cluster + * @param shard_id Shard the voice channel exists on * @param raw Raw event text as UDP packet. * @param vc owning voice client pointer * @param _user_id user id who is speaking, 0 for a mix of all user audio * @param pcm user audio to set * @param length length of user audio in bytes */ - voice_receive_t(discord_client* client, std::string&& raw, class discord_voice_client* vc, snowflake _user_id, const uint8_t* pcm, size_t length); + voice_receive_t(dpp::cluster* creator, uint32_t shard_id, std::string&& raw, class discord_voice_client* vc, snowflake _user_id, const uint8_t* pcm, size_t length); /** * @brief Voice client diff --git a/src/dpp/cluster.cpp b/src/dpp/cluster.cpp index f9b004da58..1169db32d2 100644 --- a/src/dpp/cluster.cpp +++ b/src/dpp/cluster.cpp @@ -185,7 +185,7 @@ void cluster::queue_work(int priority, work_unit task) { void cluster::log(dpp::loglevel severity, const std::string &msg) const { if (!on_log.empty()) { /* Pass to user if they've hooked the event */ - dpp::log_t logmsg(nullptr, msg); + dpp::log_t logmsg(nullptr, 0, msg); logmsg.severity = severity; logmsg.message = msg; size_t pos{0}; diff --git a/src/dpp/discordclient.cpp b/src/dpp/discordclient.cpp index 070681985d..0865069257 100644 --- a/src/dpp/discordclient.cpp +++ b/src/dpp/discordclient.cpp @@ -366,7 +366,7 @@ void discord_client::log(dpp::loglevel severity, const std::string &msg) const { if (!creator->on_log.empty()) { /* Pass to user if they've hooked the event */ - dpp::log_t logmsg(nullptr, msg); + dpp::log_t logmsg(creator, shard_id, msg); logmsg.severity = severity; logmsg.message = msg; size_t pos{0}; diff --git a/src/dpp/dispatcher.cpp b/src/dpp/dispatcher.cpp index db8ea2e888..314a1f1efe 100644 --- a/src/dpp/dispatcher.cpp +++ b/src/dpp/dispatcher.cpp @@ -31,9 +31,13 @@ namespace dpp { -event_dispatch_t::event_dispatch_t(discord_client* client, const std::string& raw) : raw_event(raw), from(client) {} +event_dispatch_t::event_dispatch_t(dpp::cluster* creator, uint32_t shard_id, const std::string& raw) : raw_event(raw), shard(shard_id), owner(creator) {} -event_dispatch_t::event_dispatch_t(discord_client* client, std::string&& raw) : raw_event(std::move(raw)), from(client) {} +event_dispatch_t::event_dispatch_t(dpp::cluster* creator, uint32_t shard_id, std::string&& raw) : raw_event(std::move(raw)), shard(shard_id), owner(creator) {} + +discord_client* event_dispatch_t::from() const { + return owner->get_shard(shard); +} const event_dispatch_t& event_dispatch_t::cancel_event() const { cancelled = true; @@ -73,12 +77,12 @@ void message_create_t::send(const std::string& m, command_completion_event_t cal } void message_create_t::send(const message& msg, command_completion_event_t callback) const { - this->from->creator->message_create(std::move(message{msg}.set_channel_id(this->msg.channel_id)), std::move(callback)); + owner->message_create(std::move(message{msg}.set_channel_id(this->msg.channel_id)), std::move(callback)); } void message_create_t::send(message&& msg, command_completion_event_t callback) const { msg.channel_id = this->msg.channel_id; - this->from->creator->message_create(std::move(msg), std::move(callback)); + owner->message_create(std::move(msg), std::move(callback)); } void message_create_t::reply(const std::string& m, bool mention_replied_user, command_completion_event_t callback) const { @@ -94,7 +98,7 @@ void message_create_t::reply(const message& msg, bool mention_replied_user, comm msg_to_send.allowed_mentions.replied_user = mention_replied_user; msg_to_send.allowed_mentions.users.push_back(this->msg.author.id); } - this->from->creator->message_create(std::move(msg_to_send), std::move(callback)); + owner->message_create(std::move(msg_to_send), std::move(callback)); } void message_create_t::reply(message&& msg, bool mention_replied_user, command_completion_event_t callback) const { @@ -104,15 +108,15 @@ void message_create_t::reply(message&& msg, bool mention_replied_user, command_c msg.allowed_mentions.replied_user = mention_replied_user; msg.allowed_mentions.users.push_back(this->msg.author.id); } - this->from->creator->message_create(std::move(msg), std::move(callback)); + owner->message_create(std::move(msg), std::move(callback)); } void interaction_create_t::reply(interaction_response_type t, const message& m, command_completion_event_t callback) const { - from->creator->interaction_response_create(this->command.id, this->command.token, dpp::interaction_response(t, m), std::move(callback)); + owner->interaction_response_create(this->command.id, this->command.token, dpp::interaction_response(t, m), std::move(callback)); } void interaction_create_t::reply(const message& m, command_completion_event_t callback) const { - from->creator->interaction_response_create( + owner->interaction_response_create( this->command.id, this->command.token, dpp::interaction_response(ir_channel_message_with_source, m), @@ -134,7 +138,7 @@ void interaction_create_t::reply(command_completion_event_t callback) const { } void interaction_create_t::dialog(const interaction_modal_response& mr, command_completion_event_t callback) const { - from->creator->interaction_response_create(this->command.id, this->command.token, mr, std::move(callback)); + owner->interaction_response_create(this->command.id, this->command.token, mr, std::move(callback)); } void interaction_create_t::reply(interaction_response_type t, const std::string& mt, command_completion_event_t callback) const { @@ -146,7 +150,7 @@ void interaction_create_t::reply(const std::string& mt, command_completion_event } void interaction_create_t::edit_response(const message& m, command_completion_event_t callback) const { - from->creator->interaction_response_edit(this->command.token, m, std::move(callback)); + owner->interaction_response_edit(this->command.token, m, std::move(callback)); } void interaction_create_t::edit_response(const std::string& mt, command_completion_event_t callback) const { @@ -154,9 +158,9 @@ void interaction_create_t::edit_response(const std::string& mt, command_completi } void interaction_create_t::get_original_response(command_completion_event_t callback) const { - from->creator->post_rest(API_PATH "/webhooks", std::to_string(command.application_id), command.token + "/messages/@original", m_get, "", [creator = this->from->creator, cb = std::move(callback)](json& j, const http_request_completion_t& http) { + owner->post_rest(API_PATH "/webhooks", std::to_string(command.application_id), command.token + "/messages/@original", m_get, "", [owner = this->owner, cb = std::move(callback)](json& j, const http_request_completion_t& http) { if (cb) { - cb(confirmation_callback_t(creator, message().fill_from_json(&j), http)); + cb(confirmation_callback_t(owner, message().fill_from_json(&j), http)); } }); } @@ -172,17 +176,17 @@ void interaction_create_t::edit_original_response(const message& m, command_comp file_mimetypes.push_back(data.mimetype); } - from->creator->post_rest_multipart(API_PATH "/webhooks", std::to_string(command.application_id), command.token + "/messages/@original", m_patch, m.build_json(), [creator = this->from->creator, cb = std::move(callback)](json& j, const http_request_completion_t& http) { + owner->post_rest_multipart(API_PATH "/webhooks", std::to_string(command.application_id), command.token + "/messages/@original", m_patch, m.build_json(), [owner = this->owner, cb = std::move(callback)](json& j, const http_request_completion_t& http) { if (cb) { - cb(confirmation_callback_t(creator, message().fill_from_json(&j), http)); + cb(confirmation_callback_t(owner, message().fill_from_json(&j), http)); } }, m.file_data); } void interaction_create_t::delete_original_response(command_completion_event_t callback) const { - from->creator->post_rest(API_PATH "/webhooks", std::to_string(command.application_id), command.token + "/messages/@original", m_delete, "", [creator = this->from->creator, cb = std::move(callback)](const json &, const http_request_completion_t& http) { + owner->post_rest(API_PATH "/webhooks", std::to_string(command.application_id), command.token + "/messages/@original", m_delete, "", [owner = this->owner, cb = std::move(callback)](const json &, const http_request_completion_t& http) { if (cb) { - cb(confirmation_callback_t(creator, confirmation(), http)); + cb(confirmation_callback_t(owner, confirmation(), http)); } }); } @@ -267,11 +271,11 @@ command_value interaction_create_t::get_parameter(const std::string& name) const return {}; } -voice_receive_t::voice_receive_t(discord_client* client, const std::string& raw, discord_voice_client* vc, snowflake _user_id, const uint8_t* pcm, size_t length) : event_dispatch_t(client, raw), voice_client(vc), user_id(_user_id) { +voice_receive_t::voice_receive_t(dpp::cluster* creator, uint32_t shard_id, const std::string& raw, discord_voice_client* vc, snowflake _user_id, const uint8_t* pcm, size_t length) : event_dispatch_t(owner, shard_id, std::move(raw)), voice_client(vc), user_id(_user_id) { reassign(vc, _user_id, pcm, length); } -voice_receive_t::voice_receive_t(discord_client* client, std::string&& raw, discord_voice_client* vc, snowflake _user_id, const uint8_t* pcm, size_t length) : event_dispatch_t(client, std::move(raw)), voice_client(vc), user_id(_user_id) { +voice_receive_t::voice_receive_t(dpp::cluster* creator, uint32_t shard_id, std::string&& raw, discord_voice_client* vc, snowflake _user_id, const uint8_t* pcm, size_t length) : event_dispatch_t(owner, shard_id, std::move(raw)), voice_client(vc), user_id(_user_id) { reassign(vc, _user_id, pcm, length); } diff --git a/src/dpp/events/automod_rule_create.cpp b/src/dpp/events/automod_rule_create.cpp index 49849cc05f..0a1bdab273 100644 --- a/src/dpp/events/automod_rule_create.cpp +++ b/src/dpp/events/automod_rule_create.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void automod_rule_create::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_automod_rule_create.empty()) { json& d = j["d"]; - automod_rule_create_t arc(client, raw); + automod_rule_create_t arc(client->owner, client->shard_id, raw); arc.created = automod_rule().fill_from_json(&d); client->creator->queue_work(0, [c = client->creator, arc]() { c->on_automod_rule_create.call(arc); diff --git a/src/dpp/events/automod_rule_delete.cpp b/src/dpp/events/automod_rule_delete.cpp index bd44fb9cf0..59ffc57655 100644 --- a/src/dpp/events/automod_rule_delete.cpp +++ b/src/dpp/events/automod_rule_delete.cpp @@ -37,7 +37,7 @@ namespace dpp::events { void automod_rule_delete::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_automod_rule_create.empty()) { json& d = j["d"]; - automod_rule_delete_t ard(client, raw); + automod_rule_delete_t ard(client->owner, client->shard_id, raw); ard.deleted = automod_rule().fill_from_json(&d); client->creator->queue_work(0, [c = client->creator, ard]() { c->on_automod_rule_delete.call(ard); diff --git a/src/dpp/events/automod_rule_execute.cpp b/src/dpp/events/automod_rule_execute.cpp index ef27d7d7f8..c2699d228b 100644 --- a/src/dpp/events/automod_rule_execute.cpp +++ b/src/dpp/events/automod_rule_execute.cpp @@ -37,7 +37,7 @@ namespace dpp::events { void automod_rule_execute::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_automod_rule_execute.empty()) { json& d = j["d"]; - automod_rule_execute_t are(client, raw); + automod_rule_execute_t are(client->owner, client->shard_id, raw); are.guild_id = snowflake_not_null(&d, "guild_id"); are.action = dpp::automod_action().fill_from_json(&(d["action"])); are.rule_id = snowflake_not_null(&d, "rule_id"); diff --git a/src/dpp/events/automod_rule_update.cpp b/src/dpp/events/automod_rule_update.cpp index 097d3ab58b..c14a968bf7 100644 --- a/src/dpp/events/automod_rule_update.cpp +++ b/src/dpp/events/automod_rule_update.cpp @@ -37,7 +37,7 @@ namespace dpp::events { void automod_rule_update::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_automod_rule_update.empty()) { json& d = j["d"]; - automod_rule_update_t aru(client, raw); + automod_rule_update_t aru(client->owner, client->shard_id, raw); aru.updated = automod_rule().fill_from_json(&d); client->creator->queue_work(0, [c = client->creator, aru]() { c->on_automod_rule_update.call(aru); diff --git a/src/dpp/events/channel_create.cpp b/src/dpp/events/channel_create.cpp index 2b931bec60..ae6bc3d1b0 100644 --- a/src/dpp/events/channel_create.cpp +++ b/src/dpp/events/channel_create.cpp @@ -67,7 +67,7 @@ void channel_create::handle(discord_client* client, json &j, const std::string & } } if (!client->creator->on_channel_create.empty()) { - dpp::channel_create_t cc(client, raw); + dpp::channel_create_t cc(client->owner, client->shard_id, raw); cc.created = c; cc.creating_guild = g; client->creator->queue_work(1, [c = client->creator, cc]() { diff --git a/src/dpp/events/channel_delete.cpp b/src/dpp/events/channel_delete.cpp index 9d6677140b..84898b2eb0 100644 --- a/src/dpp/events/channel_delete.cpp +++ b/src/dpp/events/channel_delete.cpp @@ -48,7 +48,7 @@ void channel_delete::handle(discord_client* client, json &j, const std::string & get_channel_cache()->remove(find_channel(c.id)); } if (!client->creator->on_channel_delete.empty()) { - channel_delete_t cd(client, raw); + channel_delete_t cd(client->owner, client->shard_id, raw); cd.deleted = c; cd.deleting_guild = g; client->creator->queue_work(1, [c = client->creator, cd]() { diff --git a/src/dpp/events/channel_pins_update.cpp b/src/dpp/events/channel_pins_update.cpp index f9012aea36..e3fe01cb57 100644 --- a/src/dpp/events/channel_pins_update.cpp +++ b/src/dpp/events/channel_pins_update.cpp @@ -39,7 +39,7 @@ void channel_pins_update::handle(discord_client* client, json &j, const std::str if (!client->creator->on_channel_pins_update.empty()) { json& d = j["d"]; - dpp::channel_pins_update_t cpu(client, raw); + dpp::channel_pins_update_t cpu(client->owner, client->shard_id, raw); cpu.pin_channel = dpp::find_channel(snowflake_not_null(&d, "channel_id")); cpu.pin_guild = dpp::find_guild(snowflake_not_null(&d, "guild_id")); cpu.timestamp = ts_not_null(&d, "last_pin_timestamp"); diff --git a/src/dpp/events/channel_update.cpp b/src/dpp/events/channel_update.cpp index 44cb24c5c9..5d7a9d8276 100644 --- a/src/dpp/events/channel_update.cpp +++ b/src/dpp/events/channel_update.cpp @@ -50,7 +50,7 @@ void channel_update::handle(discord_client* client, json &j, const std::string & } } if (!client->creator->on_channel_update.empty()) { - dpp::channel_update_t cu(client, raw); + dpp::channel_update_t cu(client->owner, client->shard_id, raw); cu.updated = c; cu.updating_guild = dpp::find_guild(c->guild_id); client->creator->queue_work(1, [c = client->creator, cu]() { diff --git a/src/dpp/events/entitlement_create.cpp b/src/dpp/events/entitlement_create.cpp index 3e42b675d6..59f0687877 100644 --- a/src/dpp/events/entitlement_create.cpp +++ b/src/dpp/events/entitlement_create.cpp @@ -38,7 +38,7 @@ void entitlement_create::handle(discord_client* client, json &j, const std::stri json& d = j["d"]; ent.fill_from_json(&d); - dpp::entitlement_create_t entitlement_event(client, raw); + dpp::entitlement_create_t entitlement_event(client->owner, client->shard_id, raw); entitlement_event.created = ent; client->creator->queue_work(0, [c = client->creator, entitlement_event]() { diff --git a/src/dpp/events/entitlement_delete.cpp b/src/dpp/events/entitlement_delete.cpp index 196ed0774a..2315de963e 100644 --- a/src/dpp/events/entitlement_delete.cpp +++ b/src/dpp/events/entitlement_delete.cpp @@ -38,7 +38,7 @@ void entitlement_delete::handle(discord_client* client, json &j, const std::stri json& d = j["d"]; ent.fill_from_json(&d); - dpp::entitlement_delete_t entitlement_event(client, raw); + dpp::entitlement_delete_t entitlement_event(client->owner, client->shard_id, raw); entitlement_event.deleted = ent; client->creator->queue_work(0, [c = client->creator, entitlement_event]() { diff --git a/src/dpp/events/entitlement_update.cpp b/src/dpp/events/entitlement_update.cpp index 150b2e0c0b..34979ade78 100644 --- a/src/dpp/events/entitlement_update.cpp +++ b/src/dpp/events/entitlement_update.cpp @@ -38,7 +38,7 @@ void entitlement_update::handle(discord_client* client, json &j, const std::stri json& d = j["d"]; ent.fill_from_json(&d); - dpp::entitlement_update_t entitlement_event(client, raw); + dpp::entitlement_update_t entitlement_event(client->owner, client->shard_id, raw); entitlement_event.updating_entitlement = ent; client->creator->queue_work(0, [c = client->creator, entitlement_event]() { diff --git a/src/dpp/events/guild_audit_log_entry_create.cpp b/src/dpp/events/guild_audit_log_entry_create.cpp index 15b5fc280f..de689d7a79 100644 --- a/src/dpp/events/guild_audit_log_entry_create.cpp +++ b/src/dpp/events/guild_audit_log_entry_create.cpp @@ -35,7 +35,7 @@ namespace dpp::events { void guild_audit_log_entry_create::handle(discord_client* client, json &j, const std::string &raw) { json& d = j["d"]; if (!client->creator->on_guild_audit_log_entry_create.empty()) { - dpp::guild_audit_log_entry_create_t ec(client, raw); + dpp::guild_audit_log_entry_create_t ec(client->owner, client->shard_id, raw); ec.entry.fill_from_json(&d); client->creator->queue_work(2, [c = client->creator, ec]() { c->on_guild_audit_log_entry_create.call(ec); diff --git a/src/dpp/events/guild_ban_add.cpp b/src/dpp/events/guild_ban_add.cpp index 82a2df68aa..cbec907aca 100644 --- a/src/dpp/events/guild_ban_add.cpp +++ b/src/dpp/events/guild_ban_add.cpp @@ -41,7 +41,7 @@ namespace dpp::events { void guild_ban_add::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_guild_ban_add.empty()) { json &d = j["d"]; - dpp::guild_ban_add_t gba(client, raw); + dpp::guild_ban_add_t gba(client->owner, client->shard_id, raw); gba.banning_guild = dpp::find_guild(snowflake_not_null(&d, "guild_id")); gba.banned = dpp::user().fill_from_json(&(d["user"])); client->creator->queue_work(1, [c = client->creator, gba]() { diff --git a/src/dpp/events/guild_ban_remove.cpp b/src/dpp/events/guild_ban_remove.cpp index 7a45be894d..f8b5b451c2 100644 --- a/src/dpp/events/guild_ban_remove.cpp +++ b/src/dpp/events/guild_ban_remove.cpp @@ -41,7 +41,7 @@ namespace dpp::events { void guild_ban_remove::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_guild_ban_remove.empty()) { json &d = j["d"]; - dpp::guild_ban_remove_t gbr(client, raw); + dpp::guild_ban_remove_t gbr(client->owner, client->shard_id, raw); gbr.unbanning_guild = dpp::find_guild(snowflake_not_null(&d, "guild_id")); gbr.unbanned = dpp::user().fill_from_json(&(d["user"])); client->creator->queue_work(1, [c = client->creator, gbr]() { diff --git a/src/dpp/events/guild_create.cpp b/src/dpp/events/guild_create.cpp index 5e6c3a7177..e80746a899 100644 --- a/src/dpp/events/guild_create.cpp +++ b/src/dpp/events/guild_create.cpp @@ -147,7 +147,7 @@ void guild_create::handle(discord_client* client, json &j, const std::string &ra } if (!client->creator->on_guild_create.empty()) { - dpp::guild_create_t gc(client, raw); + dpp::guild_create_t gc(client->owner, client->shard_id, raw); gc.created = g; /* Fill presences if there are any */ diff --git a/src/dpp/events/guild_delete.cpp b/src/dpp/events/guild_delete.cpp index c9b475b4a2..1711a0cb2c 100644 --- a/src/dpp/events/guild_delete.cpp +++ b/src/dpp/events/guild_delete.cpp @@ -87,7 +87,7 @@ 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); + dpp::guild_delete_t gd(client->owner, client->shard_id, raw); gd.deleted = guild_del; gd.guild_id = guild_del.id; client->creator->queue_work(0, [c = client->creator, gd]() { diff --git a/src/dpp/events/guild_emojis_update.cpp b/src/dpp/events/guild_emojis_update.cpp index 98125a9603..5ba2895bdc 100644 --- a/src/dpp/events/guild_emojis_update.cpp +++ b/src/dpp/events/guild_emojis_update.cpp @@ -71,7 +71,7 @@ void guild_emojis_update::handle(discord_client* client, json &j, const std::str } } if (!client->creator->on_guild_emojis_update.empty()) { - dpp::guild_emojis_update_t geu(client, raw); + dpp::guild_emojis_update_t geu(client->owner, client->shard_id, raw); geu.emojis = emojis; geu.updating_guild = g; client->creator->queue_work(1, [c = client->creator, geu]() { diff --git a/src/dpp/events/guild_integrations_update.cpp b/src/dpp/events/guild_integrations_update.cpp index 2d93c448b3..45c187fbd2 100644 --- a/src/dpp/events/guild_integrations_update.cpp +++ b/src/dpp/events/guild_integrations_update.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void guild_integrations_update::handle(class discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_guild_integrations_update.empty()) { json& d = j["d"]; - dpp::guild_integrations_update_t giu(client, raw); + dpp::guild_integrations_update_t giu(client->owner, client->shard_id, raw); giu.updating_guild = dpp::find_guild(snowflake_not_null(&d, "guild_id")); client->creator->queue_work(1, [c = client->creator, giu]() { c->on_guild_integrations_update.call(giu); diff --git a/src/dpp/events/guild_join_request_delete.cpp b/src/dpp/events/guild_join_request_delete.cpp index 7b13745282..6fd613210a 100644 --- a/src/dpp/events/guild_join_request_delete.cpp +++ b/src/dpp/events/guild_join_request_delete.cpp @@ -38,7 +38,7 @@ namespace dpp::events { void guild_join_request_delete::handle(class discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_guild_join_request_delete.empty()) { json& d = j["d"]; - dpp::guild_join_request_delete_t grd(client, raw); + dpp::guild_join_request_delete_t grd(client->owner, client->shard_id, raw); grd.user_id = snowflake_not_null(&d, "user_id"); grd.guild_id = snowflake_not_null(&d, "guild_id"); client->creator->queue_work(1, [c = client->creator, grd]() { diff --git a/src/dpp/events/guild_member_add.cpp b/src/dpp/events/guild_member_add.cpp index a245e7658a..bb2e0b9c2d 100644 --- a/src/dpp/events/guild_member_add.cpp +++ b/src/dpp/events/guild_member_add.cpp @@ -40,7 +40,7 @@ void guild_member_add::handle(discord_client* client, json &j, const std::string json d = j["d"]; dpp::snowflake guild_id = snowflake_not_null(&d, "guild_id"); dpp::guild* g = dpp::find_guild(guild_id); - dpp::guild_member_add_t gmr(client, raw); + dpp::guild_member_add_t gmr(client->owner, client->shard_id, raw); if (client->creator->cache_policy.user_policy == dpp::cp_none) { dpp::guild_member gm; gm.fill_from_json(&d, guild_id, snowflake_not_null(&(d["user"]), "id")); diff --git a/src/dpp/events/guild_member_remove.cpp b/src/dpp/events/guild_member_remove.cpp index acc5552c34..2d20d547d9 100644 --- a/src/dpp/events/guild_member_remove.cpp +++ b/src/dpp/events/guild_member_remove.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void guild_member_remove::handle(discord_client* client, json &j, const std::string &raw) { json d = j["d"]; - dpp::guild_member_remove_t gmr(client, raw); + dpp::guild_member_remove_t gmr(client->owner, client->shard_id, 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); diff --git a/src/dpp/events/guild_member_update.cpp b/src/dpp/events/guild_member_update.cpp index dd81d91e4c..92e007ccdc 100644 --- a/src/dpp/events/guild_member_update.cpp +++ b/src/dpp/events/guild_member_update.cpp @@ -40,7 +40,7 @@ void guild_member_update::handle(discord_client* client, json &j, const std::str if (client->creator->cache_policy.user_policy == dpp::cp_none) { dpp::user u; u.fill_from_json(&(d["user"])); - dpp::guild_member_update_t gmu(client, raw); + dpp::guild_member_update_t gmu(client->owner, client->shard_id, raw); gmu.updating_guild = g; if (!client->creator->on_guild_member_update.empty()) { guild_member m; @@ -62,7 +62,7 @@ void guild_member_update::handle(discord_client* client, json &j, const std::str } if (!client->creator->on_guild_member_update.empty()) { - dpp::guild_member_update_t gmu(client, raw); + dpp::guild_member_update_t gmu(client->owner, client->shard_id, raw); gmu.updating_guild = g; gmu.updated = m; client->creator->queue_work(0, [c = client->creator, gmu]() { diff --git a/src/dpp/events/guild_members_chunk.cpp b/src/dpp/events/guild_members_chunk.cpp index 26f5785d7c..6c589efc0b 100644 --- a/src/dpp/events/guild_members_chunk.cpp +++ b/src/dpp/events/guild_members_chunk.cpp @@ -64,7 +64,7 @@ void guild_members_chunk::handle(discord_client* client, json &j, const std::str } } if (!client->creator->on_guild_members_chunk.empty()) { - dpp::guild_members_chunk_t gmc(client, raw); + dpp::guild_members_chunk_t gmc(client->owner, client->shard_id, raw); gmc.adding = g; gmc.members = &um; client->creator->queue_work(1, [c = client->creator, gmc]() { diff --git a/src/dpp/events/guild_role_create.cpp b/src/dpp/events/guild_role_create.cpp index 2d5ad162ce..591f6bc1be 100644 --- a/src/dpp/events/guild_role_create.cpp +++ b/src/dpp/events/guild_role_create.cpp @@ -46,7 +46,7 @@ void guild_role_create::handle(discord_client* client, json &j, const std::strin dpp::role r; r.fill_from_json(guild_id, &role); if (!client->creator->on_guild_role_create.empty()) { - dpp::guild_role_create_t grc(client, raw); + dpp::guild_role_create_t grc(client->owner, client->shard_id, raw); grc.creating_guild = g; grc.created = &r; client->creator->queue_work(1, [c = client->creator, grc]() { @@ -65,7 +65,7 @@ void guild_role_create::handle(discord_client* client, json &j, const std::strin g->roles.push_back(r->id); } if (!client->creator->on_guild_role_create.empty()) { - dpp::guild_role_create_t grc(client, raw); + dpp::guild_role_create_t grc(client->owner, client->shard_id, raw); grc.creating_guild = g; grc.created = r; client->creator->queue_work(1, [c = client->creator, grc]() { diff --git a/src/dpp/events/guild_role_delete.cpp b/src/dpp/events/guild_role_delete.cpp index d23136bd4e..df01744096 100644 --- a/src/dpp/events/guild_role_delete.cpp +++ b/src/dpp/events/guild_role_delete.cpp @@ -44,7 +44,7 @@ void guild_role_delete::handle(discord_client* client, json &j, const std::strin dpp::guild* g = dpp::find_guild(guild_id); if (client->creator->cache_policy.role_policy == dpp::cp_none) { if (!client->creator->on_guild_role_delete.empty()) { - dpp::guild_role_delete_t grd(client, raw); + dpp::guild_role_delete_t grd(client->owner, client->shard_id, raw); grd.deleting_guild = g; grd.role_id = role_id; grd.deleted = nullptr; @@ -55,7 +55,7 @@ void guild_role_delete::handle(discord_client* client, json &j, const std::strin } else { dpp::role *r = dpp::find_role(role_id); if (!client->creator->on_guild_role_delete.empty()) { - dpp::guild_role_delete_t grd(client, raw); + dpp::guild_role_delete_t grd(client->owner, client->shard_id, raw); grd.deleting_guild = g; grd.deleted = r; grd.role_id = role_id; diff --git a/src/dpp/events/guild_role_update.cpp b/src/dpp/events/guild_role_update.cpp index 20f8573217..ba819511cf 100644 --- a/src/dpp/events/guild_role_update.cpp +++ b/src/dpp/events/guild_role_update.cpp @@ -44,7 +44,7 @@ void guild_role_update::handle(discord_client* client, json &j, const std::strin dpp::role r; r.fill_from_json(guild_id, &d); if (!client->creator->on_guild_role_update.empty()) { - dpp::guild_role_update_t gru(client, raw); + dpp::guild_role_update_t gru(client->owner, client->shard_id, raw); gru.updating_guild = g; gru.updated = &r; client->creator->queue_work(1, [c = client->creator, gru]() { @@ -57,7 +57,7 @@ void guild_role_update::handle(discord_client* client, json &j, const std::strin if (r) { r->fill_from_json(g->id, &role); if (!client->creator->on_guild_role_update.empty()) { - dpp::guild_role_update_t gru(client, raw); + dpp::guild_role_update_t gru(client->owner, client->shard_id, raw); gru.updating_guild = g; gru.updated = r; client->creator->queue_work(1, [c = client->creator, gru]() { diff --git a/src/dpp/events/guild_scheduled_event_create.cpp b/src/dpp/events/guild_scheduled_event_create.cpp index 7c72cd24ab..34b0e2cf07 100644 --- a/src/dpp/events/guild_scheduled_event_create.cpp +++ b/src/dpp/events/guild_scheduled_event_create.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void guild_scheduled_event_create::handle(discord_client* client, json &j, const std::string &raw) { json& d = j["d"]; if (!client->creator->on_guild_scheduled_event_create.empty()) { - dpp::guild_scheduled_event_create_t ec(client, raw); + dpp::guild_scheduled_event_create_t ec(client->owner, client->shard_id, raw); ec.created.fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, ec]() { c->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 ae914d38f6..991e1f1efe 100644 --- a/src/dpp/events/guild_scheduled_event_delete.cpp +++ b/src/dpp/events/guild_scheduled_event_delete.cpp @@ -40,7 +40,7 @@ namespace dpp::events { void guild_scheduled_event_delete::handle(discord_client* client, json &j, const std::string &raw) { json& d = j["d"]; if (!client->creator->on_guild_scheduled_event_delete.empty()) { - dpp::guild_scheduled_event_delete_t ed(client, raw); + dpp::guild_scheduled_event_delete_t ed(client->owner, client->shard_id, raw); ed.deleted.fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, ed]() { c->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 0f606d25a4..7f1085853b 100644 --- a/src/dpp/events/guild_scheduled_event_update.cpp +++ b/src/dpp/events/guild_scheduled_event_update.cpp @@ -40,7 +40,7 @@ namespace dpp::events { void guild_scheduled_event_update::handle(discord_client* client, json &j, const std::string &raw) { json& d = j["d"]; if (!client->creator->on_guild_scheduled_event_update.empty()) { - dpp::guild_scheduled_event_update_t eu(client, raw); + dpp::guild_scheduled_event_update_t eu(client->owner, client->shard_id, raw); eu.updated.fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, eu]() { c->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 bae5c7419f..c984b4f261 100644 --- a/src/dpp/events/guild_scheduled_event_user_add.cpp +++ b/src/dpp/events/guild_scheduled_event_user_add.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void guild_scheduled_event_user_add::handle(discord_client* client, json &j, const std::string &raw) { json& d = j["d"]; if (!client->creator->on_guild_scheduled_event_user_add.empty()) { - dpp::guild_scheduled_event_user_add_t eua(client, raw); + dpp::guild_scheduled_event_user_add_t eua(client->owner, client->shard_id, raw); 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"); diff --git a/src/dpp/events/guild_scheduled_event_user_remove.cpp b/src/dpp/events/guild_scheduled_event_user_remove.cpp index 5ebfc34333..2cb1e48c54 100644 --- a/src/dpp/events/guild_scheduled_event_user_remove.cpp +++ b/src/dpp/events/guild_scheduled_event_user_remove.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void guild_scheduled_event_user_remove::handle(discord_client* client, json &j, const std::string &raw) { json& d = j["d"]; if (!client->creator->on_guild_scheduled_event_user_remove.empty()) { - dpp::guild_scheduled_event_user_remove_t eur(client, raw); + dpp::guild_scheduled_event_user_remove_t eur(client->owner, client->shard_id, raw); 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"); diff --git a/src/dpp/events/guild_stickers_update.cpp b/src/dpp/events/guild_stickers_update.cpp index dfc43d30d2..c0c8773755 100644 --- a/src/dpp/events/guild_stickers_update.cpp +++ b/src/dpp/events/guild_stickers_update.cpp @@ -42,7 +42,7 @@ void guild_stickers_update::handle(discord_client* client, json &j, const std::s if (!client->creator->on_guild_stickers_update.empty()) { dpp::snowflake guild_id = snowflake_not_null(&d, "guild_id"); dpp::guild* g = dpp::find_guild(guild_id); - dpp::guild_stickers_update_t gsu(client, raw); + dpp::guild_stickers_update_t gsu(client->owner, client->shard_id, raw); for (auto & sticker : d["stickers"]) { dpp::sticker s; s.fill_from_json(&sticker); diff --git a/src/dpp/events/guild_update.cpp b/src/dpp/events/guild_update.cpp index 4398279587..75dbabec1b 100644 --- a/src/dpp/events/guild_update.cpp +++ b/src/dpp/events/guild_update.cpp @@ -65,7 +65,7 @@ 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); + dpp::guild_update_t gu(client->owner, client->shard_id, raw); gu.updated = g; client->creator->queue_work(1, [c = client->creator, gu]() { c->on_guild_update.call(gu); diff --git a/src/dpp/events/integration_create.cpp b/src/dpp/events/integration_create.cpp index 48fd9be7e8..81669856aa 100644 --- a/src/dpp/events/integration_create.cpp +++ b/src/dpp/events/integration_create.cpp @@ -40,7 +40,7 @@ namespace dpp::events { void integration_create::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_integration_create.empty()) { json& d = j["d"]; - dpp::integration_create_t ic(client, raw); + dpp::integration_create_t ic(client->owner, client->shard_id, raw); ic.created_integration = dpp::integration().fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, ic]() { c->on_integration_create.call(ic); diff --git a/src/dpp/events/integration_delete.cpp b/src/dpp/events/integration_delete.cpp index d93063e5dc..a3fcd06857 100644 --- a/src/dpp/events/integration_delete.cpp +++ b/src/dpp/events/integration_delete.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void integration_delete::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_integration_delete.empty()) { json& d = j["d"]; - dpp::integration_delete_t id(client, raw); + dpp::integration_delete_t id(client->owner, client->shard_id, raw); id.deleted_integration = dpp::integration().fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, id]() { c->on_integration_delete.call(id); diff --git a/src/dpp/events/integration_update.cpp b/src/dpp/events/integration_update.cpp index 814ac81634..7201a2554e 100644 --- a/src/dpp/events/integration_update.cpp +++ b/src/dpp/events/integration_update.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void integration_update::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_integration_update.empty()) { json& d = j["d"]; - dpp::integration_update_t iu(client, raw); + dpp::integration_update_t iu(client->owner, client->shard_id, raw); iu.updated_integration = dpp::integration().fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, iu]() { c->on_integration_update.call(iu); diff --git a/src/dpp/events/interaction_create.cpp b/src/dpp/events/interaction_create.cpp index 51d00fe958..da39a4e018 100644 --- a/src/dpp/events/interaction_create.cpp +++ b/src/dpp/events/interaction_create.cpp @@ -99,7 +99,7 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri if (cmd_data.type == ctxm_message && !client->creator->on_message_context_menu.empty()) { if (i.resolved.messages.size()) { /* Message right-click context menu */ - message_context_menu_t mcm(client, raw); + message_context_menu_t mcm(client->owner, client->shard_id, raw); mcm.command = i; mcm.set_message(i.resolved.messages.begin()->second); client->creator->queue_work(1, [c = client->creator, mcm]() { @@ -109,7 +109,7 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri } 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); + user_context_menu_t ucm(client->owner, client->shard_id, raw); ucm.command = i; ucm.set_user(i.resolved.users.begin()->second); client->creator->queue_work(1, [c = client->creator, ucm]() { @@ -117,7 +117,7 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri }); } } else if (cmd_data.type == ctxm_chat_input && !client->creator->on_slashcommand.empty()) { - dpp::slashcommand_t sc(client, raw); + dpp::slashcommand_t sc(client->owner, client->shard_id, raw); sc.command = i; client->creator->queue_work(1, [c = client->creator, sc]() { c->on_slashcommand.call(sc); @@ -128,7 +128,7 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri * events still find their way here. At some point in the future, receiving * ctxm_user and ctxm_message inputs to this event will be depreciated. */ - dpp::interaction_create_t ic(client, raw); + dpp::interaction_create_t ic(client->owner, client->shard_id, raw); ic.command = i; client->creator->queue_work(1, [c = client->creator, ic]() { c->on_interaction_create.call(ic); @@ -136,7 +136,7 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri } } else if (i.type == it_modal_submit) { if (!client->creator->on_form_submit.empty()) { - dpp::form_submit_t fs(client, raw); + dpp::form_submit_t fs(client->owner, client->shard_id, raw); fs.custom_id = string_not_null(&(d["data"]), "custom_id"); fs.command = i; for (auto & c : d["data"]["components"]) { @@ -149,7 +149,7 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri } else if (i.type == it_autocomplete) { // "data":{"id":"903319628816728104","name":"blep","options":[{"focused":true,"name":"animal","type":3,"value":"a"}],"type":1} if (!client->creator->on_autocomplete.empty()) { - dpp::autocomplete_t ac(client, raw); + dpp::autocomplete_t ac(client->owner, client->shard_id, raw); ac.id = snowflake_not_null(&(d["data"]), "id"); ac.name = string_not_null(&(d["data"]), "name"); fill_options(d["data"]["options"], ac.options); @@ -162,7 +162,7 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri dpp::component_interaction bi = std::get(i.data); if (bi.component_type == cot_button) { if (!client->creator->on_button_click.empty()) { - dpp::button_click_t ic(client, raw); + dpp::button_click_t ic(client->owner, client->shard_id, raw); ic.command = i; ic.custom_id = bi.custom_id; ic.component_type = bi.component_type; @@ -174,7 +174,7 @@ void interaction_create::handle(discord_client* client, json &j, const std::stri bi.component_type == cot_role_selectmenu || bi.component_type == cot_mentionable_selectmenu || bi.component_type == cot_channel_selectmenu) { if (!client->creator->on_select_click.empty()) { - dpp::select_click_t ic(client, raw); + dpp::select_click_t ic(client->owner, client->shard_id, raw); ic.command = i; ic.custom_id = bi.custom_id; ic.component_type = bi.component_type; diff --git a/src/dpp/events/invite_create.cpp b/src/dpp/events/invite_create.cpp index d06b38eaa2..b8af9a5eab 100644 --- a/src/dpp/events/invite_create.cpp +++ b/src/dpp/events/invite_create.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void invite_create::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_invite_create.empty()) { json& d = j["d"]; - dpp::invite_create_t ci(client, raw); + dpp::invite_create_t ci(client->owner, client->shard_id, raw); ci.created_invite = dpp::invite().fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, ci]() { c->on_invite_create.call(ci); diff --git a/src/dpp/events/invite_delete.cpp b/src/dpp/events/invite_delete.cpp index 5a77618e14..746bb4c4c7 100644 --- a/src/dpp/events/invite_delete.cpp +++ b/src/dpp/events/invite_delete.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void invite_delete::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_invite_delete.empty()) { json& d = j["d"]; - dpp::invite_delete_t cd(client, raw); + dpp::invite_delete_t cd(client->owner, client->shard_id, raw); cd.deleted_invite = dpp::invite().fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, cd]() { c->on_invite_delete.call(cd); diff --git a/src/dpp/events/logger.cpp b/src/dpp/events/logger.cpp index 33c6222433..d505acae53 100644 --- a/src/dpp/events/logger.cpp +++ b/src/dpp/events/logger.cpp @@ -37,10 +37,10 @@ namespace dpp::events { */ void logger::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_log.empty()) { - dpp::log_t logmsg(client, raw); + dpp::log_t logmsg(client->owner, client->shard_id, raw); logmsg.severity = (dpp::loglevel)from_string(raw.substr(0, raw.find(';'))); logmsg.message = raw.substr(raw.find(';') + 1, raw.length()); - c->on_log.call(logmsg); + client->creator->on_log.call(logmsg); } } diff --git a/src/dpp/events/message_create.cpp b/src/dpp/events/message_create.cpp index ddd97292e0..39ad89adf1 100644 --- a/src/dpp/events/message_create.cpp +++ b/src/dpp/events/message_create.cpp @@ -38,12 +38,11 @@ namespace dpp::events { void message_create::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_message_create.empty()) { - json js = j; - client->creator->queue_work(1, [c = client->creator, js, raw]() { + client->creator->queue_work(1, [shard_id = client->shard_id, c = client->creator, js = j, raw]() { json d = js["d"]; - dpp::message_create_t msg(client, raw); - msg.msg = message(client->owner).fill_from_json(&d, client->creator->cache_policy); - msg.msg.owner = client->creator; + dpp::message_create_t msg(c, shard_id, raw); + msg.msg = message(c).fill_from_json(&d, c->cache_policy); + msg.msg.owner = c; c->on_message_create.call(msg); }); } diff --git a/src/dpp/events/message_delete.cpp b/src/dpp/events/message_delete.cpp index e3bde8f88d..bffd907f20 100644 --- a/src/dpp/events/message_delete.cpp +++ b/src/dpp/events/message_delete.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void message_delete::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_message_delete.empty()) { json d = j["d"]; - dpp::message_delete_t msg(client, raw); + dpp::message_delete_t msg(client->owner, client->shard_id, raw); 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"); diff --git a/src/dpp/events/message_delete_bulk.cpp b/src/dpp/events/message_delete_bulk.cpp index ae53d1501b..4ac923c900 100644 --- a/src/dpp/events/message_delete_bulk.cpp +++ b/src/dpp/events/message_delete_bulk.cpp @@ -37,7 +37,7 @@ namespace dpp::events { void message_delete_bulk::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_message_delete_bulk.empty()) { json& d = j["d"]; - dpp::message_delete_bulk_t msg(client, raw); + dpp::message_delete_bulk_t msg(client->owner, client->shard_id, raw); msg.deleting_guild = dpp::find_guild(snowflake_not_null(&d, "guild_id")); msg.deleting_channel = dpp::find_channel(snowflake_not_null(&d, "channel_id")); msg.deleting_user = dpp::find_user(snowflake_not_null(&d, "user_id")); diff --git a/src/dpp/events/message_poll_vote_add.cpp b/src/dpp/events/message_poll_vote_add.cpp index 0e9e730b14..3b50d287d5 100644 --- a/src/dpp/events/message_poll_vote_add.cpp +++ b/src/dpp/events/message_poll_vote_add.cpp @@ -40,7 +40,7 @@ void message_poll_vote_add::handle(discord_client* client, json &j, const std::s if (!client->creator->on_message_poll_vote_add.empty()) { json d = j["d"]; - dpp::message_poll_vote_add_t vote(client, raw); + dpp::message_poll_vote_add_t vote(client->owner, client->shard_id, raw); vote.user_id = snowflake_not_null(&j, "user_id"); vote.message_id = snowflake_not_null(&j, "message_id"); vote.channel_id = snowflake_not_null(&j, "channel_id"); diff --git a/src/dpp/events/message_poll_vote_remove.cpp b/src/dpp/events/message_poll_vote_remove.cpp index 9bf0d0d6eb..feccb4cc00 100644 --- a/src/dpp/events/message_poll_vote_remove.cpp +++ b/src/dpp/events/message_poll_vote_remove.cpp @@ -40,7 +40,7 @@ void message_poll_vote_remove::handle(discord_client* client, json &j, const std if (!client->creator->on_message_poll_vote_add.empty()) { json d = j["d"]; - dpp::message_poll_vote_remove_t vote(client, raw); + dpp::message_poll_vote_remove_t vote(client->owner, client->shard_id, raw); vote.user_id = snowflake_not_null(&j, "user_id"); vote.message_id = snowflake_not_null(&j, "message_id"); vote.channel_id = snowflake_not_null(&j, "channel_id"); diff --git a/src/dpp/events/message_reaction_add.cpp b/src/dpp/events/message_reaction_add.cpp index 52acbcffb8..392834bf39 100644 --- a/src/dpp/events/message_reaction_add.cpp +++ b/src/dpp/events/message_reaction_add.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void message_reaction_add::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_message_reaction_add.empty()) { json &d = j["d"]; - dpp::message_reaction_add_t mra(client, raw); + dpp::message_reaction_add_t mra(client->owner, client->shard_id, raw); dpp::snowflake guild_id = snowflake_not_null(&d, "guild_id"); mra.reacting_guild = dpp::find_guild(guild_id); mra.reacting_user = dpp::user().fill_from_json(&(d["member"]["user"])); diff --git a/src/dpp/events/message_reaction_remove.cpp b/src/dpp/events/message_reaction_remove.cpp index 380f776828..25ffa9c852 100644 --- a/src/dpp/events/message_reaction_remove.cpp +++ b/src/dpp/events/message_reaction_remove.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void message_reaction_remove::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_message_reaction_remove.empty()) { json &d = j["d"]; - dpp::message_reaction_remove_t mrr(client, raw); + dpp::message_reaction_remove_t mrr(client->owner, client->shard_id, raw); dpp::snowflake guild_id = snowflake_not_null(&d, "guild_id"); mrr.reacting_guild = dpp::find_guild(guild_id); mrr.reacting_user_id = snowflake_not_null(&d, "user_id"); diff --git a/src/dpp/events/message_reaction_remove_all.cpp b/src/dpp/events/message_reaction_remove_all.cpp index 5c71f85485..dca6cce8d5 100644 --- a/src/dpp/events/message_reaction_remove_all.cpp +++ b/src/dpp/events/message_reaction_remove_all.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void message_reaction_remove_all::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_message_reaction_remove_all.empty()) { json &d = j["d"]; - dpp::message_reaction_remove_all_t mrra(client, raw); + dpp::message_reaction_remove_all_t mrra(client->owner, client->shard_id, raw); mrra.reacting_guild = dpp::find_guild(snowflake_not_null(&d, "guild_id")); mrra.channel_id = snowflake_not_null(&d, "channel_id"); mrra.reacting_channel = dpp::find_channel(mrra.channel_id); diff --git a/src/dpp/events/message_reaction_remove_emoji.cpp b/src/dpp/events/message_reaction_remove_emoji.cpp index 1c38b5fadd..ceebccfaac 100644 --- a/src/dpp/events/message_reaction_remove_emoji.cpp +++ b/src/dpp/events/message_reaction_remove_emoji.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void message_reaction_remove_emoji::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_message_reaction_remove_emoji.empty()) { json &d = j["d"]; - dpp::message_reaction_remove_emoji_t mrre(client, raw); + dpp::message_reaction_remove_emoji_t mrre(client->owner, client->shard_id, raw); mrre.reacting_guild = dpp::find_guild(snowflake_not_null(&d, "guild_id")); mrre.channel_id = snowflake_not_null(&d, "channel_id"); mrre.reacting_channel = dpp::find_channel(mrre.channel_id); diff --git a/src/dpp/events/message_update.cpp b/src/dpp/events/message_update.cpp index 6f6f5bf028..545ebd78df 100644 --- a/src/dpp/events/message_update.cpp +++ b/src/dpp/events/message_update.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void message_update::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_message_update.empty()) { json d = j["d"]; - dpp::message_update_t msg(client, raw); + dpp::message_update_t msg(client->owner, client->shard_id, raw); dpp::message m(client->creator); m.fill_from_json(&d); msg.msg = m; diff --git a/src/dpp/events/presence_update.cpp b/src/dpp/events/presence_update.cpp index cacbe2aa1a..aac6f37e63 100644 --- a/src/dpp/events/presence_update.cpp +++ b/src/dpp/events/presence_update.cpp @@ -38,7 +38,7 @@ namespace dpp::events { void presence_update::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_presence_update.empty()) { json& d = j["d"]; - dpp::presence_update_t pu(client, raw); + dpp::presence_update_t pu(client->owner, client->shard_id, raw); pu.rich_presence = dpp::presence().fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, pu]() { c->on_presence_update.call(pu); diff --git a/src/dpp/events/ready.cpp b/src/dpp/events/ready.cpp index 251f455a57..765f9a9daa 100644 --- a/src/dpp/events/ready.cpp +++ b/src/dpp/events/ready.cpp @@ -68,7 +68,7 @@ void ready::handle(discord_client* client, json &j, const std::string &raw) { } if (!client->creator->on_ready.empty()) { - dpp::ready_t r(client, raw); + dpp::ready_t r(client->owner, client->shard_id, raw); r.session_id = client->sessionid; r.shard_id = client->shard_id; for (const auto& guild : j["d"]["guilds"]) { diff --git a/src/dpp/events/resumed.cpp b/src/dpp/events/resumed.cpp index ad66831d92..706c45e2dd 100644 --- a/src/dpp/events/resumed.cpp +++ b/src/dpp/events/resumed.cpp @@ -41,7 +41,7 @@ void resumed::handle(discord_client* client, json &j, const std::string &raw) { client->ready = true; if (!client->creator->on_resumed.empty()) { - dpp::resumed_t r(client, raw); + dpp::resumed_t r(client->owner, client->shard_id, raw); r.session_id = client->sessionid; r.shard_id = client->shard_id; client->creator->queue_work(1, [c = client->creator, r]() { diff --git a/src/dpp/events/stage_instance_create.cpp b/src/dpp/events/stage_instance_create.cpp index f6049b36c3..db42c0d1a7 100644 --- a/src/dpp/events/stage_instance_create.cpp +++ b/src/dpp/events/stage_instance_create.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void stage_instance_create::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_stage_instance_create.empty()) { json& d = j["d"]; - dpp::stage_instance_create_t sic(client, raw); + dpp::stage_instance_create_t sic(client->owner, client->shard_id, raw); sic.created.fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, sic]() { c->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 15cd1a0522..d639b866e5 100644 --- a/src/dpp/events/stage_instance_delete.cpp +++ b/src/dpp/events/stage_instance_delete.cpp @@ -37,7 +37,7 @@ namespace dpp::events { void stage_instance_delete::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_stage_instance_delete.empty()) { json& d = j["d"]; - dpp::stage_instance_delete_t sid(client, raw); + dpp::stage_instance_delete_t sid(client->owner, client->shard_id, raw); sid.deleted.fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, sid]() { c->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 6f1febb7b9..d445356008 100644 --- a/src/dpp/events/stage_instance_update.cpp +++ b/src/dpp/events/stage_instance_update.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void stage_instance_update::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_stage_instance_update.empty()) { json& d = j["d"]; - dpp::stage_instance_update_t siu(client, raw); + dpp::stage_instance_update_t siu(client->owner, client->shard_id, raw); siu.updated.fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, siu]() { c->on_stage_instance_update.call(siu); diff --git a/src/dpp/events/thread_create.cpp b/src/dpp/events/thread_create.cpp index 01d3ad3022..7049ad6e52 100644 --- a/src/dpp/events/thread_create.cpp +++ b/src/dpp/events/thread_create.cpp @@ -39,7 +39,7 @@ void thread_create::handle(discord_client* client, json& j, const std::string& r g->threads.push_back(t.id); } if (!client->creator->on_thread_create.empty()) { - dpp::thread_create_t tc(client, raw); + dpp::thread_create_t tc(client->owner, client->shard_id, raw); tc.created = t; tc.creating_guild = g; client->creator->queue_work(1, [c = client->creator, tc]() { diff --git a/src/dpp/events/thread_delete.cpp b/src/dpp/events/thread_delete.cpp index 4bcab8084d..ad4512e2e3 100644 --- a/src/dpp/events/thread_delete.cpp +++ b/src/dpp/events/thread_delete.cpp @@ -39,7 +39,7 @@ void thread_delete::handle(discord_client* client, json& j, const std::string& r g->threads.erase(std::remove(g->threads.begin(), g->threads.end(), t.id), g->threads.end()); } if (!client->creator->on_thread_delete.empty()) { - dpp::thread_delete_t td(client, raw); + dpp::thread_delete_t td(client->owner, client->shard_id, raw); td.deleted = t; td.deleting_guild = g; client->creator->queue_work(1, [c = client->creator, td]() { diff --git a/src/dpp/events/thread_list_sync.cpp b/src/dpp/events/thread_list_sync.cpp index 718f834783..d0019deb2c 100644 --- a/src/dpp/events/thread_list_sync.cpp +++ b/src/dpp/events/thread_list_sync.cpp @@ -41,7 +41,7 @@ void thread_list_sync::handle(discord_client* client, json& j, const std::string } } if (!client->creator->on_thread_list_sync.empty()) { - dpp::thread_list_sync_t tls(client, raw); + dpp::thread_list_sync_t tls(client->owner, client->shard_id, raw); if (d.find("threads") != d.end()) { for (auto& t : d["threads"]) { tls.threads.push_back(thread().fill_from_json(&t)); diff --git a/src/dpp/events/thread_member_update.cpp b/src/dpp/events/thread_member_update.cpp index 39c3bafbff..61c421afb4 100644 --- a/src/dpp/events/thread_member_update.cpp +++ b/src/dpp/events/thread_member_update.cpp @@ -32,7 +32,7 @@ namespace dpp::events { void thread_member_update::handle(discord_client* client, json& j, const std::string& raw) { if (!client->creator->on_thread_member_update.empty()) { json& d = j["d"]; - dpp::thread_member_update_t tm(client, raw); + dpp::thread_member_update_t tm(client->owner, client->shard_id, raw); tm.updated = thread_member().fill_from_json(&d); client->creator->queue_work(1, [c = client->creator, tm]() { c->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 8968772011..d4e14b7676 100644 --- a/src/dpp/events/thread_members_update.cpp +++ b/src/dpp/events/thread_members_update.cpp @@ -34,7 +34,7 @@ void thread_members_update::handle(discord_client* client, json& j, const std::s dpp::guild* g = dpp::find_guild(snowflake_not_null(&d, "guild_id")); if (!client->creator->on_thread_members_update.empty()) { - dpp::thread_members_update_t tms(client, raw); + dpp::thread_members_update_t tms(client->owner, client->shard_id, raw); tms.updating_guild = g; set_snowflake_not_null(&d, "id", tms.thread_id); set_int8_not_null(&d, "member_count", tms.member_count); diff --git a/src/dpp/events/thread_update.cpp b/src/dpp/events/thread_update.cpp index 797b184a53..9600ef36f5 100644 --- a/src/dpp/events/thread_update.cpp +++ b/src/dpp/events/thread_update.cpp @@ -35,7 +35,7 @@ void thread_update::handle(discord_client* client, json& j, const std::string& r t.fill_from_json(&d); dpp::guild* g = dpp::find_guild(t.guild_id); if (!client->creator->on_thread_update.empty()) { - dpp::thread_update_t tu(client, raw); + dpp::thread_update_t tu(client->owner, client->shard_id, raw); tu.updated = t; tu.updating_guild = g; client->creator->queue_work(1, [c = client->creator, tu]() { diff --git a/src/dpp/events/typing_start.cpp b/src/dpp/events/typing_start.cpp index aa000607c7..bab90053ce 100644 --- a/src/dpp/events/typing_start.cpp +++ b/src/dpp/events/typing_start.cpp @@ -37,7 +37,7 @@ namespace dpp::events { void typing_start::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_typing_start.empty()) { json& d = j["d"]; - dpp::typing_start_t ts(client, raw); + dpp::typing_start_t ts(client->owner, client->shard_id, raw); ts.typing_guild = dpp::find_guild(snowflake_not_null(&d, "guild_id")); ts.typing_channel = dpp::find_channel(snowflake_not_null(&d, "channel_id")); ts.user_id = snowflake_not_null(&d, "user_id"); diff --git a/src/dpp/events/user_update.cpp b/src/dpp/events/user_update.cpp index 2766d34b30..05aee1b63d 100644 --- a/src/dpp/events/user_update.cpp +++ b/src/dpp/events/user_update.cpp @@ -47,7 +47,7 @@ void user_update::handle(discord_client* client, json &j, const std::string &raw u->fill_from_json(&d); } if (!client->creator->on_user_update.empty()) { - dpp::user_update_t uu(client, raw); + dpp::user_update_t uu(client->owner, client->shard_id, raw); uu.updated = *u; client->creator->queue_work(1, [c = client->creator, uu]() { c->on_user_update.call(uu); @@ -57,7 +57,7 @@ void user_update::handle(discord_client* client, json &j, const std::string &raw if (!client->creator->on_user_update.empty()) { dpp::user u; u.fill_from_json(&d); - dpp::user_update_t uu(client, raw); + dpp::user_update_t uu(client->owner, client->shard_id, raw); uu.updated = u; client->creator->queue_work(1, [c = client->creator, uu]() { c->on_user_update.call(uu); diff --git a/src/dpp/events/voice_server_update.cpp b/src/dpp/events/voice_server_update.cpp index 864584be97..489a013fdb 100644 --- a/src/dpp/events/voice_server_update.cpp +++ b/src/dpp/events/voice_server_update.cpp @@ -39,7 +39,7 @@ namespace dpp::events { void voice_server_update::handle(discord_client* client, json &j, const std::string &raw) { json &d = j["d"]; - dpp::voice_server_update_t vsu(client, raw); + dpp::voice_server_update_t vsu(client->owner, client->shard_id, raw); vsu.guild_id = snowflake_not_null(&d, "guild_id"); vsu.token = string_not_null(&d, "token"); vsu.endpoint = string_not_null(&d, "endpoint"); diff --git a/src/dpp/events/voice_state_update.cpp b/src/dpp/events/voice_state_update.cpp index 9b2b9f0543..30c81eed59 100644 --- a/src/dpp/events/voice_state_update.cpp +++ b/src/dpp/events/voice_state_update.cpp @@ -40,7 +40,7 @@ namespace dpp::events { void voice_state_update::handle(discord_client* client, json &j, const std::string &raw) { json& d = j["d"]; - dpp::voice_state_update_t vsu(client, raw); + dpp::voice_state_update_t vsu(client->owner, client->shard_id, raw); vsu.state = dpp::voicestate().fill_from_json(&d); vsu.state.shard = client; diff --git a/src/dpp/events/webhooks_update.cpp b/src/dpp/events/webhooks_update.cpp index 7eb4f0eedf..1750cdb2fd 100644 --- a/src/dpp/events/webhooks_update.cpp +++ b/src/dpp/events/webhooks_update.cpp @@ -38,7 +38,7 @@ namespace dpp::events { void webhooks_update::handle(discord_client* client, json &j, const std::string &raw) { if (!client->creator->on_webhooks_update.empty()) { json& d = j["d"]; - dpp::webhooks_update_t wu(client, raw); + dpp::webhooks_update_t wu(client->owner, client->shard_id, 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->queue_work(1, [c = client->creator, wu]() { diff --git a/src/dpp/voice/enabled/courier_loop.cpp b/src/dpp/voice/enabled/courier_loop.cpp index 72ccccdbfc..a8d8f61c0a 100644 --- a/src/dpp/voice/enabled/courier_loop.cpp +++ b/src/dpp/voice/enabled/courier_loop.cpp @@ -146,7 +146,7 @@ void discord_voice_client::voice_courier_loop(discord_voice_client& client, cour * Since this sample comes from a lost packet, * we can only pretend there is an event, without any raw payload byte. */ - voice_receive_t vr(nullptr, "", &client, d.user_id, + voice_receive_t vr(client.creator, 0, "", &client, d.user_id, reinterpret_cast(flush_data_pcm), lost_packet_samples * opus_channel_count * sizeof(opus_int16)); @@ -282,7 +282,7 @@ void discord_voice_client::voice_courier_loop(discord_voice_client& client, cour pcm_downsample_ptr += client.mixer->byte_blocks_per_register; } - voice_receive_t vr(nullptr, "", &client, 0, reinterpret_cast(pcm_downsample), + voice_receive_t vr(client.owner, 0, "", &client, 0, reinterpret_cast(pcm_downsample), max_samples * opus_channel_count * sizeof(opus_int16)); client.creator->on_voice_receive_combined.call(vr); diff --git a/src/dpp/voice/enabled/handle_frame.cpp b/src/dpp/voice/enabled/handle_frame.cpp index 6a8bfe5510..69f879bd92 100644 --- a/src/dpp/voice/enabled/handle_frame.cpp +++ b/src/dpp/voice/enabled/handle_frame.cpp @@ -204,7 +204,7 @@ bool discord_voice_client::handle_frame(const std::string &data, ws_opcode opcod } break; case voice_client_platform: { - voice_client_platform_t vcp(nullptr, data); + voice_client_platform_t vcp(owner, 0, data); vcp.voice_client = this; vcp.user_id = snowflake_not_null(&j["d"], "user_id"); vcp.platform = static_cast(int8_not_null(&j["d"], "platform")); @@ -302,7 +302,7 @@ bool discord_voice_client::handle_frame(const std::string &data, ws_opcode opcod dave_mls_pending_remove_list.insert(u_id); if (!creator->on_voice_client_disconnect.empty()) { - voice_client_disconnect_t vcd(nullptr, data); + voice_client_disconnect_t vcd(owner, 0, data); vcd.voice_client = this; vcd.user_id = u_id; creator->queue_work(0, [this, vcd]() { @@ -322,7 +322,7 @@ bool discord_voice_client::handle_frame(const std::string &data, ws_opcode opcod ssrc_map[u_ssrc] = u_id; if (!creator->on_voice_client_speaking.empty()) { - voice_client_speaking_t vcs(nullptr, data); + voice_client_speaking_t vcs(owner, 0, data); vcs.voice_client = this; vcs.user_id = u_id; vcs.ssrc = u_ssrc; @@ -422,7 +422,7 @@ bool discord_voice_client::handle_frame(const std::string &data, ws_opcode opcod send_silence(20); /* Fire on_voice_ready */ if (!creator->on_voice_ready.empty()) { - voice_ready_t rdy(nullptr, data); + voice_ready_t rdy(owner, 0, data); rdy.voice_client = this; rdy.voice_channel_id = this->channel_id; creator->queue_work(0, [this, rdy]() { @@ -533,7 +533,7 @@ void discord_voice_client::ready_for_transition(const std::string &data) { mls_state->done_ready = true; if (!creator->on_voice_ready.empty()) { - voice_ready_t rdy(nullptr, data); + voice_ready_t rdy(owner, 0, data); rdy.voice_client = this; rdy.voice_channel_id = this->channel_id; creator->queue_work(0, [this, rdy]() { diff --git a/src/dpp/voice/enabled/read_ready.cpp b/src/dpp/voice/enabled/read_ready.cpp index 03c79b0486..e499de3f5d 100644 --- a/src/dpp/voice/enabled/read_ready.cpp +++ b/src/dpp/voice/enabled/read_ready.cpp @@ -68,7 +68,7 @@ void discord_voice_client::read_ready() voice_payload vp{0, // seq, populate later 0, // timestamp, populate later - std::make_unique(nullptr, std::string(reinterpret_cast(buffer), packet_size))}; + std::make_unique(owner, 0, std::string(reinterpret_cast(buffer), packet_size))}; vp.vr->voice_client = this; diff --git a/src/dpp/voice/enabled/write_ready.cpp b/src/dpp/voice/enabled/write_ready.cpp index 6877a97c26..e2b78ef8c8 100644 --- a/src/dpp/voice/enabled/write_ready.cpp +++ b/src/dpp/voice/enabled/write_ready.cpp @@ -103,7 +103,7 @@ void discord_voice_client::write_ready() { last_timestamp = std::chrono::high_resolution_clock::now(); if (!creator->on_voice_buffer_send.empty()) { - voice_buffer_send_t snd(nullptr, ""); + voice_buffer_send_t snd(owner, 0, ""); snd.buffer_size = bufsize; snd.packets_left = outbuf.size(); snd.voice_client = this; @@ -114,7 +114,7 @@ void discord_voice_client::write_ready() { } if (track_marker_found) { if (!creator->on_voice_track_marker.empty()) { - voice_track_marker_t vtm(nullptr, ""); + voice_track_marker_t vtm(owner, 0, ""); vtm.voice_client = this; { std::lock_guard lock(this->stream_mutex); diff --git a/src/unittest/coro.cpp b/src/unittest/coro.cpp index eead3c85b6..8ec42d89d2 100644 --- a/src/unittest/coro.cpp +++ b/src/unittest/coro.cpp @@ -523,7 +523,7 @@ void coro_offline_tests() void event_handler_test(dpp::cluster *bot) { bot->on_message_create([](dpp::message_create_t event) -> dpp::task { if (event.msg.content == "coro test") { - dpp::cluster *bot = event.from->creator; + dpp::cluster *bot = event.owner; set_status(CORO_EVENT_HANDLER, ts_success); start_test(CORO_API_CALLS); diff --git a/src/unittest/test.cpp b/src/unittest/test.cpp index 9b2e0778ab..4d5d308ee0 100644 --- a/src/unittest/test.cpp +++ b/src/unittest/test.cpp @@ -411,7 +411,7 @@ Markdown lol \\|\\|spoiler\\|\\| \\~\\~strikethrough\\~\\~ \\`small \\*code\\* b // create a fake interaction dpp::cluster cluster(""); dpp::discord_client client(&cluster, 1, 1, ""); - dpp::interaction_create_t interaction(&client, ""); + dpp::interaction_create_t interaction(nullptr, 0, ""); /* Check the method with subcommands */ set_test(GET_PARAMETER_WITH_SUBCOMMANDS, false);