Compare commits
2 Commits
24c82ee668
...
e4e9db2f84
Author | SHA1 | Date | |
---|---|---|---|
e4e9db2f84 | |||
a29587d0cb |
@@ -6,8 +6,7 @@ project(TheBartender VERSION 1.0)
|
|||||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||||
|
|
||||||
# Create an executable
|
# Create an executable
|
||||||
add_executable(${PROJECT_NAME} src/Base/Entry.cpp src/CommandEvents.cpp
|
add_executable(${PROJECT_NAME} src/Base/Entry.cpp src/Commands.cpp)
|
||||||
src/CommandManagement.cpp)
|
|
||||||
|
|
||||||
# Find our pre-installed DPP package (using FindDPP.cmake).
|
# Find our pre-installed DPP package (using FindDPP.cmake).
|
||||||
find_package(DPP REQUIRED)
|
find_package(DPP REQUIRED)
|
||||||
|
@@ -1,5 +1,20 @@
|
|||||||
|
// Bot info
|
||||||
|
#define BOT_NAME "The Bartender bot"
|
||||||
|
#define BOT_VERSION "v0.2"
|
||||||
|
|
||||||
#define CURRENCY_NAME "Night Coin"
|
#define CURRENCY_NAME "Night Coin"
|
||||||
|
|
||||||
|
// Command ping
|
||||||
|
#define COMMAND_PING_DESCRIPTION "Ping-pong test"
|
||||||
|
|
||||||
|
// Command about
|
||||||
|
#define COMMAND_ABOUT_DESCRIPTION "Info about the bot"
|
||||||
|
#define COMMAND_ABOUT_RESPONSE \
|
||||||
|
"## " BOT_NAME " " BOT_VERSION \
|
||||||
|
"\n-> Written by <@!607952795794145281>.\n-> Source code " \
|
||||||
|
"https://git.thenight.club/cat/BartenderBot.\n-> Made with " \
|
||||||
|
"[D++](https://dpp.dev/) and tears."
|
||||||
|
|
||||||
// Command balance/bal
|
// Command balance/bal
|
||||||
#define COMMAND_BALANCE_DESCRIPTION "See someone's balance of " CURRENCY_NAME
|
#define COMMAND_BALANCE_DESCRIPTION "See someone's balance of " CURRENCY_NAME
|
||||||
#define COMMAND_BALANCE_USER_DESCRIPTION \
|
#define COMMAND_BALANCE_USER_DESCRIPTION \
|
||||||
|
@@ -5,3 +5,7 @@
|
|||||||
|
|
||||||
// Whoever is going to be admin. Their ID here
|
// Whoever is going to be admin. Their ID here
|
||||||
#define ADMIN_ID 0
|
#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 "../../settings.hpp"
|
||||||
#include "../Commands.hpp"
|
#include "../CommandManagement.hpp"
|
||||||
#include "../Databases.hpp"
|
#include "../Databases.hpp"
|
||||||
|
|
||||||
#include <dpp/cluster.h>
|
#include <dpp/cluster.h>
|
||||||
#include <dpp/dispatcher.h>
|
#include <dpp/dispatcher.h>
|
||||||
#include <dpp/dpp.h>
|
#include <dpp/dpp.h>
|
||||||
#include <dpp/once.h>
|
#include <dpp/once.h>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
// SQL database set up
|
// SQL database set up
|
||||||
@@ -28,12 +27,12 @@ int main(int argc, char **argv) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
bot.on_ready([&bot](const dpp::ready_t &event) {
|
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>()) {
|
if (dpp::run_once<struct register_bot_commands>()) {
|
||||||
createCommands(event, bot);
|
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
|
// Remove dpp::st_wait if you want it to return execution
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@@ -1,9 +1,22 @@
|
|||||||
#include "Commands.hpp"
|
#include "../settings.hpp"
|
||||||
#include <dpp/appcommand.h>
|
#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) {
|
void createCommands(const dpp::ready_t &event, dpp::cluster &bot) {
|
||||||
bot.global_command_create(
|
bot.global_command_create(
|
||||||
dpp::slashcommand("ping", "Ping-pong test", bot.me.id));
|
dpp::slashcommand("ping", COMMAND_PING_DESCRIPTION, bot.me.id));
|
||||||
|
|
||||||
|
bot.guild_command_create(
|
||||||
|
dpp::slashcommand("about", COMMAND_ABOUT_DESCRIPTION, bot.me.id), GUILD);
|
||||||
|
|
||||||
// Money related stuff
|
// Money related stuff
|
||||||
bot.guild_command_create(
|
bot.guild_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 "../../settings.hpp" // This is where language is imported
|
||||||
#include "Commands.hpp"
|
#include "../Base/SQL.hpp"
|
||||||
#include <cstdint>
|
#include "InlineDefinitions.hpp"
|
||||||
|
|
||||||
#include <dpp/appcommand.h>
|
#include <dpp/appcommand.h>
|
||||||
|
#include <dpp/cluster.h>
|
||||||
#include <dpp/dispatcher.h>
|
#include <dpp/dispatcher.h>
|
||||||
#include <dpp/exception.h>
|
|
||||||
#include <dpp/snowflake.h>
|
#include <dpp/snowflake.h>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
|
|
||||||
void commandPing(const dpp::slashcommand_t &event) { event.reply("Pong"); }
|
// Actual commands
|
||||||
void commandBalance(const dpp::slashcommand_t &event) {
|
void commandBalance(const dpp::slashcommand_t &event) {
|
||||||
std::string person, balance;
|
std::string person, balance;
|
||||||
dpp::command_value id = event.get_parameter("user");
|
dpp::command_value id = event.get_parameter("user");
|
||||||
@@ -110,6 +113,7 @@ void commandMoneyLeaderboard(const dpp::slashcommand_t &event) {
|
|||||||
///
|
///
|
||||||
/// HELPER INLINE METHODS
|
/// HELPER INLINE METHODS
|
||||||
///
|
///
|
||||||
|
|
||||||
inline void increaseFromUsersBalance(const dpp::snowflake userid,
|
inline void increaseFromUsersBalance(const dpp::snowflake userid,
|
||||||
std::uint64_t amount) {
|
std::uint64_t amount) {
|
||||||
std::uint64_t balance = std::stoi(getUserBalance(userid));
|
std::uint64_t balance = std::stoi(getUserBalance(userid));
|
7
src/Commands/OtherCommands.cpp
Normal file
7
src/Commands/OtherCommands.cpp
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#include "../../settings.hpp"
|
||||||
|
#include <dpp/dispatcher.h>
|
||||||
|
|
||||||
|
void commandPing(const dpp::slashcommand_t &event) { event.reply("Pong"); }
|
||||||
|
void commandAbout(const dpp::slashcommand_t &event) {
|
||||||
|
event.reply(COMMAND_ABOUT_RESPONSE);
|
||||||
|
}
|
Reference in New Issue
Block a user