From 18573286bc1e279679f4d760e2c97c089dd946b5 Mon Sep 17 00:00:00 2001 From: cat Date: Tue, 22 Jul 2025 04:41:45 +0300 Subject: [PATCH] Added bot parameter to all methods and get_pfp --- languages/locale_en.hpp | 6 ++++++ src/Base/Entry.cpp | 5 +++-- src/CommandManagement.cpp | 12 ++++++++++-- src/Commands.cpp | 8 +++++--- src/Commands/MoneyCommands.cpp | 11 ++++++----- src/Commands/OtherCommands.cpp | 12 ++++++++++-- 6 files changed, 40 insertions(+), 14 deletions(-) diff --git a/languages/locale_en.hpp b/languages/locale_en.hpp index e759973..2bea00f 100644 --- a/languages/locale_en.hpp +++ b/languages/locale_en.hpp @@ -7,6 +7,12 @@ // Command ping #define COMMAND_PING_DESCRIPTION "Ping-pong test" +// Command get_pfp +#define COMMAND_GET_PFP_DESCRIPTION \ + "Get someone elses profile picture as a picture" +#define COMMAND_GET_PFP_ARGS_USER \ + "Whose profile picture do you want to get(it can be yourself)" + // Command about #define COMMAND_ABOUT_DESCRIPTION "Info about the bot" #define COMMAND_ABOUT_RESPONSE \ diff --git a/src/Base/Entry.cpp b/src/Base/Entry.cpp index b6c352d..e3bae60 100644 --- a/src/Base/Entry.cpp +++ b/src/Base/Entry.cpp @@ -2,6 +2,7 @@ #include "../CommandManagement.cpp" #include "../Databases.hpp" +#include #include #include #include @@ -17,10 +18,10 @@ int main(int argc, char **argv) { // Neat utility bot.on_log(dpp::utility::cout_logger()); - bot.on_slashcommand([](const dpp::slashcommand_t &event) { + bot.on_slashcommand([&bot](const dpp::slashcommand_t &event) { auto command = Commands.find(event.command.get_command_name()); if (command != Commands.end()) { - command->second(event); + command->second(event, bot); return; } event.reply("Could not find that command :("); diff --git a/src/CommandManagement.cpp b/src/CommandManagement.cpp index 97fb25a..274c271 100644 --- a/src/CommandManagement.cpp +++ b/src/CommandManagement.cpp @@ -3,8 +3,9 @@ #include #include -extern std::unordered_map> +extern std::unordered_map< + std::string, + std::function> Commands; void deleteCommands(const dpp::ready_t &event, dpp::cluster &bot) { @@ -63,4 +64,11 @@ void createCommands(const dpp::ready_t &event, dpp::cluster &bot) { dpp::slashcommand("money_leaderboard", COMMAND_MONEY_LEADERBOARD_DESCRIPTION, bot.me.id), GUILD); + + bot.guild_command_create( + dpp::slashcommand("get_pfp", COMMAND_GET_PFP_DESCRIPTION, bot.me.id) + .add_option(dpp::command_option(dpp::command_option_type::co_user, + "user", COMMAND_GET_PFP_ARGS_USER, + true)), + GUILD); } diff --git a/src/Commands.cpp b/src/Commands.cpp index 54c4220..f73578b 100644 --- a/src/Commands.cpp +++ b/src/Commands.cpp @@ -3,8 +3,9 @@ #include "Commands/OtherCommands.cpp" // Registry -std::unordered_map> +std::unordered_map< + std::string, + std::function> Commands{{"ping", commandPing}, {"about", commandAbout}, {"balance", commandBalance}, @@ -12,4 +13,5 @@ std::unordered_map // Actual commands -void commandBalance(const dpp::slashcommand_t &event) { +void commandBalance(const dpp::slashcommand_t &event, dpp::cluster &bot) { std::string person, balance; dpp::command_value id = event.get_parameter("user"); @@ -29,7 +29,7 @@ void commandBalance(const dpp::slashcommand_t &event) { event.reply(COMMAND_BALANCE_SOMEONE_ELSE_RESPONSE(person, balance)); } -void commandPay(const dpp::slashcommand_t &event) { +void commandPay(const dpp::slashcommand_t &event, dpp::cluster &bot) { std::string recipient = std::get(event.get_parameter("recipient")).str(); std::uint64_t amount = std::get(event.get_parameter("amount")); @@ -46,7 +46,7 @@ void commandPay(const dpp::slashcommand_t &event) { event.reply(COMMAND_PAY_SUCCESS(recipient, std::to_string(amount))); } -void commandPrintMoney(const dpp::slashcommand_t &event) { +void commandPrintMoney(const dpp::slashcommand_t &event, dpp::cluster &bot) { std::int64_t userid = event.command.get_issuing_user().id; if (ADMIN_ID != userid) { @@ -59,7 +59,7 @@ void commandPrintMoney(const dpp::slashcommand_t &event) { COMMAND_PRINT_SUCCESS(std::to_string(ADMIN_ID), std::to_string(amount))); } -void commandBurnMoney(const dpp::slashcommand_t &event) { +void commandBurnMoney(const dpp::slashcommand_t &event, dpp::cluster &bot) { std::int64_t userid = event.command.get_issuing_user().id; if (ADMIN_ID != userid) { @@ -78,7 +78,8 @@ 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) { +void commandMoneyLeaderboard(const dpp::slashcommand_t &event, + dpp::cluster &bot) { std::string result; std::stringstream replyStream; execSQL("SELECT * FROM MONEY ORDER BY CASH DESC LIMIT 15;", &result); diff --git a/src/Commands/OtherCommands.cpp b/src/Commands/OtherCommands.cpp index f577447..a659831 100644 --- a/src/Commands/OtherCommands.cpp +++ b/src/Commands/OtherCommands.cpp @@ -1,7 +1,15 @@ #include "../../settings.hpp" #include +#include +#include -void commandPing(const dpp::slashcommand_t &event) { event.reply("Pong"); } -void commandAbout(const dpp::slashcommand_t &event) { +void commandPing(const dpp::slashcommand_t &event, dpp::cluster &bot) { + event.reply("Pong"); +} +void commandAbout(const dpp::slashcommand_t &event, dpp::cluster &bot) { event.reply(COMMAND_ABOUT_RESPONSE); } + +void commandGetPFP(const dpp::slashcommand_t &event, dpp::cluster &bot) { + dpp::snowflake user = std::get(event.get_parameter("user")); +}