aboutsummaryrefslogtreecommitdiff
path: root/modules/reactions
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2023-03-30 15:09:52 -0400
committerCara Salter <cara@devcara.com>2023-03-30 15:09:52 -0400
commit8233fc4bcffc82907e82b31072cb8129aa200ae5 (patch)
treebb9551e287fb632cbb3dfb070ffa228351ed4129 /modules/reactions
parent527b7ab2df126bb2f480999049ed05b057a6ef83 (diff)
download142bot-8233fc4bcffc82907e82b31072cb8129aa200ae5.tar.gz
142bot-8233fc4bcffc82907e82b31072cb8129aa200ae5.zip
reactions module
Diffstat (limited to 'modules/reactions')
-rw-r--r--modules/reactions/reactions.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/modules/reactions/reactions.cpp b/modules/reactions/reactions.cpp
new file mode 100644
index 0000000..3818d0d
--- /dev/null
+++ b/modules/reactions/reactions.cpp
@@ -0,0 +1,43 @@
+#include <dpp/message.h>
+#include <dpp/json.h>
+#include <stdlib.h>
+#include <142bot/modules.hpp>
+#include <fmt/format.h>
+
+using std::to_string;
+class ReactionsModule : public Module {
+ std::map<std::string, std::string> reactionMap;
+public:
+ ReactionsModule(Bot* creator, ModuleLoader* ml): Module(creator, ml) {
+ ml->attach({I_OnMessage}, this);
+
+ std::ifstream f("resources/reactions.json");
+ json reactions = json::parse(f);
+
+ for(auto it = reactions.begin(); it != reactions.end(); it++) {
+ reactionMap.insert_or_assign(it.key(), reactions.value(it.key(), ""));
+ }
+ }
+
+ virtual std::string version() {
+ return "0.1.0";
+ }
+
+ virtual std::string description() {
+ return "Auto-reactions based on keyword";
+ }
+ 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) {
+ bot->core->message_add_reaction(message.msg, i->second);
+ bot->core->log(dpp::ll_debug, "Adding reaction based on keyword");
+ }
+ }
+
+ return true;
+ }
+
+};
+
+
+ENTRYPOINT(ReactionsModule) \ No newline at end of file