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"
// Buttons
#define BUTTON_ACCEPT "Confirm"
#define BUTTON_CANCEL "Cancel"
// Command ping
#define COMMAND_PING "ping"
#define COMMAND_PING_DESCRIPTION "Ping-pong test"
// Command generate_report
#define COMMAND_GENERATE_REPORT "generate_report"
#define COMMAND_GENERATE_REPORT_DESCRIPTION "Generate a fake news report"
#define COMMAND_GENERATE_REPORT_ARGS_IMAGE_DESCRIPTION \
@@ -20,6 +25,9 @@
#define COMMAND_GENERATE_REPORT_FAIL_IMAGE_LOAD \
"Failed to load the background image! Aborting. You were not changed for " \
"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
#define COMMAND_GET_PFP "get_pfp"

View File

@@ -1,20 +1,12 @@
#include "../Common.hpp"
#include "../Utility/CairoTools.hpp"
#include <algorithm>
#include <cctype>
#include <dpp/dispatcher.h>
#include <dpp/dpp.h>
#include <dpp/guild.h>
#include <dpp/message.h>
#include <dpp/misc-enum.h>
#include <dpp/queues.h>
#include <dpp/snowflake.h>
#include <dpp/user.h>
#include <functional>
#include <string>
#include <unordered_map>
void commandGenerateReport(const dpp::slashcommand_t &event,
dpp::cluster &bot) {
@@ -25,35 +17,25 @@ void commandGenerateReport(const dpp::slashcommand_t &event,
auto fileType = supportedImageFileTypes.find(file.content_type);
if (fileType != supportedImageFileTypes.end()) {
bot.request(
file.url, dpp::http_method::m_get,
[event, &bot, fileType](const dpp::http_request_completion_t &result) {
auto imageAsSurface = fileType->second(result.body);
if (imageAsSurface == nullptr) {
event.edit_response(COMMAND_GENERATE_REPORT_FAIL_IMAGE_LOAD);
return;
}
// 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);
std::string responseData =
GenerateReportImage(imageAsSurface, headline);
dpp::message response(event.command.channel_id, "");
response.add_file("report.png", responseData);
event.edit_response(response);
});
dpp::message confirmRequest(
event.command.channel_id,
COMMAND_GENERATE_REPORT_CONFIRMATION_QUESTION(
std::to_string(COMMAND_GENERATE_REPORT_COST)));
confirmRequest.add_component(
dpp::component()
.add_component(dpp::component()
.set_label(BUTTON_ACCEPT)
.set_type(dpp::cot_button)
.set_style(dpp::component_style::cos_success)
.set_id("stinky"))
.add_component(dpp::component()
.set_label(BUTTON_CANCEL)
.set_type(dpp::cot_button)
.set_style(dpp::component_style::cos_danger)
.set_id("stinkyyy")));
event.edit_response(confirmRequest);
} else {
event.edit_response(
COMMAND_GENERATE_REPORT_FAIL_NOT_SUPPORTED(file.content_type));
}
}
//
// ACTUAL GENERATION STARTS HERE
//