From 24c82ee668b63a5d0de8208fae8773b69f973da6 Mon Sep 17 00:00:00 2001 From: cat Date: Sat, 19 Jul 2025 04:13:58 +0300 Subject: [PATCH] Added leaderboard for money --- languages/locale_en.hpp | 13 +++++++++++++ src/CommandEvents.cpp | 33 +++++++++++++++++++++++++++++++++ src/CommandManagement.cpp | 5 +++++ src/Commands.hpp | 4 +++- 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/languages/locale_en.hpp b/languages/locale_en.hpp index 97487eb..aacc39f 100644 --- a/languages/locale_en.hpp +++ b/languages/locale_en.hpp @@ -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" diff --git a/src/CommandEvents.cpp b/src/CommandEvents.cpp index cf65595..ff8d7ff 100644 --- a/src/CommandEvents.cpp +++ b/src/CommandEvents.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -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 /// diff --git a/src/CommandManagement.cpp b/src/CommandManagement.cpp index 1ada7c9..36b0446 100644 --- a/src/CommandManagement.cpp +++ b/src/CommandManagement.cpp @@ -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); } diff --git a/src/Commands.hpp b/src/Commands.hpp index d12eddc..6453dd3 100644 --- a/src/Commands.hpp +++ b/src/Commands.hpp @@ -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