aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2023-03-30 15:58:57 -0400
committerCara Salter <cara@devcara.com>2023-03-30 15:58:57 -0400
commite63f88aa3f8fe1c0cf8366ee09188a4b18ede166 (patch)
treea5184887a2ad23623bd1cf1c9d545bd9bf3aac4b
parent8233fc4bcffc82907e82b31072cb8129aa200ae5 (diff)
download142bot-e63f88aa3f8fe1c0cf8366ee09188a4b18ede166.tar.gz
142bot-e63f88aa3f8fe1c0cf8366ee09188a4b18ede166.zip
Finish reactions module
-rw-r--r--include/142bot/modules.hpp2
-rw-r--r--modules/reactions/reactions.cpp3
-rw-r--r--src/bot.cpp5
-rw-r--r--src/modules.cpp16
4 files changed, 21 insertions, 5 deletions
diff --git a/include/142bot/modules.hpp b/include/142bot/modules.hpp
index ab888d3..27025b8 100644
--- a/include/142bot/modules.hpp
+++ b/include/142bot/modules.hpp
@@ -136,6 +136,8 @@ public:
// Unloads and then reloads a module
bool reload(const std::string &fname);
+ void load_all();
+
// Get list of loaded modules
const ModuleMap& get_loaded_modules() const;
};
diff --git a/modules/reactions/reactions.cpp b/modules/reactions/reactions.cpp
index 3818d0d..6455840 100644
--- a/modules/reactions/reactions.cpp
+++ b/modules/reactions/reactions.cpp
@@ -2,6 +2,7 @@
#include <dpp/json.h>
#include <stdlib.h>
#include <142bot/modules.hpp>
+#include <142bot/util.hpp>
#include <fmt/format.h>
using std::to_string;
@@ -28,7 +29,7 @@ public:
}
virtual bool OnMessage(const dpp::message_create_t &message, const std::string& clean_message, bool mentioned, const std::vector<std::string> &stringmentions) {
for (auto i = reactionMap.begin(); i != reactionMap.end(); i++) {
- if (clean_message.find(i->first) != std::string::npos) {
+ if (lowercase(clean_message).find(i->first) != std::string::npos) {
bot->core->message_add_reaction(message.msg, i->second);
bot->core->log(dpp::ll_debug, "Adding reaction based on keyword");
}
diff --git a/src/bot.cpp b/src/bot.cpp
index 57bf091..03bea02 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -12,10 +12,7 @@ Bot::Bot(bool devel, dpp::cluster* cluster) {
dev = devel;
this->core = cluster;
this->loader = new ModuleLoader(this);
- if (!this->loader->load("module_mmanager.so")) {
- this->core->log(dpp::ll_error, "Couldn't load modulemanager");
- exit(-1);
- }
+ this->loader->load_all();
// this->loader->LoadAll();
}
diff --git a/src/modules.cpp b/src/modules.cpp
index 6a8d500..b2e56e1 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -182,6 +182,22 @@ bool ModuleLoader::reload(const std::string &filename)
return (unload(filename) && load(filename));
}
+
+/**
+ * Load all modules from the config file modules.json
+ */
+void ModuleLoader::load_all()
+{
+ json document;
+ std::ifstream configfile("./config.json");
+ configfile >> document;
+ json modlist = document["modules"];
+ for (auto entry = modlist.begin(); entry != modlist.end(); ++entry) {
+ std::string modulename = entry->get<std::string>();
+ this->load(modulename);
+ }
+}
+
/**
* Return a given symbol name from a shared object represented by the ModuleNative value.
*/