aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2023-06-10 00:06:07 -0400
committerCara Salter <cara@devcara.com>2023-06-10 00:06:07 -0400
commit6136631d2dcd9b1f561fa589acabcda7de8e2f36 (patch)
treef52b1afe5bdceff29bc11015c3f00b54d4bd4b76
parente09e7825369ec8217456065d31dbbbb992b7f1bb (diff)
download142bot-6136631d2dcd9b1f561fa589acabcda7de8e2f36.tar.gz
142bot-6136631d2dcd9b1f561fa589acabcda7de8e2f36.zip
mail: Init mail module
Also bind the slash command and form submit events properly Change-Id: I8d01cb0075945c79c6bf991fa4d64f5227dd5f86
-rw-r--r--config.example.json1
-rw-r--r--include/142bot/bot.hpp2
-rw-r--r--include/142bot/modules.hpp4
-rw-r--r--modules/mail/mail.cpp52
-rw-r--r--src/bot.cpp7
-rw-r--r--src/main.cpp2
-rw-r--r--src/modules.cpp10
7 files changed, 78 insertions, 0 deletions
diff --git a/config.example.json b/config.example.json
index 015aaf4..e184e51 100644
--- a/config.example.json
+++ b/config.example.json
@@ -5,6 +5,7 @@
"module_mmanager.so"
],
"owner": "changeme",
+ "main_guild": "changeme",
"postgres": {
"host": "localhost",
"port": 5432,
diff --git a/include/142bot/bot.hpp b/include/142bot/bot.hpp
index 1fdb042..dc709ef 100644
--- a/include/142bot/bot.hpp
+++ b/include/142bot/bot.hpp
@@ -68,6 +68,8 @@ public:
void onVoiceStateUpdate (const dpp::voice_state_update_t &event);
void onVoiceServerUpdate (const dpp::voice_server_update_t &event);
void onWebhooksUpdate (const dpp::webhooks_update_t &event);
+ void onSlashCommand (const dpp::slashcommand_t &event);
+ void onFormSubmit (const dpp::form_submit_t &event);
};
#endif
diff --git a/include/142bot/modules.hpp b/include/142bot/modules.hpp
index 37f4401..617d5af 100644
--- a/include/142bot/modules.hpp
+++ b/include/142bot/modules.hpp
@@ -55,6 +55,8 @@ enum Events
I_OnVoiceServerUpdate,
I_OnWebhooksUpdate,
I_OnCommand,
+ I_OnSlashCommand,
+ I_OnFormSubmit,
I_END
};
@@ -202,6 +204,8 @@ public:
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);
+ virtual bool OnSlashCommand(const dpp::slashcommand_t &event);
+ virtual bool OnFormSubmit(const dpp::form_submit_t &event);
void EmbedSimple(const std::string &message, int64_t channelID);
void EmbedError(int64_t channelId, std::exception &e);
void EmbedError(const std::string &message, int64_t channelId);
diff --git a/modules/mail/mail.cpp b/modules/mail/mail.cpp
new file mode 100644
index 0000000..9ec170a
--- /dev/null
+++ b/modules/mail/mail.cpp
@@ -0,0 +1,52 @@
+#include <142bot/modules.hpp>
+#include <142bot/util.hpp>
+#include <dpp/dpp.h>
+
+class MailModule: public Module {
+ public:
+ MailModule(Bot* creator, ModuleLoader* ml) : Module(creator, ml) {
+ ml->attach({I_OnSlashCommand, I_OnFormSubmit}, this);
+ auto id = creator->cfg.value("application_id", "");
+ creator->core->log(dpp::ll_info, "Application ID: " + id);
+ creator->core->guild_command_create(dpp::slashcommand("mailalert", "Alert a resident that they have mail", id), creator->cfg["main_guild"]);
+ creator->core->log(dpp::ll_info, "Registered mailalert");
+ }
+
+ virtual std::string version() {
+ return "0.1.0";
+ }
+
+ virtual std::string description() {
+ return "Alerts residents when mail has arrived";
+ }
+
+ bool OnSlashCommand(const dpp::slashcommand_t &event) {
+ if (event.command.get_command_name() == "mailalert") {
+ dpp::interaction_modal_response dialog("mail", "Mail alert!");
+
+ dialog.add_component(
+ dpp::component()
+ .set_label("Sender")
+ .set_type(dpp::component_type::cot_text)
+ .set_id("sender")
+ .set_placeholder("Boom boom")
+ .set_text_style(dpp::text_style_type::text_short)
+ );
+
+ auto select_comp = dialog.add_component(
+ dpp::component()
+ .set_label("Recipient")
+ .set_id("recipient")
+ .set_type(dpp::component_type::cot_mentionable_selectmenu)
+ );
+ }
+ return true;
+ }
+
+ bool OnFormSubmit(const dpp::form_submit_t &event) {
+
+ return true;
+ }
+};
+
+ENTRYPOINT(MailModule)
diff --git a/src/bot.cpp b/src/bot.cpp
index 8c3a84c..d3bd6b7 100644
--- a/src/bot.cpp
+++ b/src/bot.cpp
@@ -346,3 +346,10 @@ void Bot::onWebhooksUpdate(const dpp::webhooks_update_t &obj)
}
+void Bot::onSlashCommand(const dpp::slashcommand_t &event) {
+ FOREACH_MOD(I_OnSlashCommand, OnSlashCommand(event));
+}
+
+void Bot::onFormSubmit(const dpp::form_submit_t &event) {
+ FOREACH_MOD(I_OnFormSubmit, OnFormSubmit(event));
+} \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index e6d7c13..6ce5858 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -82,6 +82,8 @@ int main(int argc, char const *argv[]) {
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.on_slashcommand(std::bind(&Bot::onSlashCommand, &client, std::placeholders::_1));
+ bot.on_form_submit(std::bind(&Bot::onFormSubmit, &client, std::placeholders::_1));
bot.start(dpp::st_wait);
sentry_close();
diff --git a/src/modules.cpp b/src/modules.cpp
index e784c0c..62cc70e 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -48,6 +48,8 @@ const char* StringNames[I_END + 1] = {
"I_OnVoiceServerUpdate",
"I_OnWebhooksUpdate",
"I_OnCommand",
+ "I_OnSlashCommand",
+ "I_OnFormSubmit",
"I_END"
};
@@ -437,6 +439,14 @@ bool Module::OnCommand(const dpp::message_create_t &message, const std::string &
return true;
}
+bool Module::OnSlashCommand(const dpp::slashcommand_t &event) {
+ return true;
+}
+
+bool Module::OnFormSubmit(const dpp::form_submit_t &event) {
+ return true;
+}
+
bool Module::OnAllShardsReady()
{
return true;