Added ability to see others balance

This commit is contained in:
2025-07-19 02:53:54 +03:00
parent ec75cd32be
commit 1421d794a4
3 changed files with 34 additions and 6 deletions

View File

@@ -1,14 +1,30 @@
#include "Base/SQL.hpp"
#include "Commands.hpp"
#include <cstdint>
#include <dpp/appcommand.h>
#include <dpp/dispatcher.h>
#include <dpp/exception.h>
#include <dpp/snowflake.h>
#include <string>
#include <variant>
void commandPing(const dpp::slashcommand_t &event) { event.reply("Pong"); }
void commandBalance(const dpp::slashcommand_t &event) {
std::string balance = getUserBalance(event.command.get_issuing_user().id);
event.reply(COMMAND_BALANCE_RESPONSE(balance));
std::string person, balance;
dpp::command_value id = event.get_parameter("user");
// Weirdest thing ever
if (std::holds_alternative<std::monostate>(id)) {
person = event.command.get_issuing_user().id;
balance = getUserBalance(person);
event.reply(COMMAND_BALANCE_SELF_RESPONSE(balance));
return;
}
person = std::get<dpp::snowflake>(id).str();
balance = getUserBalance(person);
event.reply(COMMAND_BALANCE_SOMEONE_ELSE_RESPONSE(person, balance));
}
void commandPay(const dpp::slashcommand_t &event) {

View File

@@ -7,10 +7,18 @@ void createCommands(const dpp::ready_t &event, dpp::cluster &bot) {
// Money related stuff
bot.guild_command_create(
dpp::slashcommand("balance", COMMAND_BALANCE_DESCRIPTION, bot.me.id),
dpp::slashcommand("balance", COMMAND_BALANCE_DESCRIPTION, bot.me.id)
.add_option(dpp::command_option(dpp::command_option_type::co_user,
"user",
COMMAND_BALANCE_USER_DESCRIPTION)),
GUILD);
bot.guild_command_create(
dpp::slashcommand("bal", COMMAND_BALANCE_DESCRIPTION, bot.me.id), GUILD);
dpp::slashcommand("bal", COMMAND_BALANCE_DESCRIPTION, bot.me.id)
.add_option(dpp::command_option(dpp::command_option_type::co_user,
"user",
COMMAND_BALANCE_USER_DESCRIPTION)),
GUILD);
bot.guild_command_create(
dpp::slashcommand("pay", COMMAND_PAY_DESCRIPTION, bot.me.id)
.add_option(dpp::command_option(