aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--include/142bot/bot.hpp4
-rw-r--r--include/142bot/modules.hpp6
-rw-r--r--modules/mmanager/mmanager.cpp1
-rw-r--r--modules/spotify/spotify.cpp13
-rw-r--r--src/bot.cpp40
-rw-r--r--src/main.cpp2
-rw-r--r--src/modules.cpp10
8 files changed, 66 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index 74a777d..606405f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -97,3 +97,5 @@ tags
build/
config.json
.cache/
+.sentry-native
+*.log
diff --git a/include/142bot/bot.hpp b/include/142bot/bot.hpp
index 98a7ed6..342f32e 100644
--- a/include/142bot/bot.hpp
+++ b/include/142bot/bot.hpp
@@ -2,6 +2,7 @@
#include <dpp/user.h>
#include <dpp/dpp.h>
#include <pqxx/pqxx>
+#include <nlohmann/json.hpp>
#ifndef BOT_HPP
@@ -17,10 +18,11 @@ public:
char prefix;
pqxx::connection conn;
class dpp::cluster * core;
+ json cfg;
/* The bot's user from the ready event */
dpp::user user;
- Bot(bool development, dpp::cluster* cluster, char prefix);
+ Bot(bool development, dpp::cluster* cluster, char prefix, json &cfg);
//virtual ~Bot();
void set_owner_id(dpp::snowflake id);
diff --git a/include/142bot/modules.hpp b/include/142bot/modules.hpp
index c0aad32..0d48a56 100644
--- a/include/142bot/modules.hpp
+++ b/include/142bot/modules.hpp
@@ -54,6 +54,7 @@ enum Events
I_OnVoiceStateUpdate,
I_OnVoiceServerUpdate,
I_OnWebhooksUpdate,
+ I_OnCommand,
I_END
};
@@ -72,13 +73,16 @@ enum Events
} \
for (auto _i = list_to_call.begin(); _i != list_to_call.end(); ++_i) \
{ \
+ core->log(dpp::ll_debug, fmt::format("Attempting to call module")); \
try \
{ \
if (!(*_i)->x) { \
list_to_call = loader->EventHandlers[y]; \
+ core->log(dpp::ll_error, "Something happened!"); \
break; \
} \
sentry_remove_tag("module"); \
+ core->log(dpp::ll_debug, "called module 1"); \
} \
catch (std::exception& modexcept) \
{ \
@@ -89,6 +93,7 @@ enum Events
sentry_event_add_exception(event, exc); \
sentry_capture_event(event); \
} \
+ core->log(dpp::ll_debug, "Called module"); \
} \
};
@@ -196,6 +201,7 @@ public:
virtual bool OnVoiceStateUpdate(const dpp::voice_state_update_t &obj);
virtual bool OnVoiceServerUpdate(const dpp::voice_server_update_t &obj);
virtual bool OnWebhooksUpdate(const dpp::webhooks_update_t &obj);
+ virtual bool OnCommand(const dpp::message_create_t &message, const std::string &command, const std::vector<std::string>& params);
void EmbedSimple(const std::string &message, int64_t channelID);
};
diff --git a/modules/mmanager/mmanager.cpp b/modules/mmanager/mmanager.cpp
index f9ca704..2ff4636 100644
--- a/modules/mmanager/mmanager.cpp
+++ b/modules/mmanager/mmanager.cpp
@@ -64,6 +64,7 @@ public:
{
bot->core->log(dpp::ll_error, pcre_error);
}
+ bot->core->log(dpp::ll_debug, "Test");
int matcharr[90];
int matchcount = pcre_exec(comp, NULL, clean_message.c_str(), clean_message.length(), 0, 0, matcharr, 90);
diff --git a/modules/spotify/spotify.cpp b/modules/spotify/spotify.cpp
index 89c7b88..93b66ac 100644
--- a/modules/spotify/spotify.cpp
+++ b/modules/spotify/spotify.cpp
@@ -19,13 +19,14 @@
#include <stdlib.h>
#include "cpr/cpr.h"
#include <142bot/modules.hpp>
+#include <fmt/format.h>
class SpotifyModule: public Module {
std::string spotifyRegex;
public:
SpotifyModule(Bot* creator, ModuleLoader* ml) : Module(creator, ml) {
- ml->attach({I_OnMessage}, this);
+ ml->attach({I_OnMessage, I_OnCommand}, this);
this->spotifyRegex = "^https:\/\/open.spotify.com\/track\/([a-zA-Z0-9]+)(.*)$";
}
@@ -58,12 +59,20 @@ public:
EmbedSimple("Found a spotify URL", message.msg.channel_id);
} else {
if (clean_message.starts_with(bot->prefix)) {
-
+
}
}
return true;
}
+ virtual bool OnCommand(const dpp::message_create_t &message, const std::string &command, std::vector<std::string>& params) {
+ bot->core->log(dpp::ll_debug, fmt::format("spotify Got command: {}", command));
+ printf("Am i getting called?????\n");
+
+ EmbedSimple("Got your command!", message.msg.channel_id);
+
+ return true;
+ }
};
diff --git a/src/bot.cpp b/src/bot.cpp
index ed1531d..d5f21de 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -12,15 +12,16 @@
#include <pqxx/pqxx>
#include <142bot/db.hpp>
#include <filesystem>
+#include <nlohmann/json.hpp>
namespace fs = std::filesystem;
-Bot::Bot(bool devel, dpp::cluster* cluster, char prefix) {
+Bot::Bot(bool devel, dpp::cluster* cluster, char prefix, json &cfg) {
dev = devel;
this->core = cluster;
-
- std::ifstream f("config.json");
- json cfg = json::parse(f);
+ this->prefix = prefix;
+ this->cfg = cfg;
+
std::string token = cfg.value("token", "bad-token");
this->conn = db::connect(cfg["postgres"]["host"], cfg["postgres"]["user"], cfg["postgres"]["pass"], cfg["postgres"]["database"], cfg["postgres"]["port"]);
@@ -107,6 +108,7 @@ void Bot::onMessage(const dpp::message_create_t &message) {
}
/* Ignore self, and bots */
if (message.msg.author.id != user.id && message.msg.author.is_bot() == false) {
+ core->log(dpp::ll_debug, "Got message event");
/* Replace all mentions with raw nicknames */
bool mentioned = false;
@@ -129,9 +131,33 @@ void Bot::onMessage(const dpp::message_create_t &message) {
}
/* Remove linefeeds, they mess with botnix */
mentions_removed = trim(mentions_removed);
-
- /* Call modules */
- FOREACH_MOD(I_OnMessage,OnMessage(message, mentions_removed, mentioned, stringmentions));
+ if (message.msg.content.starts_with(this->prefix)) {
+ // Command
+ core->log(dpp::ll_debug, fmt::format("Got command: {}", mentions_removed));
+
+ // Tokenize
+ std::vector<std::string> result;
+
+ const char* str = message.msg.content.c_str();
+
+ do
+ {
+ const char *begin = str;
+ while(*str != ' ' && *str)
+ str++;
+ core->log(dpp::ll_debug, std::string(begin, str));
+
+ result.push_back(std::string(begin, str));
+ } while (0 != *str++);
+ core->log(dpp::ll_debug, "Attempting to call FOREACH_MOD");
+ FOREACH_MOD(I_OnCommand,OnCommand(message, result[0], result));
+
+ } else {
+ /* Call modules */
+ core->log(dpp::ll_debug, fmt::format("Got regular message: {}", mentions_removed));
+ FOREACH_MOD(I_OnMessage,OnMessage(message, mentions_removed,
+ mentioned, stringmentions));
+ }
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 08574d1..e6d7c13 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -74,7 +74,7 @@ int main(int argc, char const *argv[]) {
});
/* code */
- Bot client(0, &bot, cfg.value("prefix", ".").at(0));
+ Bot client(0, &bot, cfg.value("prefix", ".").at(0), cfg);
client.set_owner_id(dpp::snowflake(cfg.value("owner", "00000000000")));
diff --git a/src/modules.cpp b/src/modules.cpp
index 0c9fb18..4b636f9 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -7,6 +7,8 @@
#include <limits.h>
#include <link.h>
+#include <stdlib.h>
+
const char* StringNames[I_END + 1] = {
"I_BEGIN",
"I_OnMessage",
@@ -45,6 +47,7 @@ const char* StringNames[I_END + 1] = {
"I_OnVoiceStateUpdate",
"I_OnVoiceServerUpdate",
"I_OnWebhooksUpdate",
+ "I_OnCommand",
"I_END"
};
@@ -95,7 +98,7 @@ bool ModuleLoader::load(const std::string &fname) {
if (Modules.find(fname) == Modules.end()) {
char buffer[PATH_MAX + 1];
- getcwd(buffer, PATH_MAX);
+ realpath(bot->cfg.value("module_path", ".").c_str(), buffer);
std::string full_path = std::string(buffer) + "/" + fname;
m.dlopen_handle = dlopen(full_path.c_str(), RTLD_NOW | RTLD_LOCAL);
@@ -429,6 +432,11 @@ bool Module::OnWebhooksUpdate(const dpp::webhooks_update_t &obj)
return true;
}
+bool Module::OnCommand(const dpp::message_create_t &message, const std::string &command, const std::vector<std::string>& params) {
+ bot->core->log(dpp::ll_debug, "Called default OnCommand...");
+ return true;
+}
+
bool Module::OnAllShardsReady()
{
return true;