Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261#include <cstdint>#include <random>#include <unordered_set>
#include "slashcommands.hpp"#include "utils.hpp"
voidregisterSlashCommands (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);
voidrunSlashCommand (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); }}
voidc_dice (const dpp::slashcommand_t &event){ int max = std::get<long int> (event.get_parameter ("max"));
std::random_device rd; std::mt19937 gen (rd ()); std::uniform_int_distribution<int> 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);}
voidc_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);}
voidc_report (dpp::cluster &bot, const dpp::slashcommand_t &event){ std::string id = std::get<std::string> (event.get_parameter ("id")); std::string reason = std::get<std::string> (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); }}
voidc_search (const dpp::slashcommand_t &event){ std::string id = std::get<std::string> (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); }}
voidc_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);}