Created the coins.cpp command

This commit is contained in:
Mathias Wagner 2023-11-04 23:55:12 +01:00
parent 92b2767c55
commit 54385d0a7c
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

19
src/commands/coins.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "coins.h"
#include "api/util.h"
#define COINS 1000
void coins::execute(sql::Connection &con, dpp::cluster &bot, const dpp::slashcommand_t &event) {
sql::ResultSet *res = util::getResultSet(con, "SELECT coins FROM guilds WHERE guildId = ?", {event.command.guild_id.str()});
int coins;
if (!res->next()) {
util::executeQuery(con, "INSERT INTO guilds (guildId, coins) VALUES (?, ?)", {event.command.guild_id.str(), std::to_string(COINS)});
coins = COINS;
} else {
coins = res->getInt("coins");
}
util::sendSuccess(event, "You have " + std::to_string(coins) + " coins.");
delete res;
}