Added components, and moved command names to common.hpp
This commit is contained in:
@@ -1,19 +1,24 @@
|
|||||||
// Bot info
|
// Bot info
|
||||||
#define BOT_NAME "The Bartender Bot"
|
#define BOT_NAME "The Bartender Bot"
|
||||||
#define BOT_VERSION "v0.3-1"
|
#define BOT_VERSION "v0.4"
|
||||||
|
|
||||||
#define CURRENCY_NAME "Night Coin"
|
#define CURRENCY_NAME "Night Coin"
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
#define BUTTON_ACCEPT "Confirm"
|
#define BUTTON_ACCEPT "Confirm"
|
||||||
#define BUTTON_CANCEL "Cancel"
|
#define BUTTON_CANCEL "Cancel"
|
||||||
|
|
||||||
|
// Misc
|
||||||
|
#define REQUEST_CANCELLED "Your request has been cancelled. " RESPONSE_NO_CHARGE
|
||||||
|
#define RESPONSE_NO_CHARGE "You were not charged for this request."
|
||||||
|
|
||||||
|
///
|
||||||
|
/// COMMANDS
|
||||||
|
///
|
||||||
|
|
||||||
// Command ping
|
// Command ping
|
||||||
#define COMMAND_PING "ping"
|
|
||||||
#define COMMAND_PING_DESCRIPTION "Ping-pong test"
|
#define COMMAND_PING_DESCRIPTION "Ping-pong test"
|
||||||
|
|
||||||
// Command generate_report
|
// Command generate_report
|
||||||
#define COMMAND_GENERATE_REPORT "generate_report"
|
|
||||||
#define COMMAND_GENERATE_REPORT_DESCRIPTION "Generate a fake news report"
|
#define COMMAND_GENERATE_REPORT_DESCRIPTION "Generate a fake news report"
|
||||||
#define COMMAND_GENERATE_REPORT_ARGS_IMAGE_DESCRIPTION \
|
#define COMMAND_GENERATE_REPORT_ARGS_IMAGE_DESCRIPTION \
|
||||||
"Upload a background image to use (Only supports PNG, JPEG, and WEBP files)"
|
"Upload a background image to use (Only supports PNG, JPEG, and WEBP files)"
|
||||||
@@ -21,16 +26,19 @@
|
|||||||
"What is the headline?"
|
"What is the headline?"
|
||||||
#define COMMAND_GENERATE_REPORT_FAIL_NOT_SUPPORTED(filetype) \
|
#define COMMAND_GENERATE_REPORT_FAIL_NOT_SUPPORTED(filetype) \
|
||||||
"File type: " + filetype + \
|
"File type: " + filetype + \
|
||||||
" is not allowed. Only PNG, JPEG, and WEBP are allowed!"
|
" is not supported. Only PNG, JPEG, and WEBP are allowed!"
|
||||||
|
#define COMMAND_GENERATE_REPORT_FAIL_IMAGE_DOWNLOAD \
|
||||||
|
"Failed to download the background image! Aborting." RESPONSE_NO_CHARGE
|
||||||
#define COMMAND_GENERATE_REPORT_FAIL_IMAGE_LOAD \
|
#define COMMAND_GENERATE_REPORT_FAIL_IMAGE_LOAD \
|
||||||
"Failed to load the background image! Aborting. You were not changed for " \
|
"Failed to load the background image! Aborting." RESPONSE_NO_CHARGE
|
||||||
"this."
|
#define COMMAND_GENERATE_REPORT_CONFIRMATION_QUESTION(price, imageURL, \
|
||||||
#define COMMAND_GENERATE_REPORT_CONFIRMATION_QUESTION(price) \
|
headline) \
|
||||||
"This image generation will cost you " + price + \
|
"This image generation will cost you " + price + \
|
||||||
" " CURRENCY_NAME "(s).\nAre you sure you want to continue?"
|
" " CURRENCY_NAME \
|
||||||
|
"(s).\nAre you sure you want to continue?\nHeadline: " + \
|
||||||
|
headline + " [image](" + imageURL + ")"
|
||||||
|
|
||||||
// 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 \
|
||||||
@@ -48,7 +56,6 @@
|
|||||||
") 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 \
|
||||||
@@ -57,8 +64,6 @@
|
|||||||
"[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"
|
||||||
@@ -68,7 +73,6 @@
|
|||||||
"<@!" + 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"
|
||||||
@@ -79,7 +83,6 @@
|
|||||||
"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) \
|
||||||
@@ -89,7 +92,6 @@
|
|||||||
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?"
|
||||||
@@ -102,7 +104,6 @@
|
|||||||
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."
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
#include "../Databases.hpp"
|
#include "../Databases.hpp"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <dpp/appcommand.h>
|
||||||
#include <dpp/cluster.h>
|
#include <dpp/cluster.h>
|
||||||
#include <dpp/dispatcher.h>
|
#include <dpp/dispatcher.h>
|
||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
@@ -32,7 +33,15 @@ int main(int argc, char **argv) {
|
|||||||
event.reply("Could not find that command :(");
|
event.reply("Could not find that command :(");
|
||||||
});
|
});
|
||||||
|
|
||||||
bot.on_button_click([&bot](const dpp::button_click_t &event) {});
|
bot.on_button_click([&bot](const dpp::button_click_t &event) {
|
||||||
|
event.reply(dpp::ir_deferred_update_message, "processing");
|
||||||
|
|
||||||
|
auto component = Components.find(event.custom_id);
|
||||||
|
if (component != Components.end()) {
|
||||||
|
component->second(event, bot);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
bot.on_ready([&bot](const dpp::ready_t &event) {
|
bot.on_ready([&bot](const dpp::ready_t &event) {
|
||||||
if (dpp::run_once<struct register_bot_commands>()) {
|
if (dpp::run_once<struct register_bot_commands>()) {
|
||||||
|
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
extern std::unordered_map<std::string, std::function<void(COMMAND_ARGS)>>
|
extern std::unordered_map<std::string, std::function<void(COMMAND_ARGS)>>
|
||||||
Commands;
|
Commands;
|
||||||
|
extern std::unordered_map<std::string, std::function<void(COMPONENT_ARGS)>>
|
||||||
|
Components;
|
||||||
|
|
||||||
void deleteCommands(const dpp::ready_t &event, dpp::cluster &bot) {
|
void deleteCommands(const dpp::ready_t &event, dpp::cluster &bot) {
|
||||||
// bot.guild_bulk_command_delete(GUILD);
|
// bot.guild_bulk_command_delete(GUILD);
|
||||||
|
@@ -3,6 +3,9 @@
|
|||||||
#include "Commands/MoneyCommands.cpp"
|
#include "Commands/MoneyCommands.cpp"
|
||||||
#include "Commands/OtherCommands.cpp"
|
#include "Commands/OtherCommands.cpp"
|
||||||
|
|
||||||
|
// Component Responses
|
||||||
|
#include "Commands/Components/GenerativeComponents.cpp"
|
||||||
|
|
||||||
// Registry
|
// Registry
|
||||||
std::unordered_map<std::string, std::function<void(COMMAND_ARGS)>> Commands{
|
std::unordered_map<std::string, std::function<void(COMMAND_ARGS)>> Commands{
|
||||||
{COMMAND_PING, commandPing},
|
{COMMAND_PING, commandPing},
|
||||||
@@ -15,3 +18,6 @@ std::unordered_map<std::string, std::function<void(COMMAND_ARGS)>> Commands{
|
|||||||
{COMMAND_MONEY_LEADERBOARD, commandMoneyLeaderboard},
|
{COMMAND_MONEY_LEADERBOARD, commandMoneyLeaderboard},
|
||||||
{COMMAND_GET_PFP, commandGetPFP},
|
{COMMAND_GET_PFP, commandGetPFP},
|
||||||
{COMMAND_GENERATE_REPORT, commandGenerateReport}};
|
{COMMAND_GENERATE_REPORT, commandGenerateReport}};
|
||||||
|
|
||||||
|
std::unordered_map<std::string, std::function<void(COMPONENT_ARGS)>> Components{
|
||||||
|
{COMPONENT_COMMAND_CANCEL, componentCancel}};
|
||||||
|
6
src/Commands/Components/GenerativeComponents.cpp
Normal file
6
src/Commands/Components/GenerativeComponents.cpp
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include "../../Common.hpp"
|
||||||
|
#include "../../Utility/CairoTools.hpp"
|
||||||
|
#include <dpp/cluster.h>
|
||||||
|
#include <dpp/dispatcher.h>
|
||||||
|
|
||||||
|
void componentCancel(COMPONENT_ARGS) { event.edit_response(REQUEST_CANCELLED); }
|
@@ -17,22 +17,30 @@ void commandGenerateReport(const dpp::slashcommand_t &event,
|
|||||||
auto fileType = supportedImageFileTypes.find(file.content_type);
|
auto fileType = supportedImageFileTypes.find(file.content_type);
|
||||||
|
|
||||||
if (fileType != supportedImageFileTypes.end()) {
|
if (fileType != supportedImageFileTypes.end()) {
|
||||||
|
// Don't forget that its only funny if it is all in upper case
|
||||||
|
std::string headline =
|
||||||
|
std::get<std::string>(event.get_parameter("headline"));
|
||||||
|
// Never seen this method before but looks awesome
|
||||||
|
std::transform(headline.begin(), headline.end(), headline.data(),
|
||||||
|
::toupper);
|
||||||
|
|
||||||
dpp::message confirmRequest(
|
dpp::message confirmRequest(
|
||||||
event.command.channel_id,
|
event.command.channel_id,
|
||||||
COMMAND_GENERATE_REPORT_CONFIRMATION_QUESTION(
|
COMMAND_GENERATE_REPORT_CONFIRMATION_QUESTION(
|
||||||
std::to_string(COMMAND_GENERATE_REPORT_COST)));
|
std::to_string(COMMAND_GENERATE_REPORT_COST), file.url, headline));
|
||||||
|
|
||||||
confirmRequest.add_component(
|
confirmRequest.add_component(
|
||||||
dpp::component()
|
dpp::component()
|
||||||
.add_component(dpp::component()
|
.add_component(dpp::component()
|
||||||
.set_label(BUTTON_ACCEPT)
|
.set_label(BUTTON_ACCEPT)
|
||||||
.set_type(dpp::cot_button)
|
.set_type(dpp::cot_button)
|
||||||
.set_style(dpp::component_style::cos_success)
|
.set_style(dpp::component_style::cos_success)
|
||||||
.set_id("generate_report_confirm"))
|
.set_id(COMPONENT_GENERATE_REPORT_CONFIRM))
|
||||||
.add_component(dpp::component()
|
.add_component(dpp::component()
|
||||||
.set_label(BUTTON_CANCEL)
|
.set_label(BUTTON_CANCEL)
|
||||||
.set_type(dpp::cot_button)
|
.set_type(dpp::cot_button)
|
||||||
.set_style(dpp::component_style::cos_danger)
|
.set_style(dpp::component_style::cos_danger)
|
||||||
.set_id("generate_report_deny")));
|
.set_id(COMPONENT_COMMAND_CANCEL)));
|
||||||
event.edit_response(confirmRequest);
|
event.edit_response(confirmRequest);
|
||||||
} else {
|
} else {
|
||||||
event.edit_response(
|
event.edit_response(
|
||||||
|
@@ -1,6 +1,23 @@
|
|||||||
#include "../settings.hpp"
|
#include "../settings.hpp"
|
||||||
|
|
||||||
#define COMMAND_ARGS const dpp::slashcommand_t &event, dpp::cluster &bot
|
#define COMMAND_ARGS const dpp::slashcommand_t &event, dpp::cluster &bot
|
||||||
|
#define COMPONENT_ARGS const dpp::button_click_t &event, dpp::cluster &bot
|
||||||
|
|
||||||
// Costs of commands
|
// Costs of commands
|
||||||
#define COMMAND_GENERATE_REPORT_COST 2
|
#define COMMAND_GENERATE_REPORT_COST 2
|
||||||
|
|
||||||
|
// Command names
|
||||||
|
#define COMMAND_PING "ping"
|
||||||
|
#define COMMAND_GENERATE_REPORT "generate_report"
|
||||||
|
#define COMMAND_GET_PFP "get_pfp"
|
||||||
|
#define COMMAND_ABOUT "about"
|
||||||
|
#define COMMAND_BALANCE "balance"
|
||||||
|
#define COMMAND_BALANCE_SHORT "bal"
|
||||||
|
#define COMMAND_PAY "pay"
|
||||||
|
#define COMMAND_PRINT_MONEY "print_money"
|
||||||
|
#define COMMAND_BURN_MONEY "burn_money"
|
||||||
|
#define COMMAND_MONEY_LEADERBOARD "money_leaderboard"
|
||||||
|
|
||||||
|
// Component names
|
||||||
|
#define COMPONENT_GENERATE_REPORT_CONFIRM "generate_report_confirm"
|
||||||
|
#define COMPONENT_COMMAND_CANCEL "cancel"
|
||||||
|
Reference in New Issue
Block a user