#include #include #include #include "slashcommands.hpp" #include "utils.hpp" void registerSlashCommands (dpp::cluster &bot) { bot.global_command_create ( dpp::slashcommand ("dice", "Rolls a random number.", bot.me.id) .add_option (dpp::command_option (dpp::co_integer, "max", "Max number.", true))); bot.global_command_create (dpp::slashcommand ( "force-search", "Finds all blacklisted members in the current server. [WHITELIST ONLT]", bot.me.id)); bot.global_command_create ( dpp::slashcommand ("ping", "Returns pong.", bot.me.id)); bot.global_command_create ( dpp::slashcommand ("report", "Report someone to RGN. [WHITELIST ONLY]", bot.me.id) .add_option (dpp::command_option ( dpp::co_string, "id", "ID of the person you want to report.", true)) .add_option (dpp::command_option ( dpp::co_string, "reason", "Why should this person be blacklisted?", true))); bot.global_command_create ( dpp::slashcommand ("search", "Search the blacklist for an ID. [WHITELIST ONLY]", bot.me.id) .add_option (dpp::command_option ( dpp::co_string, "id", "ID of the person to search.", true))); bot.global_command_create (dpp::slashcommand ( "status", "Shows the current status of the bot.", bot.me.id)); } void c_dice (const dpp::slashcommand_t &event); void c_forceSearch (dpp::cluster &bot, const dpp::slashcommand_t &event); void c_report (dpp::cluster &bot, const dpp::slashcommand_t &event); void c_search (const dpp::slashcommand_t &event); void c_status (const dpp::slashcommand_t &event); void runSlashCommand (dpp::cluster &bot, const dpp::slashcommand_t &event) { if (event.command.get_command_name () == "dice") { c_dice (event); } else if (event.command.get_command_name () == "force-search") { c_forceSearch (bot, event); } else if (event.command.get_command_name () == "ping") { event.reply ("Pong!"); } else if (event.command.get_command_name () == "report") { c_report (bot, event); } else if (event.command.get_command_name () == "search") { c_search (event); } else if (event.command.get_command_name () == "status") { c_status (event); } } void c_dice (const dpp::slashcommand_t &event) { int max = std::get (event.get_parameter ("max")); std::random_device rd; std::mt19937 gen (rd ()); std::uniform_int_distribution distr (1, max); std::string rolledText = "You rolled a " + std::to_string (distr (gen)); dpp::embed embed = dpp::embed () .set_color (dpp::colors::purple_amethyst) .set_title ("Dice") .set_description (rolledText); dpp::message msg (event.command.channel_id, embed); event.reply (msg); } void c_forceSearch (dpp::cluster &bot, const dpp::slashcommand_t &event) { dpp::snowflake guildID = event.command.guild_id; std::string userID = std::to_string (event.command.usr.id); bool isAuth = checkAuth (userID); if (isAuth) { checkBan (bot, guildID); } else { dpp::embed embed = dpp::embed () .set_color (dpp::colors::purple_amethyst) .set_title ("Error!") .set_description ("You are not whitelisted."); dpp::message msg = dpp::message (event.command.channel_id, embed) .set_flags (dpp::m_ephemeral); event.reply (msg); } dpp::embed embed = dpp::embed () .set_color (dpp::colors::purple_amethyst) .set_title ("Force Search Initiated") .set_description ("Scanning the server and scanning against " "the blacklist database..."); dpp::message msg = dpp::message (event.command.channel_id, embed) .set_flags (dpp::m_ephemeral); event.reply (msg); } void c_report (dpp::cluster &bot, const dpp::slashcommand_t &event) { std::string id = std::get (event.get_parameter ("id")); std::string reason = std::get (event.get_parameter ("reason")); std::string userID = std::to_string (event.command.usr.id); const char *s_channelID = std::getenv ("REPORT_CHANNEL_ID"); dpp::snowflake channelID = std::stoull (s_channelID); bool isAuth = checkAuth (userID); if (isAuth) { dpp::embed embed = dpp::embed () .set_color (dpp::colors::purple_amethyst) .set_title ("Report received.") .add_field ("ID", id) .add_field ("Reason", reason) .add_field ("Reporter", event.command.usr.username); dpp::message msg = dpp::message (channelID, embed); dpp::embed embedReply = dpp::embed () .set_color (dpp::colors::purple_amethyst) .set_title ("Report sent.") .set_description ("Report sent successfully"); dpp::message msgReply = dpp::message (event.command.channel_id, embedReply); bot.message_create (msg); event.reply (msgReply); } else { dpp::embed embed = dpp::embed () .set_color (dpp::colors::purple_amethyst) .set_title ("Error!") .set_description ("You are not whitelisted."); dpp::message msg = dpp::message (event.command.channel_id, embed) .set_flags (dpp::m_ephemeral); event.reply (msg); } } void c_search (const dpp::slashcommand_t &event) { std::string id = std::get (event.get_parameter ("id")); std::string userID = std::to_string (event.command.usr.id); bool isAuth = checkAuth (userID); if (isAuth) { bool isBlacklisted = searchBlacklist (id); if (isBlacklisted) { dpp::embed embed = dpp::embed () .set_color (dpp::colors::purple_amethyst) .set_title ("Blacklisted!") .set_description ("This ID is blacklisted."); dpp::message msg = dpp::message (event.command.channel_id, embed) .set_flags (dpp::m_ephemeral); event.reply (msg); } else { dpp::embed embed = dpp::embed () .set_color (dpp::colors::purple_amethyst) .set_title ("Not Blacklisted!") .set_description ("This ID is not blacklisted."); dpp::message msg = dpp::message (event.command.channel_id, embed) .set_flags (dpp::m_ephemeral); event.reply (msg); } } else { dpp::embed embed = dpp::embed () .set_color (dpp::colors::purple_amethyst) .set_title ("Error!") .set_description ("You are not whitelisted."); dpp::message msg = dpp::message (event.command.channel_id, embed) .set_flags (dpp::m_ephemeral); event.reply (msg); } } void c_status (const dpp::slashcommand_t &event) { std::string serverCount = std::to_string (dpp::get_guild_count ()); std::ifstream file ("blacklist.lunar"); if (!file.is_open ()) { std::cerr << "Error opening blacklist file.\n"; return; } int lineCount = 0; std::string line; while (std::getline (file, line)) { lineCount++; } std::string s_lineCount = std::to_string (lineCount); dpp::embed embed = dpp::embed () .set_color (dpp::colors::purple_amethyst) .set_title ("Status") .set_description ("Current bot status.") .add_field ("Scanning", "ON", true) .add_field ("Server Count", serverCount, true) .add_field ("Blacklist Count", s_lineCount, true); dpp::message msg = dpp::message (event.command.channel_id, embed) .set_flags (dpp::m_ephemeral); event.reply (msg); }