diff --git a/include/dpp/cluster.h b/include/dpp/cluster.h index a8e9b4d518..8b161e9a92 100644 --- a/include/dpp/cluster.h +++ b/include/dpp/cluster.h @@ -354,7 +354,7 @@ template class event_router_t { * @brief A function to be called whenever the method is called, to check * some condition that is required for this event to trigger correctly. */ - std::function warning; + std::function warning; protected: @@ -364,7 +364,7 @@ template class event_router_t { * * @param warning_function A checking function to call */ - void set_warning_callback(std::function warning_function) { + void set_warning_callback(std::function warning_function) { warning = warning_function; } @@ -383,7 +383,7 @@ template class event_router_t { */ void call(const T& event) const { if (warning) { - warning(); + warning(event); } std::shared_lock l(lock); std::for_each(dispatch_container.begin(), dispatch_container.end(), [&](auto &ev) { @@ -441,9 +441,6 @@ template class event_router_t { * detach the listener from the event later if necessary. */ event_handle attach(std::function func) { - if (warning) { - warning(); - } std::unique_lock l(lock); event_handle h = __next_handle++; dispatch_container.emplace(h, func); diff --git a/src/dpp/cluster.cpp b/src/dpp/cluster.cpp index d6ea9c6f8d..a7529e6ed5 100644 --- a/src/dpp/cluster.cpp +++ b/src/dpp/cluster.cpp @@ -54,19 +54,18 @@ namespace dpp { */ thread_local std::string audit_reason; -event_handle __next_handle = 1; - /** * @brief Make a warning lambda for missing message intents - * + * + * @tparam T type of parameter for the event in the router * @param cl Creating cluster * @param required_intent Intent which is required * @param message Message to display - * @return std::function Returned lambda + * @return std::function Returned lambda */ -std::function make_intent_warning(cluster* cl, const intents required_intent, const std::string& message) { - return [cl, required_intent, message]() { - if (!(cl->intents & required_intent)) { +template std::function make_intent_warning(cluster* cl, const intents required_intent, const std::string& message) { + return [cl, required_intent, message](const T& event) { + if (!(cl->intents & required_intent) && event.msg.guild_id) { cl->log(ll_warning, message); } }; @@ -82,13 +81,18 @@ cluster::cluster(const std::string &_token, uint32_t _intents, uint32_t _shards, raw_rest = new request_queue(this, request_threads); /* Add checks for missing intents, these emit a one-off warning to the log if bound without the right intents */ - std::function message_intents_warning = make_intent_warning(this, i_message_content, "You have attached an event to cluster::on_message_*() but have not specified the privileged intent dpp::i_message_content. Message content, embeds, attachments, and components on received guild messages will be empty."); - std::function member_intents_warning = make_intent_warning(this, i_guild_members, "You have attached an event to cluster::on_guild_member_*() but have not specified the privileged intent dpp::i_guild_members. These events will not fire, and the cache will only fill when a user interacts with the bot or channels."); - on_message_create.set_warning_callback(message_intents_warning); - on_message_update.set_warning_callback(message_intents_warning); - on_guild_member_add.set_warning_callback(member_intents_warning); - on_guild_member_remove.set_warning_callback(member_intents_warning); - on_guild_member_update.set_warning_callback(member_intents_warning); + on_message_create.set_warning_callback( + make_intent_warning( + this, + i_message_content, + "You have attached an event to cluster::on_message_create() but have not specified the privileged intent dpp::i_message_content. Message content, embeds, attachments, and components on received guild messages will be empty.") + ); + on_message_update.set_warning_callback( + make_intent_warning( + this, + i_message_content, + "You have attached an event to cluster::on_message_update() but have not specified the privileged intent dpp::i_message_content. Message content, embeds, attachments, and components on received guild messages will be empty.") + ); } cluster::~cluster()