Major reordering of the bot
This commit is contained in:
@@ -6,8 +6,7 @@ project(TheBartender VERSION 1.0)
|
||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
|
||||
# Create an executable
|
||||
add_executable(${PROJECT_NAME} src/Base/Entry.cpp src/CommandEvents.cpp
|
||||
src/CommandManagement.cpp)
|
||||
add_executable(${PROJECT_NAME} src/Base/Entry.cpp src/Commands.cpp)
|
||||
|
||||
# Find our pre-installed DPP package (using FindDPP.cmake).
|
||||
find_package(DPP REQUIRED)
|
||||
|
@@ -5,3 +5,6 @@
|
||||
|
||||
// Whoever is going to be admin. Their ID here
|
||||
#define ADMIN_ID 0
|
||||
|
||||
// Replace locale_en with any available one
|
||||
#include "languages/locale_en.hpp"
|
||||
|
@@ -1,12 +1,11 @@
|
||||
#include "../../languages/locale_en.hpp"
|
||||
#include "../Commands.hpp"
|
||||
#include "../../settings.hpp"
|
||||
#include "../CommandManagement.hpp"
|
||||
#include "../Databases.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
|
||||
@@ -28,12 +27,12 @@ int main(int argc, char **argv) {
|
||||
});
|
||||
|
||||
bot.on_ready([&bot](const dpp::ready_t &event) {
|
||||
if (dpp::run_once<struct clear_bot_commands>()) {
|
||||
// bot.global_command_delete(1395839332220408051);
|
||||
}
|
||||
if (dpp::run_once<struct register_bot_commands>()) {
|
||||
createCommands(event, bot);
|
||||
}
|
||||
if (dpp::run_once<struct clear_bot_commands>()) {
|
||||
deleteCommands(event, bot);
|
||||
}
|
||||
});
|
||||
|
||||
// Remove dpp::st_wait if you want it to return execution
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <sqlite3.h>
|
||||
#include <string>
|
||||
|
@@ -1,5 +1,15 @@
|
||||
#include "Commands.hpp"
|
||||
#include "../settings.hpp"
|
||||
#include <dpp/appcommand.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
|
||||
extern std::unordered_map<std::string,
|
||||
std::function<void(const dpp::slashcommand_t &event)>>
|
||||
Commands;
|
||||
|
||||
void deleteCommands(const dpp::ready_t &event, dpp::cluster &bot) {
|
||||
// bot.guild_bulk_command_delete(GUILD);
|
||||
}
|
||||
|
||||
void createCommands(const dpp::ready_t &event, dpp::cluster &bot) {
|
||||
bot.global_command_create(
|
17
src/Commands.cpp
Normal file
17
src/Commands.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
// Unity Build
|
||||
#include "Commands/MoneyCommands.cpp"
|
||||
#include "Commands/OtherCommands.cpp"
|
||||
|
||||
// Registry
|
||||
std::unordered_map<std::string,
|
||||
std::function<void(const dpp::slashcommand_t &event)>>
|
||||
Commands{{"ping", commandPing},
|
||||
{"about", commandAbout},
|
||||
{"balance", commandBalance},
|
||||
{"bal", commandBalance},
|
||||
{"pay", commandPay},
|
||||
{"print_money", commandPrintMoney},
|
||||
{"burn_money", commandBurnMoney},
|
||||
{"money_leaderboard", commandMoneyLeaderboard}};
|
@@ -1,33 +0,0 @@
|
||||
#include "../languages/locale_en.hpp"
|
||||
#include "../settings.hpp"
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/snowflake.h>
|
||||
|
||||
void createCommands(const dpp::ready_t &event, dpp::cluster &bot);
|
||||
void commandPing(const dpp::slashcommand_t &event);
|
||||
void commandBalance(const dpp::slashcommand_t &event);
|
||||
void commandPay(const dpp::slashcommand_t &event);
|
||||
void commandPrintMoney(const dpp::slashcommand_t &event);
|
||||
void commandBurnMoney(const dpp::slashcommand_t &event);
|
||||
void commandMoneyLeaderboard(const dpp::slashcommand_t &event);
|
||||
|
||||
// Inline helpers
|
||||
inline void increaseFromUsersBalance(const dpp::snowflake userid,
|
||||
std::uint64_t amount);
|
||||
|
||||
inline bool deductFromUsersBalance(const dpp::snowflake userid,
|
||||
std::uint64_t amount);
|
||||
|
||||
inline std::string getUserBalance(const dpp::snowflake userid);
|
||||
inline void addUserToDatabase(const dpp::snowflake userid);
|
||||
|
||||
inline std::unordered_map<std::string,
|
||||
std::function<void(const dpp::slashcommand_t &event)>>
|
||||
Commands{{"ping", commandPing},
|
||||
{"balance", commandBalance},
|
||||
{"bal", commandBalance},
|
||||
{"pay", commandPay},
|
||||
{"print_money", commandPrintMoney},
|
||||
{"burn_money", commandBurnMoney},
|
||||
{"money_leaderboard", commandMoneyLeaderboard}};
|
9
src/Commands/InlineDefinitions.hpp
Normal file
9
src/Commands/InlineDefinitions.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <dpp/snowflake.h>
|
||||
|
||||
// Helper methods
|
||||
inline void increaseFromUsersBalance(const dpp::snowflake userid,
|
||||
std::uint64_t amount);
|
||||
inline bool deductFromUsersBalance(const dpp::snowflake userid,
|
||||
std::uint64_t amount);
|
||||
inline std::string getUserBalance(const dpp::snowflake userid);
|
||||
inline void addUserToDatabase(const dpp::snowflake userid);
|
@@ -1,15 +1,18 @@
|
||||
#include "Base/SQL.hpp"
|
||||
#include "Commands.hpp"
|
||||
#include <cstdint>
|
||||
#include "../../settings.hpp" // This is where language is imported
|
||||
#include "../Base/SQL.hpp"
|
||||
#include "InlineDefinitions.hpp"
|
||||
|
||||
#include <dpp/appcommand.h>
|
||||
#include <dpp/cluster.h>
|
||||
#include <dpp/dispatcher.h>
|
||||
#include <dpp/exception.h>
|
||||
#include <dpp/snowflake.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
|
||||
void commandPing(const dpp::slashcommand_t &event) { event.reply("Pong"); }
|
||||
// Actual commands
|
||||
void commandBalance(const dpp::slashcommand_t &event) {
|
||||
std::string person, balance;
|
||||
dpp::command_value id = event.get_parameter("user");
|
||||
@@ -110,6 +113,7 @@ void commandMoneyLeaderboard(const dpp::slashcommand_t &event) {
|
||||
///
|
||||
/// HELPER INLINE METHODS
|
||||
///
|
||||
|
||||
inline void increaseFromUsersBalance(const dpp::snowflake userid,
|
||||
std::uint64_t amount) {
|
||||
std::uint64_t balance = std::stoi(getUserBalance(userid));
|
4
src/Commands/OtherCommands.cpp
Normal file
4
src/Commands/OtherCommands.cpp
Normal file
@@ -0,0 +1,4 @@
|
||||
#include <dpp/dispatcher.h>
|
||||
|
||||
void commandPing(const dpp::slashcommand_t &event) { event.reply("Pong"); }
|
||||
void commandAbout(const dpp::slashcommand_t &event) { event.reply("Pong"); }
|
Reference in New Issue
Block a user