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

docs: Added emoji page #1019

Merged
merged 14 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docpages/example_code/using_emoji1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <dpp/dpp.h>
#include <dpp/unicode_emoji.h>

int main() {
dpp::cluster bot("Epic Token");

bot.on_log(dpp::utility::cout_logger());

/* We'll be using two emojis: shocked guy and animated mad face. */
dpp::emoji shocked("vahuyi", 1179366531856093214);
dpp::emoji mad("mad", 1117795317052616704, dpp::e_animated); /* We need this third argument, which is an emoji flag. */

bot.on_slashcommand([shocked, mad](const dpp::slashcommand_t& event) {
if (event.command.get_command_name() == "send-emojis") {

Henonicks marked this conversation as resolved.
Show resolved Hide resolved
/* Here we send our very informative message: three epic emojis. */
event.reply(dpp::unicode_emoji::nerd + shocked.get_mention() + mad.get_mention());
}
});

bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
dpp::slashcommand send("send-emojis", "Send the emojis", bot.me.id);
bot.global_bulk_command_create({ send });
Henonicks marked this conversation as resolved.
Show resolved Hide resolved
}
});

/* Start the bot! */
bot.start(dpp::st_wait);
return 0;
}
35 changes: 35 additions & 0 deletions docpages/example_code/using_emoji2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <dpp/dpp.h>
#include <dpp/unicode_emoji.h>

int main() {
dpp::cluster bot("Epic Token", dpp::i_default_intents | dpp::i_message_content);
/* The second argument is a bitmask of intents - i_message_content is needed to see the messages */

bot.on_log(dpp::utility::cout_logger());

/* We'll be using a shocked guy emoji */
dpp::emoji shocked("vahuyi", 1179366531856093214);
dpp::emoji mad("mad", 1117795317052616704, dpp::e_animated); /* We need this third argument, which is an emoji flag. */

bot.on_message_create([&bot, shocked, mad](const dpp::message_create_t& event) {
if (event.msg.content == "I'm hungry") {
/* But if they're hungry */
bot.message_add_reaction(event.msg.id, event.msg.channel_id, dpp::unicode_emoji::cut_of_meat);
/* Let's send some meat to the message, so they don't starve. They will thank us later. */

} else if (event.msg.content == "WHAT?") {
/* If some unknown content shocked the user */
bot.message_add_reaction(event.msg.id, event.msg.channel_id, shocked.format());
/* React to their message with a shocked guy */

} else if (event.msg.content == "I'm unsubscribing") {
/* They are angry! We should also be! */
bot.message_add_reaction(event.msg.id, event.msg.channel_id, mad.format());
/* React to their message with a mad emoji */
}
});

/* Start the bot! */
bot.start(dpp::st_wait);
return 0;
}
48 changes: 48 additions & 0 deletions docpages/example_code/using_emoji3.cpp
Henonicks marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <dpp/dpp.h>
#include <dpp/unicode_emoji.h>

int main() {
dpp::cluster bot("Epic Token");

bot.on_log(dpp::utility::cout_logger());

/* We now have a new character! That's for the select menu. */
dpp::emoji walter("walter_black", 1179374919088361544);
dpp::emoji mad("mad", 1117795317052616704, dpp::e_animated); /* We need this third argument, which is an emoji flag. */

/* The event is fired when someone issues your commands */
bot.on_slashcommand([walter, mad](const dpp::slashcommand_t& event) {
if (event.command.get_command_name() == "select") {
dpp::message msg(event.command.channel_id, "Now.");
msg.add_component(
dpp::component().add_component(
dpp::component()
.set_type(dpp::cot_selectmenu)
.set_placeholder("Say my name.")
.add_select_option(dpp::select_option("Do what?", "Yeah, you do.", "I don't have a damn clue what you're talking about.").set_emoji(dpp::unicode_emoji::thinking))
.add_select_option(dpp::select_option("Heisenberg", "You're goddamn right!", "The one and only").set_emoji(walter.name, walter.id))
.add_select_option(dpp::select_option("I'm unsubscribing", "Wait what", "Pure cruelty").set_emoji(mad.name, mad.id, mad.is_animated())) /* Since our mad emoji is animated, we should tell that to the function */
.set_id("myselectid")
)
);
event.reply(msg);
}
});

bot.on_select_click([](const dpp::select_click_t & event) {
event.reply(event.values[0]);
});

bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
/* Create and register a command when the bot is ready */
bot.global_command_create(dpp::slashcommand("select", "Select something at random!", bot.me.id), [&bot](const dpp::confirmation_callback_t& callback) {
std::cout << callback.http_info.body << std::endl;
Henonicks marked this conversation as resolved.
Show resolved Hide resolved
});
}
});

/* Start the bot! */
bot.start(dpp::st_wait);
return 0;
}
1 change: 1 addition & 0 deletions docpages/example_programs/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ This section lists examples that do not fit neatly into any of the categories ab
* \subpage cpp-eval-command-discord
* \subpage checking-member-permissions
* \subpage setting_status
* \subpage using-emoji
27 changes: 27 additions & 0 deletions docpages/example_programs/misc/using-emoji.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
\page using-emoji Sending Emoji
Henonicks marked this conversation as resolved.
Show resolved Hide resolved

Need your bot to use emoji? Then you've come to the right place! Here are shown 3 cases of where and how you would use emoji.
Henonicks marked this conversation as resolved.
Show resolved Hide resolved

First - sending emoji. You have to use its mention, which depends on the type. If it's a default emoji, you use the corresponding character. So, for example, if you wanted to send a nerd emoji, you would use the nerd unicode character. Now, custom emoji. There are two types: static and animated. Their mentions are `<:[name]:[id]>` and `<a:[name]:[id]>` consequently, where `[name]` means the emoji name and `[id]` is for its ID. When you send such mention, it automatically gets converted into your emoji. Here's an example of sending emojis:
Henonicks marked this conversation as resolved.
Show resolved Hide resolved

\include{cpp} using_emoji1.cpp

Now, our bot will send our epic emojis!

\image html using_emoji1.png

Sometimes there's something so interesting in the chat that we want to react to it. And while we see the emoji we react with, for bots, it's some plain text. There are different formats for different kinds of emoji when reacting, too. For unicode, it's simply its character, like when sending. For custom ones it's either `[name]:[id]` (if static) or `a:[name]:[id]` (if animated). Let's show our bot's honest reactions!
Henonicks marked this conversation as resolved.
Show resolved Hide resolved

\include{cpp} using_emoji2.cpp

Yay, our bot has emotions now!

\image html using_emoji2.png

Finally, select menus. They're lists that let you select an option with an emoji each and are an optional part of a message. These guys are covered \ref components3 "here". They require emoji components (name, ID, animated state) to come separately. Also, if the emoji you're using isn't animated, you don't have to specify that. If your emoji is unicode, the ID is optional, too, since both are defaulted to none (0/false).

\include{cpp} using_emoji3.cpp

The Cook appears.
Henonicks marked this conversation as resolved.
Show resolved Hide resolved

\image html using_emoji3.png
Binary file added docpages/images/using_emoji1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docpages/images/using_emoji2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docpages/images/using_emoji3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.