aboutsummaryrefslogtreecommitdiff
path: root/src/modules.cpp
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/modules.cpp
parent527b7ab2df126bb2f480999049ed05b057a6ef83 (diff)
download142bot-8233fc4bcffc82907e82b31072cb8129aa200ae5.tar.gz
142bot-8233fc4bcffc82907e82b31072cb8129aa200ae5.zip
reactions module
Diffstat (limited to 'src/modules.cpp')
-rw-r--r--src/modules.cpp39
1 files changed, 38 insertions, 1 deletions
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