02 - 01 - 01
This commit is contained in:
+1
-2
@@ -143,7 +143,7 @@ BreakFunctionDefinitionParameters: false
|
|||||||
BreakInheritanceList: BeforeColon
|
BreakInheritanceList: BeforeColon
|
||||||
BreakStringLiterals: true
|
BreakStringLiterals: true
|
||||||
BreakTemplateDeclarations: Yes
|
BreakTemplateDeclarations: Yes
|
||||||
ColumnLimit: 80
|
ColumnLimit: 120
|
||||||
CommentPragmas: "^ IWYU pragma:"
|
CommentPragmas: "^ IWYU pragma:"
|
||||||
CompactNamespaces: false
|
CompactNamespaces: false
|
||||||
ConstructorInitializerIndentWidth: 4
|
ConstructorInitializerIndentWidth: 4
|
||||||
@@ -355,4 +355,3 @@ WhitespaceSensitiveMacros:
|
|||||||
- STRINGIZE
|
- STRINGIZE
|
||||||
WrapNamespaceBodyWithEmptyLines: Leave
|
WrapNamespaceBodyWithEmptyLines: Leave
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,7 @@ int main() {
|
|||||||
dotenv::init();
|
dotenv::init();
|
||||||
// Make sure the DISCORD_TOKEN was loaded
|
// Make sure the DISCORD_TOKEN was loaded
|
||||||
if (!std::getenv("DISCORD_TOKEN")) {
|
if (!std::getenv("DISCORD_TOKEN")) {
|
||||||
std::cout
|
std::cout << "Failed to load the discord token from .env or the environment" << std::endl;
|
||||||
<< "Failed to load the discord token from .env or the environment"
|
|
||||||
<< std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
// Get the bot token
|
// Get the bot token
|
||||||
|
|||||||
@@ -13,9 +13,7 @@ int main() {
|
|||||||
dotenv::init();
|
dotenv::init();
|
||||||
// Check to make sure the token was loaded
|
// Check to make sure the token was loaded
|
||||||
if (!std::getenv("DISCORD_TOKEN")) {
|
if (!std::getenv("DISCORD_TOKEN")) {
|
||||||
std::cout
|
std::cout << "Failed to load the discord token from .env or the environment" << std::endl;
|
||||||
<< "Failed to load the discord token from .env or the environment"
|
|
||||||
<< std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
// Load in the token
|
// Load in the token
|
||||||
@@ -43,8 +41,7 @@ int main() {
|
|||||||
// Set the title url
|
// Set the title url
|
||||||
.set_url("https://dpp.dev")
|
.set_url("https://dpp.dev")
|
||||||
// Set the author info
|
// Set the author info
|
||||||
.set_author("Firewire", "https://dpp.dev",
|
.set_author("Firewire", "https://dpp.dev", "https://dpp.dev/DPP-Logo.png")
|
||||||
"https://dpp.dev/DPP-Logo.png")
|
|
||||||
.set_description("Description")
|
.set_description("Description")
|
||||||
// Set the thumbnail, this is a small image off the right
|
// Set the thumbnail, this is a small image off the right
|
||||||
.set_thumbnail("https://dpp.dev/DPP-Logo.png")
|
.set_thumbnail("https://dpp.dev/DPP-Logo.png")
|
||||||
@@ -55,9 +52,7 @@ int main() {
|
|||||||
// Set the main image, this will be the center large image
|
// Set the main image, this will be the center large image
|
||||||
.set_image("https://dpp.dev/DPP-Logo.png")
|
.set_image("https://dpp.dev/DPP-Logo.png")
|
||||||
// Set the footer
|
// Set the footer
|
||||||
.set_footer(dpp::embed_footer()
|
.set_footer(dpp::embed_footer().set_text("Footer text").set_icon("https://dpp.dev/DPP-Logo.png"))
|
||||||
.set_text("Footer text")
|
|
||||||
.set_icon("https://dpp.dev/DPP-Logo.png"))
|
|
||||||
// Add a timestamp,
|
// Add a timestamp,
|
||||||
// time(<arg>) returns a timer of <arg> seconds
|
// time(<arg>) returns a timer of <arg> seconds
|
||||||
// using a 0 for the arg just returns the current time
|
// using a 0 for the arg just returns the current time
|
||||||
@@ -77,8 +72,7 @@ int main() {
|
|||||||
// on_ready() is called once reconnected.
|
// on_ready() is called once reconnected.
|
||||||
// We dont want to re-register when this happens)
|
// We dont want to re-register when this happens)
|
||||||
if (dpp::run_once<struct register_bot_commands>()) {
|
if (dpp::run_once<struct register_bot_commands>()) {
|
||||||
bot.global_command_create(
|
bot.global_command_create(dpp::slashcommand("embed", "Send an embed", bot.me.id));
|
||||||
dpp::slashcommand("embed", "Send an embed", bot.me.id));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ int main() {
|
|||||||
dotenv::init();
|
dotenv::init();
|
||||||
// Check to make sure the token was loaded
|
// Check to make sure the token was loaded
|
||||||
if (!std::getenv("DISCORD_TOKEN")) {
|
if (!std::getenv("DISCORD_TOKEN")) {
|
||||||
std::cout
|
std::cout << "Failed to load the discord token from .env or the environment" << std::endl;
|
||||||
<< "Failed to load the discord token from .env or the environment"
|
|
||||||
<< std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
// Load in the token into a string
|
// Load in the token into a string
|
||||||
@@ -61,15 +59,11 @@ int main() {
|
|||||||
// Reply back with a message saying the direct message
|
// Reply back with a message saying the direct message
|
||||||
// failed to send
|
// failed to send
|
||||||
if (user == event.command.get_issuing_user().id) {
|
if (user == event.command.get_issuing_user().id) {
|
||||||
event.reply(
|
event.reply(dpp::message("I couldnt send you a message.").set_flags(dpp::m_ephemeral));
|
||||||
dpp::message("I couldnt send you a message.")
|
|
||||||
.set_flags(dpp::m_ephemeral));
|
|
||||||
} else {
|
} else {
|
||||||
event.reply(
|
event.reply(dpp::message("I couldnt send a message to that user. "
|
||||||
dpp::message(
|
"Please check that is a valid user.")
|
||||||
"I couldnt send a message to that user. "
|
.set_flags(dpp::m_ephemeral));
|
||||||
"Please check that is a valid user.")
|
|
||||||
.set_flags(dpp::m_ephemeral));
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -77,14 +71,10 @@ int main() {
|
|||||||
// In the case the direct message was able to be sent, send
|
// In the case the direct message was able to be sent, send
|
||||||
// a confirmation message
|
// a confirmation message
|
||||||
if (user == event.command.get_issuing_user().id) {
|
if (user == event.command.get_issuing_user().id) {
|
||||||
event.reply(
|
event.reply(dpp::message("I've sent you a private message").set_flags(dpp::m_ephemeral));
|
||||||
dpp::message("I've sent you a private message")
|
|
||||||
.set_flags(dpp::m_ephemeral));
|
|
||||||
} else {
|
} else {
|
||||||
event.reply(
|
event.reply(
|
||||||
dpp::message(
|
dpp::message("I've sent a private message to that user.").set_flags(dpp::m_ephemeral));
|
||||||
"I've sent a private message to that user.")
|
|
||||||
.set_flags(dpp::m_ephemeral));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -94,11 +84,9 @@ int main() {
|
|||||||
bot.on_ready([&bot](const dpp::ready_t& event) {
|
bot.on_ready([&bot](const dpp::ready_t& event) {
|
||||||
if (dpp::run_once<struct register_bot_commands>()) {
|
if (dpp::run_once<struct register_bot_commands>()) {
|
||||||
// Create the /pm slashcommand
|
// Create the /pm slashcommand
|
||||||
dpp::slashcommand command("pm", "Send a private message.",
|
dpp::slashcommand command("pm", "Send a private message.", bot.me.id);
|
||||||
bot.me.id);
|
|
||||||
// Add the "user" option to the command
|
// Add the "user" option to the command
|
||||||
command.add_option(dpp::command_option(
|
command.add_option(dpp::command_option(dpp::co_mentionable, "user", "The user to message", false));
|
||||||
dpp::co_mentionable, "user", "The user to message", false));
|
|
||||||
// Register the command with discord
|
// Register the command with discord
|
||||||
bot.global_command_create(command);
|
bot.global_command_create(command);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ int main() {
|
|||||||
dotenv::init();
|
dotenv::init();
|
||||||
// Make sure the DISCORD_TOKEN was loaded in
|
// Make sure the DISCORD_TOKEN was loaded in
|
||||||
if (!std::getenv("DISCORD_TOKEN")) {
|
if (!std::getenv("DISCORD_TOKEN")) {
|
||||||
std::cout
|
std::cout << "Failed to load the discord token from .env or the environment" << std::endl;
|
||||||
<< "Failed to load the discord token from .env or the environment"
|
|
||||||
<< std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
// Load in the token
|
// Load in the token
|
||||||
@@ -32,8 +30,7 @@ int main() {
|
|||||||
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
|
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
|
||||||
if (event.command.get_command_name() == "file") {
|
if (event.command.get_command_name() == "file") {
|
||||||
// Create the message
|
// Create the message
|
||||||
dpp::message msg(event.command.channel_id,
|
dpp::message msg(event.command.channel_id, "Hey there, I've got a file for you!");
|
||||||
"Hey there, I've got a file for you!");
|
|
||||||
// Add the "README.md" file to the message
|
// Add the "README.md" file to the message
|
||||||
msg.add_file("README.md", dpp::utility::read_file("README.md"));
|
msg.add_file("README.md", dpp::utility::read_file("README.md"));
|
||||||
// Send the message
|
// Send the message
|
||||||
@@ -43,16 +40,13 @@ int main() {
|
|||||||
// Handle the external command
|
// Handle the external command
|
||||||
if (event.command.get_command_name() == "external") {
|
if (event.command.get_command_name() == "external") {
|
||||||
bot.request("https://dpp.dev/DPP-Logo.png", dpp::m_get,
|
bot.request("https://dpp.dev/DPP-Logo.png", dpp::m_get,
|
||||||
[event](const dpp::http_request_completion_t&
|
[event](const dpp::http_request_completion_t& httpRequestCompletion) {
|
||||||
httpRequestCompletion) {
|
|
||||||
// Create the message
|
// Create the message
|
||||||
dpp::message msg(event.command.channel_id,
|
dpp::message msg(event.command.channel_id, "Heres an external image!");
|
||||||
"Heres an external image!");
|
|
||||||
// Make sure the http request was completed
|
// Make sure the http request was completed
|
||||||
if (httpRequestCompletion.status == 200) {
|
if (httpRequestCompletion.status == 200) {
|
||||||
// Add the body of the request to the msg
|
// Add the body of the request to the msg
|
||||||
msg.add_file("logo.png",
|
msg.add_file("logo.png", httpRequestCompletion.body);
|
||||||
httpRequestCompletion.body);
|
|
||||||
}
|
}
|
||||||
// Send the message
|
// Send the message
|
||||||
event.reply(msg);
|
event.reply(msg);
|
||||||
@@ -62,15 +56,13 @@ int main() {
|
|||||||
// Handle the embed command
|
// Handle the embed command
|
||||||
if (event.command.get_command_name() == "embed") {
|
if (event.command.get_command_name() == "embed") {
|
||||||
bot.request("https://dpp.dev/DPP-Logo.png", dpp::m_get,
|
bot.request("https://dpp.dev/DPP-Logo.png", dpp::m_get,
|
||||||
[event](const dpp::http_request_completion_t&
|
[event](const dpp::http_request_completion_t& httpRequestCompletion) {
|
||||||
httpRequestCompletion) {
|
|
||||||
// Create the message
|
// Create the message
|
||||||
dpp::message msg(event.command.channel_id, "");
|
dpp::message msg(event.command.channel_id, "");
|
||||||
// Make sure the http request completed
|
// Make sure the http request completed
|
||||||
if (httpRequestCompletion.status == 200) {
|
if (httpRequestCompletion.status == 200) {
|
||||||
// Add the file to the message
|
// Add the file to the message
|
||||||
msg.add_file("logo.png",
|
msg.add_file("logo.png", httpRequestCompletion.body);
|
||||||
httpRequestCompletion.body);
|
|
||||||
// Create the embed
|
// Create the embed
|
||||||
dpp::embed embed;
|
dpp::embed embed;
|
||||||
// Set the image for the embed as the image
|
// Set the image for the embed as the image
|
||||||
@@ -90,18 +82,15 @@ int main() {
|
|||||||
// Create and register the file command
|
// Create and register the file command
|
||||||
// This command will send a copy of the README.md file in the root
|
// This command will send a copy of the README.md file in the root
|
||||||
// of the project
|
// of the project
|
||||||
dpp::slashcommand fileCommand(
|
dpp::slashcommand fileCommand("file", "Send a message with a file attached!", bot.me.id);
|
||||||
"file", "Send a message with a file attached!", bot.me.id);
|
|
||||||
bot.global_command_create(fileCommand);
|
bot.global_command_create(fileCommand);
|
||||||
|
|
||||||
// Create and register the external command
|
// Create and register the external command
|
||||||
dpp::slashcommand externalCommand(
|
dpp::slashcommand externalCommand("external", "Send an image from an external source", bot.me.id);
|
||||||
"external", "Send an image from an external source", bot.me.id);
|
|
||||||
bot.global_command_create(externalCommand);
|
bot.global_command_create(externalCommand);
|
||||||
|
|
||||||
// Create and register the embed command
|
// Create and register the embed command
|
||||||
dpp::slashcommand embedCommand(
|
dpp::slashcommand embedCommand("embed", "Send a message with an image embed", bot.me.id);
|
||||||
"embed", "Send a message with an image embed", bot.me.id);
|
|
||||||
bot.global_command_create(embedCommand);
|
bot.global_command_create(embedCommand);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ int main() {
|
|||||||
// Load in the .env file into the environment
|
// Load in the .env file into the environment
|
||||||
dotenv::init();
|
dotenv::init();
|
||||||
if (!std::getenv("DISCORD_WEBHOOK")) {
|
if (!std::getenv("DISCORD_WEBHOOK")) {
|
||||||
std::cout << "Failed to get webhook from .env or environment"
|
std::cout << "Failed to get webhook from .env or environment" << std::endl;
|
||||||
<< std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,9 +19,7 @@ int main() {
|
|||||||
// Load the .env into the environment
|
// Load the .env into the environment
|
||||||
dotenv::init();
|
dotenv::init();
|
||||||
if (!std::getenv("DISCORD_TOKEN")) {
|
if (!std::getenv("DISCORD_TOKEN")) {
|
||||||
std::cout
|
std::cout << "Failed to get the discord token from the .env or enviroment" << std::endl;
|
||||||
<< "Failed to get the discord token from the .env or enviroment"
|
|
||||||
<< std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
// Get the bot token
|
// Get the bot token
|
||||||
@@ -37,57 +35,47 @@ int main() {
|
|||||||
if (event.command.get_command_name() == "msgs-get") {
|
if (event.command.get_command_name() == "msgs-get") {
|
||||||
int64_t limit = std::get<int64_t>(event.get_parameter("quantity"));
|
int64_t limit = std::get<int64_t>(event.get_parameter("quantity"));
|
||||||
|
|
||||||
bot.messages_get(
|
bot.messages_get(event.command.channel_id, 0, 0, 0, limit,
|
||||||
event.command.channel_id, 0, 0, 0, limit,
|
[event](const dpp::confirmation_callback_t& callback) {
|
||||||
[event](const dpp::confirmation_callback_t& callback) {
|
if (callback.is_error()) {
|
||||||
if (callback.is_error()) {
|
std::cout << callback.get_error().message << std::endl;
|
||||||
std::cout << callback.get_error().message << std::endl;
|
return;
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
auto messages = callback.get<dpp::message_map>();
|
auto messages = callback.get<dpp::message_map>();
|
||||||
|
|
||||||
std::string contents;
|
std::string contents;
|
||||||
for (const auto& x : messages) {
|
for (const auto& x : messages) {
|
||||||
contents += x.second.content + "\n";
|
contents += x.second.content + "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
event.reply(contents);
|
event.reply(contents);
|
||||||
});
|
});
|
||||||
} else if (event.command.get_command_name() == "channel-create") {
|
} else if (event.command.get_command_name() == "channel-create") {
|
||||||
dpp::channel channel = dpp::channel().set_name("test").set_guild_id(
|
dpp::channel channel = dpp::channel().set_name("test").set_guild_id(event.command.guild_id);
|
||||||
event.command.guild_id);
|
|
||||||
|
|
||||||
bot.channel_create(
|
bot.channel_create(channel, [&bot, event](const dpp::confirmation_callback_t& callback) -> void {
|
||||||
channel,
|
if (callback.is_error()) {
|
||||||
[&bot,
|
bot.log(dpp::loglevel::ll_error, callback.get_error().message);
|
||||||
event](const dpp::confirmation_callback_t& callback) -> void {
|
return;
|
||||||
if (callback.is_error()) {
|
}
|
||||||
bot.log(dpp::loglevel::ll_error,
|
|
||||||
callback.get_error().message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto channel = callback.get<dpp::channel>();
|
auto channel = callback.get<dpp::channel>();
|
||||||
dpp::message message =
|
dpp::message message =
|
||||||
dpp::message("The channel's name is '" + channel.name +
|
dpp::message("The channel's name is '" + channel.name + "', ID is '" + std::to_string(channel.id) +
|
||||||
"', ID is '" + std::to_string(channel.id) +
|
"', and the type is '" + std::to_string(channel.get_type()) + "'.");
|
||||||
"', and the type is '" +
|
event.reply(message);
|
||||||
std::to_string(channel.get_type()) + "'.");
|
});
|
||||||
event.reply(message);
|
|
||||||
});
|
|
||||||
} else if (event.command.get_command_name() == "msg-error") {
|
} else if (event.command.get_command_name() == "msg-error") {
|
||||||
bot.message_get(
|
bot.message_get(0, 0, [event](const dpp::confirmation_callback_t& callback) -> void {
|
||||||
0, 0,
|
if (callback.is_error()) {
|
||||||
[event](const dpp::confirmation_callback_t& callback) -> void {
|
event.reply(callback.get_error().message);
|
||||||
if (callback.is_error()) {
|
return;
|
||||||
event.reply(callback.get_error().message);
|
}
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto message = callback.get<dpp::message>();
|
auto message = callback.get<dpp::message>();
|
||||||
event.reply(message);
|
event.reply(message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -98,18 +86,14 @@ int main() {
|
|||||||
constexpr int64_t max_val{100};
|
constexpr int64_t max_val{100};
|
||||||
|
|
||||||
msgs_get.add_option(
|
msgs_get.add_option(
|
||||||
dpp::command_option(dpp::co_integer, "quantity",
|
dpp::command_option(dpp::co_integer, "quantity", "Quantity of messages to get. - Max 100")
|
||||||
"Quantity of messages to get. - Max 100")
|
|
||||||
.set_min_value(min_val)
|
.set_min_value(min_val)
|
||||||
.set_max_value(max_val));
|
.set_max_value(max_val));
|
||||||
|
|
||||||
dpp::slashcommand channel_create("channel-create",
|
dpp::slashcommand channel_create("channel-create", "Create a channel", bot.me.id);
|
||||||
"Create a channel", bot.me.id);
|
dpp::slashcommand msg_error("msg-error", "Get an error instead of a message", bot.me.id);
|
||||||
dpp::slashcommand msg_error(
|
|
||||||
"msg-error", "Get an error instead of a message", bot.me.id);
|
|
||||||
|
|
||||||
bot.global_bulk_command_create(
|
bot.global_bulk_command_create({msgs_get, channel_create, msg_error});
|
||||||
{msgs_get, channel_create, msg_error});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,7 @@ int main() {
|
|||||||
dotenv::init();
|
dotenv::init();
|
||||||
// Make sure the DISCORD_TOKEN environment var exists
|
// Make sure the DISCORD_TOKEN environment var exists
|
||||||
if (!std::getenv("DISCORD_TOKEN")) {
|
if (!std::getenv("DISCORD_TOKEN")) {
|
||||||
std::cout << "Failed to get DISCORD_TOKEN from .env or the environment."
|
std::cout << "Failed to get DISCORD_TOKEN from .env or the environment." << std::endl;
|
||||||
<< std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
// Get the bot token from DISCORD_TOKEN
|
// Get the bot token from DISCORD_TOKEN
|
||||||
@@ -25,31 +24,26 @@ int main() {
|
|||||||
dpp::cluster bot(botToken, dpp::i_default_intents | dpp::i_guild_members);
|
dpp::cluster bot(botToken, dpp::i_default_intents | dpp::i_guild_members);
|
||||||
|
|
||||||
// Create a lamba as a callback for when a reaction is removed
|
// Create a lamba as a callback for when a reaction is removed
|
||||||
bot.on_message_reaction_remove(
|
bot.on_message_reaction_remove([&bot](const dpp::message_reaction_remove_t& event) {
|
||||||
[&bot](const dpp::message_reaction_remove_t& event) {
|
// Get the user from the cache.
|
||||||
// Get the user from the cache.
|
// More then just users are cached, you can use the following
|
||||||
// More then just users are cached, you can use the following
|
// functions to interact with it
|
||||||
// functions to interact with it
|
// dpp::find_role()
|
||||||
// dpp::find_role()
|
// dpp::find_channel()
|
||||||
// dpp::find_channel()
|
// dpp::find_guild()
|
||||||
// dpp::find_guild()
|
// dpp::find_guild_member()
|
||||||
// dpp::find_guild_member()
|
// dpp::find_user()
|
||||||
// dpp::find_user()
|
dpp::user* reacting_user = dpp::find_user(event.reacting_user_id);
|
||||||
dpp::user* reacting_user = dpp::find_user(event.reacting_user_id);
|
|
||||||
|
|
||||||
// Make sure the user was actually found in the cache
|
// Make sure the user was actually found in the cache
|
||||||
if (!reacting_user) {
|
if (!reacting_user) {
|
||||||
bot.log(dpp::ll_info,
|
bot.log(dpp::ll_info, "User with id " + std::to_string(event.reacting_user_id) + " was not found.");
|
||||||
"User with id " +
|
return;
|
||||||
std::to_string(event.reacting_user_id) +
|
}
|
||||||
" was not found.");
|
// Log the action, using their username that we grabbed from the
|
||||||
return;
|
// cache
|
||||||
}
|
bot.log(dpp::ll_info, reacting_user->format_username() + " removed their reaction.");
|
||||||
// Log the action, using their username that we grabbed from the
|
});
|
||||||
// cache
|
|
||||||
bot.log(dpp::ll_info, reacting_user->format_username() +
|
|
||||||
" removed their reaction.");
|
|
||||||
});
|
|
||||||
|
|
||||||
// Start the bot
|
// Start the bot
|
||||||
bot.start(dpp::st_wait);
|
bot.start(dpp::st_wait);
|
||||||
|
|||||||
@@ -18,8 +18,7 @@ int main() {
|
|||||||
dotenv::init();
|
dotenv::init();
|
||||||
// Make sure the DISCORD_TOKEN env var exists
|
// Make sure the DISCORD_TOKEN env var exists
|
||||||
if (!std::getenv("DISCORD_TOKEN")) {
|
if (!std::getenv("DISCORD_TOKEN")) {
|
||||||
std::cout << "Failed to get DISCORD_TOKEN from .env or environment"
|
std::cout << "Failed to get DISCORD_TOKEN from .env or environment" << std::endl;
|
||||||
<< std::endl;
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
// Load in the bot token from the env
|
// Load in the bot token from the env
|
||||||
@@ -32,8 +31,7 @@ int main() {
|
|||||||
bot.on_message_create([](const dpp::message_create_t& event) {
|
bot.on_message_create([](const dpp::message_create_t& event) {
|
||||||
// Filter through the message content
|
// Filter through the message content
|
||||||
if (event.msg.content.find("bad word") != std::string::npos) {
|
if (event.msg.content.find("bad word") != std::string::npos) {
|
||||||
event.reply("That is not allowed here. Please, mind you language.",
|
event.reply("That is not allowed here. Please, mind you language.", true);
|
||||||
true);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,91 @@
|
|||||||
|
#include <appcommand.h>
|
||||||
|
#include <cluster.h>
|
||||||
|
#include <dispatcher.h>
|
||||||
|
#include <once.h>
|
||||||
|
|
||||||
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "dotenv.h"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
std::cout << "WIP" << std::endl;
|
// Load the .env file into the environment
|
||||||
|
dotenv::init();
|
||||||
|
// Make sure the DISCORD_TOKEN env var exists
|
||||||
|
if (!std::getenv("DISCORD_TOKEN") || !std::getenv("DISCORD_GUILD")) {
|
||||||
|
std::cout << "Failed to get DISCORD_TOKEN or DISCORD_GUILD from .env or environment" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// Load in the bot token
|
||||||
|
std::string botToken = std::getenv("DISCORD_TOKEN");
|
||||||
|
// Load in the guild id
|
||||||
|
std::string guildId = std::getenv("DISCORD_GUILD");
|
||||||
|
|
||||||
|
// Create the bot
|
||||||
|
dpp::cluster bot(botToken);
|
||||||
|
// Register a cout logger
|
||||||
|
bot.on_log(dpp::utility::cout_logger());
|
||||||
|
|
||||||
|
// Create a lambda callback for when a slashcommand is run
|
||||||
|
bot.on_slashcommand([](const dpp::slashcommand_t& event) {
|
||||||
|
// Filter through the command name and run its matching code
|
||||||
|
if (event.command.get_command_name() == "blep") {
|
||||||
|
// Get the "animal" option
|
||||||
|
std::string animal = std::get<std::string>(event.get_parameter("animal"));
|
||||||
|
// Reply back
|
||||||
|
event.reply(std::string("Blep! You chose") + animal);
|
||||||
|
} else if (event.command.get_command_name() == "blep-guild") {
|
||||||
|
std::string animal = std::get<std::string>(event.get_parameter("animal"));
|
||||||
|
event.reply(std::string("Blep! You chose") + animal);
|
||||||
|
} else if (event.command.get_command_name() == "ping") {
|
||||||
|
event.reply("Pong!");
|
||||||
|
} else if (event.command.get_command_name() == "pong") {
|
||||||
|
event.reply("Ping!");
|
||||||
|
} else if (event.command.get_command_name() == "ding") {
|
||||||
|
event.reply("Dong!");
|
||||||
|
} else if (event.command.get_command_name() == "dong") {
|
||||||
|
event.reply("Ding!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create a lambda for when the bot is ready
|
||||||
|
bot.on_ready([&bot, &guildId](const dpp::ready_t& event) {
|
||||||
|
// Only run once
|
||||||
|
if (dpp::run_once<struct register_bot_commands>()) {
|
||||||
|
// Create the "blep" global command
|
||||||
|
dpp::slashcommand globalCommand("blep", "Send a random adorable animal photo", bot.me.id);
|
||||||
|
// Add some options to the global command
|
||||||
|
globalCommand.add_option(
|
||||||
|
dpp::command_option(dpp::co_string, "animal", "The type of animal", true)
|
||||||
|
.add_choice(dpp::command_option_choice("Dog", std::string("animal_dog")))
|
||||||
|
.add_choice(dpp::command_option_choice("Cat", std::string("animal_cat")))
|
||||||
|
.add_choice(dpp::command_option_choice("Penguin", std::string("animal_penguin"))));
|
||||||
|
|
||||||
|
// Register the global command
|
||||||
|
bot.global_command_create(globalCommand);
|
||||||
|
|
||||||
|
// Create the guild only command
|
||||||
|
dpp::slashcommand guildCommand("blep-guild", "Send a random adorable animal photo", bot.me.id);
|
||||||
|
guildCommand.add_option(
|
||||||
|
dpp::command_option(dpp::co_string, "animal", "The type of animal", true)
|
||||||
|
.add_choice(dpp::command_option_choice("Dog", std::string("animal_dog")))
|
||||||
|
.add_choice(dpp::command_option_choice("Cat", std::string("animal_cat")))
|
||||||
|
.add_choice(dpp::command_option_choice("Penguin", std::string("animal_penguin"))));
|
||||||
|
// Register the guild command
|
||||||
|
bot.guild_command_create(guildCommand, guildId);
|
||||||
|
|
||||||
|
// Create some commands
|
||||||
|
dpp::slashcommand pingCommand("ping", "Pong", bot.me.id);
|
||||||
|
dpp::slashcommand pongCommand("pong", "ping", bot.me.id);
|
||||||
|
dpp::slashcommand dingCommand("ding", "dong", bot.me.id);
|
||||||
|
dpp::slashcommand dongCommand("dong", "ding", bot.me.id);
|
||||||
|
// Bulk register the commands using a list
|
||||||
|
bot.global_bulk_command_create({pingCommand, pongCommand, dingCommand, dongCommand});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Start the bot
|
||||||
|
bot.start(dpp::st_wait);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user