Debian Codegraph @

src/dpp/events/message_reaction_remove.cpp

raw symbols SCIP
1 /************************************************************************************
2 *
3 * D++, A Lightweight C++ library for Discord
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 * Copyright 2021 Craig Edwards and D++ contributors
7 * (https://github.com/brainboxdotcc/DPP/graphs/contributors)
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 *
21 ************************************************************************************/
22 #include <dpp/discordevents.h>
23 #include <dpp/cluster.h>
24 #include <dpp/message.h>
25 #include <dpp/stringops.h>
26 #include <dpp/json.h>
27
28
29 namespace dpp::events {
30
31
32 /**
33 * @brief Handle event
34 *
35 * @param client Websocket client (current shard)
36 * @param j JSON data for the event
37 * @param raw Raw JSON string
38 */
39 void message_reaction_remove::handle(discord_client* client, json &j, const std::string &raw) {
40 if (!client->creator->on_message_reaction_remove.empty()) {
41 json &d = j["d"];
42
43 message_reaction_remove_t mrr(client->owner, client->shard_id, raw);
44
45 snowflake guild_id = snowflake_not_null(&d, "guild_id");
46 snowflake user_id = snowflake_not_null(&d, "user_id");
47 snowflake channel_id = snowflake_not_null(&d, "channel_id");
48 snowflake message_id = snowflake_not_null(&d, "message_id");
49
50 guild* g = find_guild(guild_id);
51 channel* c = dpp::find_channel(mrr.channel_id);
52
53 mrr.reacting_guild = g ? *g : guild{};
54 mrr.reacting_guild.id = guild_id;
55
56 mrr.reacting_user_id = user_id;
57
58 mrr.channel_id = channel_id;
59 mrr.reacting_channel = c ? *c : channel{};
60 mrr.reacting_channel.id = channel_id;
61
62 mrr.message_id = message_id;
63 mrr.reacting_emoji = dpp::emoji().fill_from_json(&(d["emoji"]));
64
65 if (mrr.channel_id && mrr.message_id) {
66 client->creator->queue_work(1, [c = client->creator, mrr]() {
67 c->on_message_reaction_remove.call(mrr);
68 });
69 }
70 }
71 }
72
73 };