Using macro for command names

This commit is contained in:
2025-07-22 17:15:46 +03:00
parent fcab736436
commit ceaf2a0c2d
4 changed files with 30 additions and 18 deletions

View File

@@ -5,9 +5,11 @@
#define CURRENCY_NAME "Night Coin" #define CURRENCY_NAME "Night Coin"
// Command ping // Command ping
#define COMMAND_PING "ping"
#define COMMAND_PING_DESCRIPTION "Ping-pong test" #define COMMAND_PING_DESCRIPTION "Ping-pong test"
// Command get_pfp // Command get_pfp
#define COMMAND_GET_PFP "get_pfp"
#define COMMAND_GET_PFP_DESCRIPTION \ #define COMMAND_GET_PFP_DESCRIPTION \
"Get someone elses profile picture as an image" "Get someone elses profile picture as an image"
#define COMMAND_GET_PFP_ARGS_USER \ #define COMMAND_GET_PFP_ARGS_USER \
@@ -25,6 +27,7 @@
") and their [server profile picture](" + guildpfp + ")" ") and their [server profile picture](" + guildpfp + ")"
// Command about // Command about
#define COMMAND_ABOUT "about"
#define COMMAND_ABOUT_DESCRIPTION "Info about the bot" #define COMMAND_ABOUT_DESCRIPTION "Info about the bot"
#define COMMAND_ABOUT_RESPONSE \ #define COMMAND_ABOUT_RESPONSE \
"## " BOT_NAME " " BOT_VERSION \ "## " BOT_NAME " " BOT_VERSION \
@@ -33,6 +36,8 @@
"[D++](<https://dpp.dev/>) and tears." "[D++](<https://dpp.dev/>) and tears."
// Command balance/bal // Command balance/bal
#define COMMAND_BALANCE "balance"
#define COMMAND_BALANCE_SHORT "bal"
#define COMMAND_BALANCE_DESCRIPTION "See someone's balance of " CURRENCY_NAME #define COMMAND_BALANCE_DESCRIPTION "See someone's balance of " CURRENCY_NAME
#define COMMAND_BALANCE_USER_DESCRIPTION \ #define COMMAND_BALANCE_USER_DESCRIPTION \
"Leave this blank if you want to see your own balance" "Leave this blank if you want to see your own balance"
@@ -42,6 +47,7 @@
"<@!" + person + "> currently has " + balance + " " CURRENCY_NAME "(s)" "<@!" + person + "> currently has " + balance + " " CURRENCY_NAME "(s)"
// Command pay // Command pay
#define COMMAND_PAY "pay"
#define COMMAND_PAY_DESCRIPTION "Send someone some amount of " CURRENCY_NAME "s" #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_USER_DESCRIPTION "Who do you want to pay"
#define COMMAND_PAY_ARGS_AMOUNT_DESCRIPTION "How much do you want to pay" #define COMMAND_PAY_ARGS_AMOUNT_DESCRIPTION "How much do you want to pay"
@@ -52,6 +58,7 @@
"Successfully sent <@!" + recipient + "> " + amount + " " CURRENCY_NAME "(s)!" "Successfully sent <@!" + recipient + "> " + amount + " " CURRENCY_NAME "(s)!"
// Command print_money // Command print_money
#define COMMAND_PRINT_MONEY "print_money"
#define COMMAND_PRINT_DESCRIPTION "Allows the admin to print money on-demand" #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_ARGS_AMOUNT_DESCRIPTION "How much are we printing boss?"
#define COMMAND_PRINT_FAIL_NO_PRIVILIEGE(recipient) \ #define COMMAND_PRINT_FAIL_NO_PRIVILIEGE(recipient) \
@@ -61,6 +68,7 @@
recipient + "> !" recipient + "> !"
// Command burn_money // Command burn_money
#define COMMAND_BURN_MONEY "burn_money"
#define COMMAND_BURN_DESCRIPTION \ #define COMMAND_BURN_DESCRIPTION \
"Allows the admin to burn money, burn baby burn!" "Allows the admin to burn money, burn baby burn!"
#define COMMAND_BURN_ARGS_AMOUNT_DESCRIPTION "How much are we burning?" #define COMMAND_BURN_ARGS_AMOUNT_DESCRIPTION "How much are we burning?"
@@ -73,6 +81,7 @@
recipient + "> !" recipient + "> !"
// Command money_leaderboard // Command money_leaderboard
#define COMMAND_MONEY_LEADERBOARD "money_leaderboard"
#define COMMAND_MONEY_LEADERBOARD_DESCRIPTION \ #define COMMAND_MONEY_LEADERBOARD_DESCRIPTION \
"See who are the wealthiest members of the server, and who are... less " \ "See who are the wealthiest members of the server, and who are... less " \
"fortunate." "fortunate."

View File

@@ -15,26 +15,27 @@ void deleteCommands(const dpp::ready_t &event, dpp::cluster &bot) {
void createCommands(const dpp::ready_t &event, dpp::cluster &bot) { void createCommands(const dpp::ready_t &event, dpp::cluster &bot) {
bot.global_command_create( bot.global_command_create(
dpp::slashcommand("ping", COMMAND_PING_DESCRIPTION, bot.me.id)); dpp::slashcommand(COMMAND_PING, COMMAND_PING_DESCRIPTION, bot.me.id));
std::vector<dpp::slashcommand> guildCommands{ std::vector<dpp::slashcommand> guildCommands{
// Other commands // Other commands
dpp::slashcommand("about", COMMAND_ABOUT_DESCRIPTION, bot.me.id), dpp::slashcommand(COMMAND_ABOUT, COMMAND_ABOUT_DESCRIPTION, bot.me.id),
dpp::slashcommand("get_pfp", COMMAND_GET_PFP_DESCRIPTION, bot.me.id) dpp::slashcommand(COMMAND_GET_PFP, COMMAND_GET_PFP_DESCRIPTION, bot.me.id)
.add_option(dpp::command_option(dpp::command_option_type::co_user, .add_option(dpp::command_option(dpp::command_option_type::co_user,
"user", COMMAND_GET_PFP_ARGS_USER, "user", COMMAND_GET_PFP_ARGS_USER,
true)), true)),
// Money related commands // Money related commands
dpp::slashcommand("balance", COMMAND_BALANCE_DESCRIPTION, bot.me.id) dpp::slashcommand(COMMAND_BALANCE, COMMAND_BALANCE_DESCRIPTION, bot.me.id)
.add_option(dpp::command_option(dpp::command_option_type::co_user, .add_option(dpp::command_option(dpp::command_option_type::co_user,
"user", "user",
COMMAND_BALANCE_USER_DESCRIPTION)), COMMAND_BALANCE_USER_DESCRIPTION)),
dpp::slashcommand("bal", COMMAND_BALANCE_DESCRIPTION, bot.me.id) dpp::slashcommand(COMMAND_BALANCE_SHORT, COMMAND_BALANCE_DESCRIPTION,
bot.me.id)
.add_option(dpp::command_option(dpp::command_option_type::co_user, .add_option(dpp::command_option(dpp::command_option_type::co_user,
"user", "user",
COMMAND_BALANCE_USER_DESCRIPTION)), COMMAND_BALANCE_USER_DESCRIPTION)),
dpp::slashcommand("pay", COMMAND_PAY_DESCRIPTION, bot.me.id) dpp::slashcommand(COMMAND_PAY, COMMAND_PAY_DESCRIPTION, bot.me.id)
.add_option(dpp::command_option( .add_option(dpp::command_option(
dpp::command_option_type::co_user, "recipient", dpp::command_option_type::co_user, "recipient",
COMMAND_PAY_ARGS_USER_DESCRIPTION, true)) COMMAND_PAY_ARGS_USER_DESCRIPTION, true))
@@ -42,17 +43,18 @@ void createCommands(const dpp::ready_t &event, dpp::cluster &bot) {
dpp::command_option_type::co_integer, "amount", dpp::command_option_type::co_integer, "amount",
COMMAND_PAY_ARGS_AMOUNT_DESCRIPTION, true) COMMAND_PAY_ARGS_AMOUNT_DESCRIPTION, true)
.set_min_value(1)), .set_min_value(1)),
dpp::slashcommand("print_money", COMMAND_PRINT_DESCRIPTION, bot.me.id) dpp::slashcommand(COMMAND_PRINT_MONEY, COMMAND_PRINT_DESCRIPTION,
bot.me.id)
.add_option(dpp::command_option( .add_option(dpp::command_option(
dpp::command_option_type::co_integer, "amount", dpp::command_option_type::co_integer, "amount",
COMMAND_PRINT_ARGS_AMOUNT_DESCRIPTION, true) COMMAND_PRINT_ARGS_AMOUNT_DESCRIPTION, true)
.set_min_value(1)), .set_min_value(1)),
dpp::slashcommand("burn_money", COMMAND_BURN_DESCRIPTION, bot.me.id) dpp::slashcommand(COMMAND_BURN_MONEY, COMMAND_BURN_DESCRIPTION, bot.me.id)
.add_option(dpp::command_option( .add_option(dpp::command_option(
dpp::command_option_type::co_integer, "amount", dpp::command_option_type::co_integer, "amount",
COMMAND_BURN_ARGS_AMOUNT_DESCRIPTION, true) COMMAND_BURN_ARGS_AMOUNT_DESCRIPTION, true)
.set_min_value(1)), .set_min_value(1)),
dpp::slashcommand("money_leaderboard", dpp::slashcommand(COMMAND_MONEY_LEADERBOARD,
COMMAND_MONEY_LEADERBOARD_DESCRIPTION, bot.me.id), COMMAND_MONEY_LEADERBOARD_DESCRIPTION, bot.me.id),
}; };

View File

@@ -6,12 +6,12 @@
std::unordered_map< std::unordered_map<
std::string, std::string,
std::function<void(const dpp::slashcommand_t &event, dpp::cluster &bot)>> std::function<void(const dpp::slashcommand_t &event, dpp::cluster &bot)>>
Commands{{"ping", commandPing}, Commands{{COMMAND_PING, commandPing},
{"about", commandAbout}, {COMMAND_ABOUT, commandAbout},
{"balance", commandBalance}, {COMMAND_BALANCE, commandBalance},
{"bal", commandBalance}, {COMMAND_BALANCE_SHORT, commandBalance},
{"pay", commandPay}, {COMMAND_PAY, commandPay},
{"print_money", commandPrintMoney}, {COMMAND_PRINT_MONEY, commandPrintMoney},
{"burn_money", commandBurnMoney}, {COMMAND_BURN_MONEY, commandBurnMoney},
{"money_leaderboard", commandMoneyLeaderboard}, {COMMAND_MONEY_LEADERBOARD, commandMoneyLeaderboard},
{"get_pfp", commandGetPFP}}; {COMMAND_GET_PFP, commandGetPFP}};

View File

@@ -23,6 +23,7 @@ void commandGetPFP(const dpp::slashcommand_t &event, dpp::cluster &bot) {
event.reply(COMMAND_GET_PFP_FAIL_NOT_A_MEMBER(userID.str())); event.reply(COMMAND_GET_PFP_FAIL_NOT_A_MEMBER(userID.str()));
return; return;
} }
std::string memberUrl = member.get_avatar_url(DPP_AVATAR_GET_ARGS), std::string memberUrl = member.get_avatar_url(DPP_AVATAR_GET_ARGS),
discordUrl = discordUrl =
member.get_user()->get_avatar_url(DPP_AVATAR_GET_ARGS); member.get_user()->get_avatar_url(DPP_AVATAR_GET_ARGS);