Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle attachments and reactions for messages #14

Merged
merged 2 commits into from
May 7, 2021

Conversation

SarahIsWeird
Copy link
Contributor

Discord sends a list of all attachments in the JSON when transmitting a message object. Similarly, under certain circumstances a list of all reactions is transmitted. This PR adds both infos to the dpp::message object.

Firstly, there's a new attachment struct. It closely follows the official docs on what's present and what not.
Secondly, I've added one field to dpp::reaction, the emoji name. Discord sends it, and for non-custom reactions, this is often the only way to figure out which emoji was used to react.

Both are populated accordingly.

To accomplish this, a new struct was added: dpp::attachment. It represents an attachment, obviously.
@SarahIsWeird
Copy link
Contributor Author

This is an example file that showcases both new features.

#include <dpp/dpp.h>

int main() {
    dpp::cluster bot("token");

    bot.on_message_create([&bot](const dpp::message_create_t &event) {
        if (event.msg->attachments.size() == 0)
            return;

        bot.message_create(dpp::message(event.msg->channel_id, "Your message has attachments!"));
        // Do stuff with attachment url, width and height, ...
    });

    bot.on_message_reaction_add([&bot](const dpp::message_reaction_add_t &event) {
        bot.message_get(event.message_id, event.reacting_channel->id, [](const dpp::confirmation_callback_t &cb) {
            for (auto &reaction : ((dpp::message &) cb.value).reactions) {
                // Yes, this isn't that good of an idea. The emoji name doesn't actually need to be
                // populated. But it's just so you get the idea. :D
                std::cout << reaction.count << " people reacted with " << reaction.emoji_name << "." << std::endl;
            }
        });
    });

    bot.start(false);

    return 0;
}

@braindigitalis braindigitalis merged commit ae541f9 into brainboxdotcc:dev May 7, 2021
braindigitalis pushed a commit that referenced this pull request Jan 29, 2022
braindigitalis pushed a commit that referenced this pull request Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants