Added ability to burn money
This commit is contained in:
@@ -24,3 +24,14 @@
|
||||
#define COMMAND_PRINT_SUCCESS(recipient, amount) \
|
||||
"Successfully printed " + amount + " " CURRENCY_NAME "(s) to <@!" + \
|
||||
recipient + "> !"
|
||||
|
||||
#define COMMAND_BURN_DESCRIPTION \
|
||||
"Allows the admin to burn money, burn baby burn!"
|
||||
#define COMMAND_BURN_ARGS_AMOUNT_DESCRIPTION "How much are we burning?"
|
||||
#define COMMAND_BURN_FAIL_NO_PRIVILIEGE(recipient) \
|
||||
"Only <@!" + recipient + "> can burn money!"
|
||||
#define COMMAND_BURN_FAIL_INSUFFICIENT_AMOUNT(amount) \
|
||||
"You do not have" + amount + " " CURRENCY_NAME "(s) to burn!"
|
||||
#define COMMAND_BURN_SUCCESS(recipient, amount) \
|
||||
"Successfully burned " + amount + " " CURRENCY_NAME "(s) to <@!" + \
|
||||
recipient + "> !"
|
||||
|
@@ -55,10 +55,28 @@ 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) {
|
||||
std::int64_t userid = event.command.get_issuing_user().id;
|
||||
|
||||
if (ADMIN_ID != userid) {
|
||||
event.reply(COMMAND_BURN_FAIL_NO_PRIVILIEGE(std::to_string(ADMIN_ID)));
|
||||
return;
|
||||
}
|
||||
std::uint64_t amount = std::get<std::int64_t>(event.get_parameter("amount"));
|
||||
|
||||
// Insufficient in balance
|
||||
if (!deductFromUsersBalance(ADMIN_ID, amount)) {
|
||||
event.reply(COMMAND_BURN_FAIL_INSUFFICIENT_AMOUNT(std::to_string(amount)));
|
||||
return;
|
||||
}
|
||||
|
||||
event.reply(
|
||||
COMMAND_BURN_SUCCESS(std::to_string(ADMIN_ID), std::to_string(amount)));
|
||||
}
|
||||
|
||||
///
|
||||
/// HELPER INLINE METHODS
|
||||
///
|
||||
|
||||
inline void increaseFromUsersBalance(const dpp::snowflake userid,
|
||||
std::uint64_t amount) {
|
||||
std::uint64_t balance = std::stoi(getUserBalance(userid));
|
||||
|
@@ -37,4 +37,12 @@ void createCommands(const dpp::ready_t &event, dpp::cluster &bot) {
|
||||
COMMAND_PRINT_ARGS_AMOUNT_DESCRIPTION, true)
|
||||
.set_min_value(1)),
|
||||
GUILD);
|
||||
|
||||
bot.guild_command_create(
|
||||
dpp::slashcommand("burn_money", COMMAND_BURN_DESCRIPTION, bot.me.id)
|
||||
.add_option(dpp::command_option(
|
||||
dpp::command_option_type::co_integer, "amount",
|
||||
COMMAND_BURN_ARGS_AMOUNT_DESCRIPTION, true)
|
||||
.set_min_value(1)),
|
||||
GUILD);
|
||||
}
|
||||
|
@@ -9,6 +9,7 @@ void commandPing(const dpp::slashcommand_t &event);
|
||||
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);
|
||||
|
||||
// Inline helpers
|
||||
inline void increaseFromUsersBalance(const dpp::snowflake userid,
|
||||
@@ -26,4 +27,5 @@ inline std::unordered_map<std::string,
|
||||
{"balance", commandBalance},
|
||||
{"bal", commandBalance},
|
||||
{"pay", commandPay},
|
||||
{"print_money", commandPrintMoney}};
|
||||
{"print_money", commandPrintMoney},
|
||||
{"burn_money", commandBurnMoney}};
|
||||
|
Reference in New Issue
Block a user