Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169#include <cstdlib>#include <unordered_set>
#include "utils.hpp"
boolcheckAuth (std::string userID){ std::ifstream file ("whitelist.lunar");
if (!file.is_open ()) { std::cerr << "Error opening whitelist file.\n"; return false; }
bool isAuth = false; std::string line; while (std::getline (file, line)) { if (line == userID) { isAuth = true; break; } } file.close ();
return isAuth;}
voidcheckBan (dpp::cluster &bot, dpp::snowflake guildID){ std::unordered_set<std::string> blacklist; std::ifstream file ("blacklist.lunar");
if (!file.is_open ()) { std::cerr << "Error opening blacklist file.\n"; return; }
std::string line; while (std::getline (file, line)) { if (!line.empty ()) { blacklist.insert (line); } } file.close ();
bot.guild_get_members ( guildID, 1000, 0, [&bot, guildID, blacklist] (const dpp::confirmation_callback_t &callback) { if (callback.is_error ()) { std::cerr << "Failed to fetch guild members.\n"; return; }
if (!std::holds_alternative<dpp::guild_member_map> (callback.value)) { std::cerr << "Unexpected data type returned from get_get_members.\n"; return; }
auto member_map = std::get<dpp::guild_member_map> (callback.value);
for (const auto &[userID, member] : member_map) { (void)member; std::string s_userID = std::to_string (userID);
if (blacklist.find (s_userID) != blacklist.end ()) { bot.guild_ban_add ( guildID, userID, 0, [s_userID] ( const dpp::confirmation_callback_t &ban_callback) { if (ban_callback.is_error ()) { std::cerr << "Failed to ban: " << s_userID << ".\n"; } else { std::cout << "Successfully banned blacklisted user: " << s_userID << ".\n"; } }); } } });}
voidloadDotenv (const std::string &filename){ std::ifstream file (filename); if (!file.is_open ()) { std::cerr << "Warning: Could not open " << filename << "!\n"; return; }
std::string line; while (std::getline (file, line)) { if (line.empty () || line[0] == '#') continue;
std::size_t delimiterPosition = line.find ('='); if (delimiterPosition == std::string::npos) continue;
std::string key = line.substr (0, delimiterPosition); std::string value = line.substr (delimiterPosition + 1);
key.erase (key.find_last_not_of (" \t") + 1); value.erase (0, value.find_first_not_of (" \t")); value.erase (value.find_last_not_of (" \t") + 1);
if (value.size () >= 2) { char first = value.front (); char last = value.back (); if ((first == '"' && last == '"') || (first == '\'' && last == '\'')) { value = value.substr (1, value.size () - 2); } }
#if defined(_WIN32) _putenv_s (key.c_str (), value.c_str ());#else setenv (key.c_str (), value.c_str (), 1);#endif }}
boolsearchBlacklist (std::string userID){ std::ifstream file ("blacklist.lunar");
if (!file.is_open ()) { std::cerr << "Error opening blacklist file.\n"; return false; }
bool isBlacklisted = false; std::string line; while (std::getline (file, line)) { if (line == userID) { isBlacklisted = true; break; } } file.close ();
return isBlacklisted;}