SQL, Language, Organising commands
This commit is contained in:
3
src/Commands.cpp
Normal file
3
src/Commands.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "Commands.hpp"
|
||||
|
||||
void commandPing(const dpp::slashcommand_t &event) { event.reply("Pong"); }
|
6
src/Commands.hpp
Normal file
6
src/Commands.hpp
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <dpp/dispatcher.h>
|
||||
void commandPing(const dpp::slashcommand_t &event);
|
||||
|
||||
inline std::unordered_map<std::string,
|
||||
std::function<void(const dpp::slashcommand_t &event)>>
|
||||
Commands{{"ping", commandPing}};
|
27
src/SQL.hpp
Normal file
27
src/SQL.hpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <iostream>
|
||||
#include <sqlite3.h>
|
||||
#include <string>
|
||||
|
||||
inline sqlite3 *database;
|
||||
|
||||
// Its invoked per returned row/record
|
||||
// typeCount is each column
|
||||
static int callback(void *deadWeight, int typeCount, char **value, char **key) {
|
||||
for (int x = 0; x < typeCount; x++) {
|
||||
std::cout << key[x] << " " << value[x] << "\n";
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void execSQL(std::string sql) {
|
||||
int errorCode = 0;
|
||||
errorCode = sqlite3_exec(database, sql.c_str(), callback, 0, NULL);
|
||||
if (errorCode == 19) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (errorCode) {
|
||||
std::cerr << sqlite3_errmsg(database) << " exiting!\n";
|
||||
exit(1);
|
||||
}
|
||||
}
|
2
src/local_en.hpp
Normal file
2
src/local_en.hpp
Normal file
@@ -0,0 +1,2 @@
|
||||
#define CURRENCY_NAME "The Night Coin"
|
||||
#define COMMAND_BALANCE_DESCRIPTION "See your balance of " CURRENCY_NAME
|
30
src/main.cpp
30
src/main.cpp
@@ -1,25 +1,49 @@
|
||||
#include "../token.h"
|
||||
#include "Commands.hpp"
|
||||
#include "SQL.hpp"
|
||||
#include "local_en.hpp"
|
||||
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/dpp.h>
|
||||
#include <dpp/once.h>
|
||||
#include <string>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// SQL database set up
|
||||
sqlite3_open("discordServer.db", &database);
|
||||
|
||||
// Fuck dude capitalism 😔😔😔
|
||||
execSQL("CREATE TABLE IF NOT EXISTS MONEY("
|
||||
"UID INT PRIMARY KEY NOT NULL,"
|
||||
"Cash INT NOT NULL DEFAULT 0)");
|
||||
|
||||
// Bot setup bullshit
|
||||
dpp::cluster bot(TOKEN);
|
||||
|
||||
// Neat utility
|
||||
bot.on_log(dpp::utility::cout_logger());
|
||||
|
||||
bot.on_slashcommand([](const dpp::slashcommand_t &event) {
|
||||
if (event.command.get_command_name() == "test") {
|
||||
event.reply("Recieved");
|
||||
auto command = Commands.find(event.command.get_command_name());
|
||||
if (command != Commands.end()) {
|
||||
command->second(event);
|
||||
return;
|
||||
}
|
||||
event.reply("Could not find that command :(");
|
||||
});
|
||||
|
||||
bot.on_ready([&bot](const dpp::ready_t &event) {
|
||||
if (dpp::run_once<struct register_bot_commands>()) {
|
||||
bot.global_command_create(
|
||||
dpp::slashcommand("test", "quick test", bot.me.id));
|
||||
dpp::slashcommand("ping", "Ping-pong test", bot.me.id));
|
||||
bot.guild_command_create(
|
||||
dpp::slashcommand("balance", COMMAND_BALANCE_DESCRIPTION, bot.me.id),
|
||||
GUILD);
|
||||
}
|
||||
|
||||
if (dpp::run_once<struct clear_bot_commands>()) {
|
||||
// bot.global_command_delete(1395839332220408051);
|
||||
}
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user