Reorganising and adding generate-report

This commit is contained in:
2025-07-22 17:36:05 +03:00
parent ceaf2a0c2d
commit 01c8e9d03b
7 changed files with 40 additions and 9 deletions

View File

@@ -8,6 +8,13 @@
#define COMMAND_PING "ping"
#define COMMAND_PING_DESCRIPTION "Ping-pong test"
#define COMMAND_GENERATE_REPORT "generate_report"
#define COMMAND_GENERATE_REPORT_DESCRIPTION "Generate a fake news report"
#define COMMAND_GENERATE_REPORT_ARGS_IMAGE_DESCRIPTION \
"Upload a background image to use (Only supports PNG, JPEG, and WEBP files)"
#define COMMAND_GENERATE_REPORT_ARGS_HEADLINE_DESCRIPTION \
"What is the headline?"
// Command get_pfp
#define COMMAND_GET_PFP "get_pfp"
#define COMMAND_GET_PFP_DESCRIPTION \

View File

@@ -25,6 +25,19 @@ void createCommands(const dpp::ready_t &event, dpp::cluster &bot) {
"user", COMMAND_GET_PFP_ARGS_USER,
true)),
// Generative commands
dpp::slashcommand(COMMAND_GENERATE_REPORT,
COMMAND_GENERATE_REPORT_DESCRIPTION, bot.me.id)
.add_option(dpp::command_option(
dpp::command_option_type::co_attachment, "background-image",
COMMAND_GENERATE_REPORT_ARGS_IMAGE_DESCRIPTION, true))
.add_option(dpp::command_option(
dpp::command_option_type::co_string, "headline",
COMMAND_GENERATE_REPORT_ARGS_HEADLINE_DESCRIPTION,
true)
.set_min_length(3)
.set_max_length(70)),
// Money related commands
dpp::slashcommand(COMMAND_BALANCE, COMMAND_BALANCE_DESCRIPTION, bot.me.id)
.add_option(dpp::command_option(dpp::command_option_type::co_user,

View File

@@ -1,4 +1,5 @@
// Unity Build
#include "Commands/GenerativeCommands.cpp"
#include "Commands/MoneyCommands.cpp"
#include "Commands/OtherCommands.cpp"
@@ -14,4 +15,5 @@ std::unordered_map<
{COMMAND_PRINT_MONEY, commandPrintMoney},
{COMMAND_BURN_MONEY, commandBurnMoney},
{COMMAND_MONEY_LEADERBOARD, commandMoneyLeaderboard},
{COMMAND_GET_PFP, commandGetPFP}};
{COMMAND_GET_PFP, commandGetPFP},
{COMMAND_GENERATE_REPORT, commandGenerateReport}};

View File

@@ -0,0 +1,9 @@
#include "../../settings.hpp"
#include <dpp/dispatcher.h>
#include <dpp/dpp.h>
#include <dpp/guild.h>
#include <dpp/snowflake.h>
#include <dpp/user.h>
void commandGenerateReport(const dpp::slashcommand_t &event,
dpp::cluster &bot) {}

View File

@@ -1,6 +1,6 @@
#include "../../settings.hpp" // This is where language is imported
#include "../Base/SQL.hpp"
#include "InlineDefinitions.hpp"
#include "TransactionMethods.hpp"
#include <dpp/appcommand.h>
#include <dpp/cluster.h>
@@ -112,18 +112,17 @@ void commandMoneyLeaderboard(const dpp::slashcommand_t &event,
}
///
/// HELPER INLINE METHODS
/// Transaction Methods
///
inline void increaseFromUsersBalance(const dpp::snowflake userid,
void increaseFromUsersBalance(const dpp::snowflake userid,
std::uint64_t amount) {
std::uint64_t balance = std::stoll(getUserBalance(userid));
execSQL("UPDATE MONEY SET CASH=" + std::to_string(balance + amount) +
" WHERE UID=" + userid.str());
}
inline bool deductFromUsersBalance(const dpp::snowflake userid,
std::uint64_t amount) {
bool deductFromUsersBalance(const dpp::snowflake userid, std::uint64_t amount) {
std::uint64_t balance = std::stoll(getUserBalance(userid));
if (balance < amount) {
return false;
@@ -135,7 +134,7 @@ inline bool deductFromUsersBalance(const dpp::snowflake userid,
return true;
}
inline std::string getUserBalance(const dpp::snowflake userid) {
std::string getUserBalance(const dpp::snowflake userid) {
std::string balance;
execSQL("SELECT CASH FROM MONEY WHERE UID=" + userid.str(), &balance);
@@ -150,6 +149,6 @@ inline std::string getUserBalance(const dpp::snowflake userid) {
return balance.substr(begining, balance.find(';') - begining);
}
inline void addUserToDatabase(const dpp::snowflake userid) {
void addUserToDatabase(const dpp::snowflake userid) {
execSQL("INSERT INTO MONEY (UID) VALUES (" + userid.str() + ");");
}

1
src/Cost.hpp Normal file
View File

@@ -0,0 +1 @@
#define COMMAND_GENERATE_REPORT_COST 2