Added the generate_report's confirmation. Just need to do buttons.

This commit is contained in:
2025-07-23 04:05:34 +03:00
parent f662317bdb
commit 7f147bb58c
2 changed files with 25 additions and 35 deletions

View File

@@ -4,10 +4,15 @@
#define CURRENCY_NAME "Night Coin" #define CURRENCY_NAME "Night Coin"
// Buttons
#define BUTTON_ACCEPT "Confirm"
#define BUTTON_CANCEL "Cancel"
// Command ping // Command ping
#define COMMAND_PING "ping" #define COMMAND_PING "ping"
#define COMMAND_PING_DESCRIPTION "Ping-pong test" #define COMMAND_PING_DESCRIPTION "Ping-pong test"
// Command generate_report
#define COMMAND_GENERATE_REPORT "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 \
@@ -20,6 +25,9 @@
#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. You were not changed for " \
"this." "this."
#define COMMAND_GENERATE_REPORT_CONFIRMATION_QUESTION(price) \
"This image generation will cost you " + price + \
" " CURRENCY_NAME "(s).\nAre you sure you want to continue?"
// Command get_pfp // Command get_pfp
#define COMMAND_GET_PFP "get_pfp" #define COMMAND_GET_PFP "get_pfp"

View File

@@ -1,20 +1,12 @@
#include "../Common.hpp" #include "../Common.hpp"
#include "../Utility/CairoTools.hpp" #include "../Utility/CairoTools.hpp"
#include <algorithm>
#include <cctype>
#include <dpp/dispatcher.h> #include <dpp/dispatcher.h>
#include <dpp/dpp.h> #include <dpp/dpp.h>
#include <dpp/guild.h> #include <dpp/guild.h>
#include <dpp/message.h>
#include <dpp/misc-enum.h>
#include <dpp/queues.h>
#include <dpp/snowflake.h> #include <dpp/snowflake.h>
#include <dpp/user.h>
#include <functional>
#include <string> #include <string>
#include <unordered_map>
void commandGenerateReport(const dpp::slashcommand_t &event, void commandGenerateReport(const dpp::slashcommand_t &event,
dpp::cluster &bot) { dpp::cluster &bot) {
@@ -25,35 +17,25 @@ 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()) {
bot.request( dpp::message confirmRequest(
file.url, dpp::http_method::m_get, event.command.channel_id,
[event, &bot, fileType](const dpp::http_request_completion_t &result) { COMMAND_GENERATE_REPORT_CONFIRMATION_QUESTION(
auto imageAsSurface = fileType->second(result.body); std::to_string(COMMAND_GENERATE_REPORT_COST)));
if (imageAsSurface == nullptr) { confirmRequest.add_component(
event.edit_response(COMMAND_GENERATE_REPORT_FAIL_IMAGE_LOAD); dpp::component()
return; .add_component(dpp::component()
} .set_label(BUTTON_ACCEPT)
.set_type(dpp::cot_button)
// Don't forget that its only funny if it is all in upper case .set_style(dpp::component_style::cos_success)
std::string headline = .set_id("stinky"))
std::get<std::string>(event.get_parameter("headline")); .add_component(dpp::component()
.set_label(BUTTON_CANCEL)
// Never seen this method before but looks awesome .set_type(dpp::cot_button)
std::transform(headline.begin(), headline.end(), headline.data(), .set_style(dpp::component_style::cos_danger)
::toupper); .set_id("stinkyyy")));
event.edit_response(confirmRequest);
std::string responseData =
GenerateReportImage(imageAsSurface, headline);
dpp::message response(event.command.channel_id, "");
response.add_file("report.png", responseData);
event.edit_response(response);
});
} else { } else {
event.edit_response( event.edit_response(
COMMAND_GENERATE_REPORT_FAIL_NOT_SUPPORTED(file.content_type)); COMMAND_GENERATE_REPORT_FAIL_NOT_SUPPORTED(file.content_type));
} }
} }
//
// ACTUAL GENERATION STARTS HERE
//