aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
parent527b7ab2df126bb2f480999049ed05b057a6ef83 (diff)
download142bot-8233fc4bcffc82907e82b31072cb8129aa200ae5.tar.gz
142bot-8233fc4bcffc82907e82b31072cb8129aa200ae5.zip
reactions module
Diffstat (limited to 'src')
-rw-r--r--src/bot.cpp14
-rw-r--r--src/main.cpp6
-rw-r--r--src/meta.cpp9
-rw-r--r--src/modules.cpp39
4 files changed, 54 insertions, 14 deletions
diff --git a/src/bot.cpp b/src/bot.cpp
index 1c764b7..57bf091 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -1,4 +1,5 @@
+#include <dpp/snowflake.h>
#include <stdlib.h>
#include <142bot/bot.hpp>
#include <dpp/dpp.h>
@@ -22,6 +23,14 @@ bool Bot::isDevMode() {
return dev;
}
+void Bot::set_owner_id(dpp::snowflake id) {
+ this->owner_id = id;
+}
+
+dpp::snowflake Bot::get_owner_id() {
+ return this->owner_id;
+}
+
int64_t Bot::getID() {
return this->user.id;
}
@@ -127,9 +136,8 @@ void Bot::onGuildUpdate(const dpp::guild_update_t &obj)
}
-void Bot::onMessageReactionAdd(const dpp::message_reaction_add_t &obj)
-{
-
+void Bot::onMessageReactionAdd(const dpp::message_reaction_add_t &obj) {
+ FOREACH_MOD(I_OnMessageReactionAdd, OnMessageReactionAdd(obj));
}
diff --git a/src/main.cpp b/src/main.cpp
index d58f474..8f3ad9a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -6,6 +6,7 @@
#include <spdlog/async.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/sinks/rotating_file_sink.h>
+#include <string>
using namespace std;
@@ -29,7 +30,7 @@ int main(int argc, char const *argv[]) {
log = std::make_shared<spdlog::async_logger>("logs", sinks.begin(), sinks.end(), spdlog::thread_pool(), spdlog::async_overflow_policy::block);
spdlog::register_logger(log);
log->set_pattern("%^%Y-%m-%d %H:%M:%S.%e [%L] [th#%t]%$ : %v");
- log->set_level(spdlog::level::level_enum::debug);
+ log->set_level(spdlog::level::level_enum::trace);
/* Integrate spdlog logger to D++ log events */
bot.on_log([&bot, &log](const dpp::log_t & event) {
@@ -59,9 +60,12 @@ int main(int argc, char const *argv[]) {
Bot client(0, &bot);
+ client.set_owner_id(dpp::snowflake(cfg.value("owner", "00000000000")));
+
/* Attach events to the Bot class methods */
bot.on_message_create(std::bind(&Bot::onMessage, &client, std::placeholders::_1));
bot.on_ready(std::bind(&Bot::onReady, &client, std::placeholders::_1));
+ bot.on_message_reaction_add(std::bind(&Bot::onMessageReactionAdd, &client, std::placeholders::_1));
bot.start(dpp::st_wait);
return 0;
diff --git a/src/meta.cpp b/src/meta.cpp
deleted file mode 100644
index 3ae58a7..0000000
--- a/src/meta.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <dpp/dpp.h>
-#include <commandhandler.h>
-
-using namespace std;
-using namespace dpp;
-
-void about(const std::string &name, const parameter_list_t &params, command_source) {
-
-} \ No newline at end of file
diff --git a/src/modules.cpp b/src/modules.cpp
index efdc447..6a8d500 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -116,7 +116,7 @@ bool ModuleLoader::load(const std::string &fname) {
dlclose(m.dlopen_handle);
return false;
} else {
- bot->core->log(dpp::ll_info, fmt::format("Loaded module {}", m.mod->description()));
+ bot->core->log(dpp::ll_info, fmt::format("Loaded {} ({})", m.mod->description(), m.mod->version()));
Modules[fname] = m;
mod_map[fname] = m.mod;
return true;
@@ -173,6 +173,15 @@ bool ModuleLoader::unload(const std::string &fname) {
}
+
+bool ModuleLoader::reload(const std::string &filename)
+{
+ /* Short-circuit evaluation here means that if Unload() returns false,
+ * Load() won't be called at all.
+ */
+ return (unload(filename) && load(filename));
+}
+
/**
* Return a given symbol name from a shared object represented by the ModuleNative value.
*/
@@ -410,3 +419,31 @@ bool Module::OnAllShardsReady()
}
+
+/**
+ * Output a simple embed to a channel consisting just of a message.
+ */
+void Module::EmbedSimple(const std::string &message, int64_t channelID)
+{
+ std::stringstream s;
+ json embed_json;
+
+ s << "{\"color\":16767488, \"description\": \"" << message << "\"}";
+
+ try {
+ embed_json = json::parse(s.str());
+ }
+ catch (const std::exception &e) {
+ bot->core->log(dpp::ll_error, fmt::format("Invalid json for channel {} created by EmbedSimple: ", channelID, s.str()));
+ }
+ dpp::channel* channel = dpp::find_channel(channelID);
+ if (channel) {
+ dpp::message m;
+ m.channel_id = channel->id;
+ m.embeds.push_back(dpp::embed(&embed_json));
+ bot->core->message_create(m);
+
+ } else {
+ bot->core->log(dpp::ll_error, fmt::format("Invalid channel {} passed to EmbedSimple", channelID));
+ }
+} \ No newline at end of file