mirror of
https://gitlab.com/niansa/SomeBot.git
synced 2025-03-06 20:48:26 +01:00
65 lines
2.5 KiB
C++
65 lines
2.5 KiB
C++
#ifndef _BOT_HPP
|
|
#define _BOT_HPP
|
|
#include <string>
|
|
#include <string_view>
|
|
#include <functional>
|
|
|
|
#include <dpp/dpp.h>
|
|
#include "sqlite_modern_cpp/sqlite_modern_cpp.h"
|
|
|
|
|
|
|
|
#define BOT_ADD_MODULE(name) static name this_bot_module
|
|
|
|
class Bot {
|
|
static std::vector<std::function<void ()>> on_init;
|
|
|
|
public:
|
|
dpp::cluster cluster;
|
|
sqlite::database db;
|
|
|
|
template<class interactionCallbackDataT>
|
|
struct Interaction {
|
|
std::vector<std::string> names;
|
|
std::string description;
|
|
dpp::slashcommand misc;
|
|
using Callback = std::function<void (const interactionCallbackDataT& i)>;
|
|
Callback callback;
|
|
|
|
Interaction(const std::vector<std::string>& names, const std::string& description)
|
|
: names(names), description(description) {}
|
|
Interaction(const std::vector<std::string>& names, const std::string& description, const dpp::slashcommand& misc)
|
|
: names(names), description(description), misc(misc) {}
|
|
|
|
void operator()(const interactionCallbackDataT& i) const {
|
|
callback(i);
|
|
}
|
|
|
|
bool operator==(const dpp::interaction& i) const {
|
|
for (const auto& name : names) {
|
|
if (name == i.get_command_name()) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
};
|
|
using ChatCommand = Interaction<dpp::slashcommand_t>;
|
|
using UserCommand = Interaction<dpp::user_context_menu_t>;
|
|
using MessageCommand = Interaction<dpp::message_context_menu_t>;
|
|
std::vector<ChatCommand> chat_commands;
|
|
std::vector<UserCommand> user_commands;
|
|
std::vector<MessageCommand> message_commands;
|
|
std::vector<std::pair<ChatCommand, dpp::snowflake>> guild_chat_commands;
|
|
std::vector<std::pair<UserCommand, dpp::snowflake>> guild_user_commands;
|
|
std::vector<std::pair<MessageCommand, dpp::snowflake>> guild_message_commands;
|
|
|
|
Bot(const std::string& token, const std::string& database = "db.sqlite3") : cluster(token), db(database) {}
|
|
|
|
void start(bool reregister_commands = true);
|
|
static inline void add_on_init(const std::function<void ()>& cb) {on_init.push_back(cb);}
|
|
void add_chatcommand(ChatCommand command, const ChatCommand::Callback& cb, dpp::snowflake guild_id = 0);
|
|
void add_usercommand(UserCommand command, const UserCommand::Callback& cb, dpp::snowflake guild_id = 0);
|
|
void add_messagecommand(MessageCommand command, const MessageCommand::Callback& cb, dpp::snowflake guild_id = 0);
|
|
} extern *bot;
|
|
#endif // _BOT_HPP
|