This commit is contained in:
@@ -1,18 +1,81 @@
|
|||||||
|
#include <appcommand.h>
|
||||||
#include <cluster.h>
|
#include <cluster.h>
|
||||||
#include <dispatcher.h>
|
#include <dispatcher.h>
|
||||||
#include <dotenv/dotenv.h>
|
#include <dotenv/dotenv.h>
|
||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
|
#include <message.h>
|
||||||
|
#include <once.h>
|
||||||
|
#include <restresults.h>
|
||||||
|
#include <snowflake.h>
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
dotenv::init();
|
dotenv::init();
|
||||||
std::string botToken = std::getenv("DISCORD_BOT");
|
std::string botToken = std::getenv("DISCORD_TOKEN");
|
||||||
|
if (botToken.empty()) {
|
||||||
|
std::cout
|
||||||
|
<< "Failed to load the discord token from .env or the environment"
|
||||||
|
<< std::endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
dpp::cluster bot(botToken);
|
dpp::cluster bot(botToken);
|
||||||
|
|
||||||
bot.on_log(dpp::utility::cout_logger());
|
bot.on_log(dpp::utility::cout_logger());
|
||||||
|
|
||||||
|
bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
|
||||||
|
if (event.command.get_command_name() == "pm") {
|
||||||
|
dpp::snowflake user;
|
||||||
|
|
||||||
|
if (event.get_parameter("user").index() == 0) {
|
||||||
|
user = event.command.get_issuing_user().id;
|
||||||
|
} else {
|
||||||
|
user = std::get<dpp::snowflake>(event.get_parameter("user"));
|
||||||
|
}
|
||||||
|
|
||||||
|
bot.direct_message_create(
|
||||||
|
user, dpp::message("Here's a private message!"),
|
||||||
|
[event, user](const dpp::confirmation_callback_t& callback) {
|
||||||
|
if (callback.is_error()) {
|
||||||
|
if (user == event.command.get_issuing_user().id) {
|
||||||
|
event.reply(
|
||||||
|
dpp::message("I couldnt send you a message.")
|
||||||
|
.set_flags(dpp::m_ephemeral));
|
||||||
|
} else {
|
||||||
|
event.reply(
|
||||||
|
dpp::message(
|
||||||
|
"I couldnt send a message to that user. "
|
||||||
|
"Please check that is a valid user.")
|
||||||
|
.set_flags(dpp::m_ephemeral));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user == event.command.get_issuing_user().id) {
|
||||||
|
event.reply(
|
||||||
|
dpp::message("I've sent you a private message")
|
||||||
|
.set_flags(dpp::m_ephemeral));
|
||||||
|
} else {
|
||||||
|
event.reply(
|
||||||
|
dpp::message(
|
||||||
|
"I've sent a private message to that user.")
|
||||||
|
.set_flags(dpp::m_ephemeral));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bot.on_ready([&bot](const dpp::ready_t& event) {
|
||||||
|
if (dpp::run_once<struct register_bot_commands>()) {
|
||||||
|
dpp::slashcommand command("pm", "Send a private message.",
|
||||||
|
bot.me.id);
|
||||||
|
command.add_option(dpp::command_option(
|
||||||
|
dpp::co_mentionable, "user", "The user to message", false));
|
||||||
|
bot.global_command_create(command);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
bot.start(dpp::st_wait);
|
bot.start(dpp::st_wait);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user