diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f4fc56..2df18a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/settings.hpp.empty b/settings.hpp.empty index 7f73811..156efb2 100644 --- a/settings.hpp.empty +++ b/settings.hpp.empty @@ -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" diff --git a/src/Base/Entry.cpp b/src/Base/Entry.cpp index abb666d..c1714db 100644 --- a/src/Base/Entry.cpp +++ b/src/Base/Entry.cpp @@ -1,12 +1,11 @@ -#include "../../languages/locale_en.hpp" -#include "../Commands.hpp" +#include "../../settings.hpp" +#include "../CommandManagement.hpp" #include "../Databases.hpp" #include #include #include #include -#include 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()) { - // bot.global_command_delete(1395839332220408051); - } if (dpp::run_once()) { createCommands(event, bot); } + if (dpp::run_once()) { + deleteCommands(event, bot); + } }); // Remove dpp::st_wait if you want it to return execution diff --git a/src/Base/SQL.hpp b/src/Base/SQL.hpp index b8ed6e3..6e09720 100644 --- a/src/Base/SQL.hpp +++ b/src/Base/SQL.hpp @@ -1,3 +1,5 @@ +#pragma once + #include #include #include diff --git a/src/CommandManagement.cpp b/src/CommandManagement.hpp similarity index 87% rename from src/CommandManagement.cpp rename to src/CommandManagement.hpp index 36b0446..f52f9c2 100644 --- a/src/CommandManagement.cpp +++ b/src/CommandManagement.hpp @@ -1,5 +1,15 @@ -#include "Commands.hpp" +#include "../settings.hpp" #include +#include +#include + +extern std::unordered_map> + 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( diff --git a/src/Commands.cpp b/src/Commands.cpp new file mode 100644 index 0000000..682b06e --- /dev/null +++ b/src/Commands.cpp @@ -0,0 +1,17 @@ +#pragma once + +// Unity Build +#include "Commands/MoneyCommands.cpp" +#include "Commands/OtherCommands.cpp" + +// Registry +std::unordered_map> + Commands{{"ping", commandPing}, + {"about", commandAbout}, + {"balance", commandBalance}, + {"bal", commandBalance}, + {"pay", commandPay}, + {"print_money", commandPrintMoney}, + {"burn_money", commandBurnMoney}, + {"money_leaderboard", commandMoneyLeaderboard}}; diff --git a/src/Commands.hpp b/src/Commands.hpp deleted file mode 100644 index 6453dd3..0000000 --- a/src/Commands.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "../languages/locale_en.hpp" -#include "../settings.hpp" -#include -#include -#include - -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> - Commands{{"ping", commandPing}, - {"balance", commandBalance}, - {"bal", commandBalance}, - {"pay", commandPay}, - {"print_money", commandPrintMoney}, - {"burn_money", commandBurnMoney}, - {"money_leaderboard", commandMoneyLeaderboard}}; diff --git a/src/Commands/InlineDefinitions.hpp b/src/Commands/InlineDefinitions.hpp new file mode 100644 index 0000000..e0b6b28 --- /dev/null +++ b/src/Commands/InlineDefinitions.hpp @@ -0,0 +1,9 @@ +#include + +// 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); diff --git a/src/CommandEvents.cpp b/src/Commands/MoneyCommands.cpp similarity index 96% rename from src/CommandEvents.cpp rename to src/Commands/MoneyCommands.cpp index ff8d7ff..8808fc4 100644 --- a/src/CommandEvents.cpp +++ b/src/Commands/MoneyCommands.cpp @@ -1,15 +1,18 @@ -#include "Base/SQL.hpp" -#include "Commands.hpp" -#include +#include "../../settings.hpp" // This is where language is imported +#include "../Base/SQL.hpp" +#include "InlineDefinitions.hpp" + #include +#include #include -#include #include + +#include #include #include #include -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)); diff --git a/src/Commands/OtherCommands.cpp b/src/Commands/OtherCommands.cpp new file mode 100644 index 0000000..31a58ab --- /dev/null +++ b/src/Commands/OtherCommands.cpp @@ -0,0 +1,4 @@ +#include + +void commandPing(const dpp::slashcommand_t &event) { event.reply("Pong"); } +void commandAbout(const dpp::slashcommand_t &event) { event.reply("Pong"); }