Compare commits
2 Commits
ceaf2a0c2d
...
1450dd4621
Author | SHA1 | Date | |
---|---|---|---|
1450dd4621 | |||
01c8e9d03b |
@@ -8,6 +8,13 @@
|
|||||||
#define COMMAND_PING "ping"
|
#define COMMAND_PING "ping"
|
||||||
#define COMMAND_PING_DESCRIPTION "Ping-pong test"
|
#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
|
// Command get_pfp
|
||||||
#define COMMAND_GET_PFP "get_pfp"
|
#define COMMAND_GET_PFP "get_pfp"
|
||||||
#define COMMAND_GET_PFP_DESCRIPTION \
|
#define COMMAND_GET_PFP_DESCRIPTION \
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
#include "../../settings.hpp"
|
|
||||||
#include "../CommandManagement.cpp"
|
#include "../CommandManagement.cpp"
|
||||||
|
#include "../Common.hpp"
|
||||||
#include "../Databases.hpp"
|
#include "../Databases.hpp"
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
@@ -1,12 +1,10 @@
|
|||||||
#include "../settings.hpp"
|
#include "Common.hpp"
|
||||||
#include <dpp/appcommand.h>
|
#include <dpp/appcommand.h>
|
||||||
#include <dpp/cluster.h>
|
#include <dpp/cluster.h>
|
||||||
#include <dpp/dispatcher.h>
|
#include <dpp/dispatcher.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
extern std::unordered_map<
|
extern std::unordered_map<std::string, std::function<void(COMMAND_ARGS)>>
|
||||||
std::string,
|
|
||||||
std::function<void(const dpp::slashcommand_t &event, dpp::cluster &bot)>>
|
|
||||||
Commands;
|
Commands;
|
||||||
|
|
||||||
void deleteCommands(const dpp::ready_t &event, dpp::cluster &bot) {
|
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,
|
"user", COMMAND_GET_PFP_ARGS_USER,
|
||||||
true)),
|
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
|
// Money related commands
|
||||||
dpp::slashcommand(COMMAND_BALANCE, COMMAND_BALANCE_DESCRIPTION, bot.me.id)
|
dpp::slashcommand(COMMAND_BALANCE, COMMAND_BALANCE_DESCRIPTION, bot.me.id)
|
||||||
.add_option(dpp::command_option(dpp::command_option_type::co_user,
|
.add_option(dpp::command_option(dpp::command_option_type::co_user,
|
||||||
|
@@ -1,17 +1,17 @@
|
|||||||
// Unity Build
|
// Unity Build
|
||||||
|
#include "Commands/GenerativeCommands.cpp"
|
||||||
#include "Commands/MoneyCommands.cpp"
|
#include "Commands/MoneyCommands.cpp"
|
||||||
#include "Commands/OtherCommands.cpp"
|
#include "Commands/OtherCommands.cpp"
|
||||||
|
|
||||||
// Registry
|
// Registry
|
||||||
std::unordered_map<
|
std::unordered_map<std::string, std::function<void(COMMAND_ARGS)>> Commands{
|
||||||
std::string,
|
{COMMAND_PING, commandPing},
|
||||||
std::function<void(const dpp::slashcommand_t &event, dpp::cluster &bot)>>
|
{COMMAND_ABOUT, commandAbout},
|
||||||
Commands{{COMMAND_PING, commandPing},
|
{COMMAND_BALANCE, commandBalance},
|
||||||
{COMMAND_ABOUT, commandAbout},
|
{COMMAND_BALANCE_SHORT, commandBalance},
|
||||||
{COMMAND_BALANCE, commandBalance},
|
{COMMAND_PAY, commandPay},
|
||||||
{COMMAND_BALANCE_SHORT, commandBalance},
|
{COMMAND_PRINT_MONEY, commandPrintMoney},
|
||||||
{COMMAND_PAY, commandPay},
|
{COMMAND_BURN_MONEY, commandBurnMoney},
|
||||||
{COMMAND_PRINT_MONEY, commandPrintMoney},
|
{COMMAND_MONEY_LEADERBOARD, commandMoneyLeaderboard},
|
||||||
{COMMAND_BURN_MONEY, commandBurnMoney},
|
{COMMAND_GET_PFP, commandGetPFP},
|
||||||
{COMMAND_MONEY_LEADERBOARD, commandMoneyLeaderboard},
|
{COMMAND_GENERATE_REPORT, commandGenerateReport}};
|
||||||
{COMMAND_GET_PFP, commandGetPFP}};
|
|
||||||
|
10
src/Commands/GenerativeCommands.cpp
Normal file
10
src/Commands/GenerativeCommands.cpp
Normal 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) {}
|
@@ -1,6 +1,6 @@
|
|||||||
#include "../../settings.hpp" // This is where language is imported
|
|
||||||
#include "../Base/SQL.hpp"
|
#include "../Base/SQL.hpp"
|
||||||
#include "InlineDefinitions.hpp"
|
#include "../Common.hpp"
|
||||||
|
#include "TransactionMethods.hpp"
|
||||||
|
|
||||||
#include <dpp/appcommand.h>
|
#include <dpp/appcommand.h>
|
||||||
#include <dpp/cluster.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 amount) {
|
||||||
std::uint64_t balance = std::stoll(getUserBalance(userid));
|
std::uint64_t balance = std::stoll(getUserBalance(userid));
|
||||||
execSQL("UPDATE MONEY SET CASH=" + std::to_string(balance + amount) +
|
execSQL("UPDATE MONEY SET CASH=" + std::to_string(balance + amount) +
|
||||||
" WHERE UID=" + userid.str());
|
" WHERE UID=" + userid.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool deductFromUsersBalance(const dpp::snowflake userid,
|
bool deductFromUsersBalance(const dpp::snowflake userid, std::uint64_t amount) {
|
||||||
std::uint64_t amount) {
|
|
||||||
std::uint64_t balance = std::stoll(getUserBalance(userid));
|
std::uint64_t balance = std::stoll(getUserBalance(userid));
|
||||||
if (balance < amount) {
|
if (balance < amount) {
|
||||||
return false;
|
return false;
|
||||||
@@ -135,7 +134,7 @@ inline bool deductFromUsersBalance(const dpp::snowflake userid,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline std::string getUserBalance(const dpp::snowflake userid) {
|
std::string getUserBalance(const dpp::snowflake userid) {
|
||||||
std::string balance;
|
std::string balance;
|
||||||
execSQL("SELECT CASH FROM MONEY WHERE UID=" + userid.str(), &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);
|
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() + ");");
|
execSQL("INSERT INTO MONEY (UID) VALUES (" + userid.str() + ");");
|
||||||
}
|
}
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
#include "../../settings.hpp"
|
#include "../Common.hpp"
|
||||||
#include <dpp/dispatcher.h>
|
#include <dpp/dispatcher.h>
|
||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
#include <dpp/guild.h>
|
#include <dpp/guild.h>
|
||||||
|
6
src/Common.hpp
Normal file
6
src/Common.hpp
Normal 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
|
Reference in New Issue
Block a user