Added leaderboard for money
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#define CURRENCY_NAME "Night Coin"
|
||||
|
||||
// Command balance/bal
|
||||
#define COMMAND_BALANCE_DESCRIPTION "See someone's balance of " CURRENCY_NAME
|
||||
#define COMMAND_BALANCE_USER_DESCRIPTION \
|
||||
"Leave this blank if you want to see your own balance"
|
||||
@@ -8,6 +9,7 @@
|
||||
#define COMMAND_BALANCE_SOMEONE_ELSE_RESPONSE(person, balance) \
|
||||
"<@!" + person + "> currently has " + balance + " " CURRENCY_NAME "(s)"
|
||||
|
||||
// Command pay
|
||||
#define COMMAND_PAY_DESCRIPTION "Send someone some amount of " CURRENCY_NAME "s"
|
||||
#define COMMAND_PAY_ARGS_USER_DESCRIPTION "Who do you want to pay"
|
||||
#define COMMAND_PAY_ARGS_AMOUNT_DESCRIPTION "How much do you want to pay"
|
||||
@@ -17,6 +19,7 @@
|
||||
#define COMMAND_PAY_SUCCESS(recipient, amount) \
|
||||
"Successfully sent <@!" + recipient + "> " + amount + " " CURRENCY_NAME "(s)!"
|
||||
|
||||
// Command print_money
|
||||
#define COMMAND_PRINT_DESCRIPTION "Allows the admin to print money on-demand"
|
||||
#define COMMAND_PRINT_ARGS_AMOUNT_DESCRIPTION "How much are we printing boss?"
|
||||
#define COMMAND_PRINT_FAIL_NO_PRIVILIEGE(recipient) \
|
||||
@@ -25,6 +28,7 @@
|
||||
"Successfully printed " + amount + " " CURRENCY_NAME "(s) to <@!" + \
|
||||
recipient + "> !"
|
||||
|
||||
// Command burn_money
|
||||
#define COMMAND_BURN_DESCRIPTION \
|
||||
"Allows the admin to burn money, burn baby burn!"
|
||||
#define COMMAND_BURN_ARGS_AMOUNT_DESCRIPTION "How much are we burning?"
|
||||
@@ -35,3 +39,12 @@
|
||||
#define COMMAND_BURN_SUCCESS(recipient, amount) \
|
||||
"Successfully burned " + amount + " " CURRENCY_NAME "(s) to <@!" + \
|
||||
recipient + "> !"
|
||||
|
||||
// Command money_leaderboard
|
||||
#define COMMAND_MONEY_LEADERBOARD_DESCRIPTION \
|
||||
"See who are the wealthiest members of the server, and who are... less " \
|
||||
"fortunate."
|
||||
#define COMMAND_MONEY_LEADERBOARD_TEXT \
|
||||
"## Here are the top 15 most wealthiest people in the server.\n-# Note: if " \
|
||||
"you don't see yourself here it is either due to never interacting with " \
|
||||
"the bot, or having too low of a balance.\n"
|
||||
|
@@ -5,6 +5,7 @@
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/exception.h>
|
||||
#include <dpp/snowflake.h>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
@@ -74,6 +75,38 @@ void commandBurnMoney(const dpp::slashcommand_t &event) {
|
||||
COMMAND_BURN_SUCCESS(std::to_string(ADMIN_ID), std::to_string(amount)));
|
||||
}
|
||||
|
||||
void commandMoneyLeaderboard(const dpp::slashcommand_t &event) {
|
||||
std::string result;
|
||||
std::stringstream replyStream;
|
||||
execSQL("SELECT * FROM MONEY ORDER BY CASH DESC LIMIT 15;", &result);
|
||||
|
||||
replyStream << COMMAND_MONEY_LEADERBOARD_TEXT;
|
||||
|
||||
// AI code starts here
|
||||
std::stringstream ss(result);
|
||||
std::string token;
|
||||
uint8_t rank = 1;
|
||||
|
||||
while (std::getline(ss, token, ';')) {
|
||||
if (token.find("UID:") == 0) {
|
||||
std::string uid = token.substr(4); // Remove "UID:"
|
||||
|
||||
// Get the next token (CASH)
|
||||
if (std::getline(ss, token, ';')) {
|
||||
std::string cash = token.substr(5); // Remove "CASH:"
|
||||
replyStream << std::to_string(rank) << ". <@!" << uid << "> - " << cash
|
||||
<< " " << CURRENCY_NAME << "(s)"
|
||||
<< "\n";
|
||||
rank++;
|
||||
}
|
||||
}
|
||||
}
|
||||
// AI code ends here
|
||||
// I hate parsing strings, thank you AI
|
||||
|
||||
event.reply(replyStream.str());
|
||||
}
|
||||
|
||||
///
|
||||
/// HELPER INLINE METHODS
|
||||
///
|
||||
|
@@ -45,4 +45,9 @@ void createCommands(const dpp::ready_t &event, dpp::cluster &bot) {
|
||||
COMMAND_BURN_ARGS_AMOUNT_DESCRIPTION, true)
|
||||
.set_min_value(1)),
|
||||
GUILD);
|
||||
|
||||
bot.guild_command_create(
|
||||
dpp::slashcommand("money_leaderboard",
|
||||
COMMAND_MONEY_LEADERBOARD_DESCRIPTION, bot.me.id),
|
||||
GUILD);
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ void commandBalance(const dpp::slashcommand_t &event);
|
||||
void commandPay(const dpp::slashcommand_t &event);
|
||||
void commandPrintMoney(const dpp::slashcommand_t &event);
|
||||
void commandBurnMoney(const dpp::slashcommand_t &event);
|
||||
void commandMoneyLeaderboard(const dpp::slashcommand_t &event);
|
||||
|
||||
// Inline helpers
|
||||
inline void increaseFromUsersBalance(const dpp::snowflake userid,
|
||||
@@ -28,4 +29,5 @@ inline std::unordered_map<std::string,
|
||||
{"bal", commandBalance},
|
||||
{"pay", commandPay},
|
||||
{"print_money", commandPrintMoney},
|
||||
{"burn_money", commandBurnMoney}};
|
||||
{"burn_money", commandBurnMoney},
|
||||
{"money_leaderboard", commandMoneyLeaderboard}};
|
||||
|
Reference in New Issue
Block a user