Compare commits

...

2 Commits

Author SHA1 Message Date
cat
1450dd4621 Common header is made and costs are moved there 2025-07-22 17:42:27 +03:00
cat
01c8e9d03b Reorganising and adding generate-report 2025-07-22 17:36:05 +03:00
9 changed files with 60 additions and 27 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

@@ -1,5 +1,5 @@
#include "../../settings.hpp"
#include "../CommandManagement.cpp"
#include "../Common.hpp"
#include "../Databases.hpp"
#include <cstdlib>

View File

@@ -1,12 +1,10 @@
#include "../settings.hpp"
#include "Common.hpp"
#include <dpp/appcommand.h>
#include <dpp/cluster.h>
#include <dpp/dispatcher.h>
#include <vector>
extern std::unordered_map<
std::string,
std::function<void(const dpp::slashcommand_t &event, dpp::cluster &bot)>>
extern std::unordered_map<std::string, std::function<void(COMMAND_ARGS)>>
Commands;
void deleteCommands(const dpp::ready_t &event, dpp::cluster &bot) {
@@ -25,6 +23,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,12 +1,11 @@
// Unity Build
#include "Commands/GenerativeCommands.cpp"
#include "Commands/MoneyCommands.cpp"
#include "Commands/OtherCommands.cpp"
// Registry
std::unordered_map<
std::string,
std::function<void(const dpp::slashcommand_t &event, dpp::cluster &bot)>>
Commands{{COMMAND_PING, commandPing},
std::unordered_map<std::string, std::function<void(COMMAND_ARGS)>> Commands{
{COMMAND_PING, commandPing},
{COMMAND_ABOUT, commandAbout},
{COMMAND_BALANCE, commandBalance},
{COMMAND_BALANCE_SHORT, commandBalance},
@@ -14,4 +13,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,10 @@
#include "../Common.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 "../Common.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() + ");");
}

View File

@@ -1,4 +1,4 @@
#include "../../settings.hpp"
#include "../Common.hpp"
#include <dpp/dispatcher.h>
#include <dpp/dpp.h>
#include <dpp/guild.h>

6
src/Common.hpp Normal file
View File

@@ -0,0 +1,6 @@
#include "../settings.hpp"
#define COMMAND_ARGS const dpp::slashcommand_t &event, dpp::cluster &bot
// Costs of commands
#define COMMAND_GENERATE_REPORT_COST 2