From 6136631d2dcd9b1f561fa589acabcda7de8e2f36 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Sat, 10 Jun 2023 00:06:07 -0400 Subject: mail: Init mail module Also bind the slash command and form submit events properly Change-Id: I8d01cb0075945c79c6bf991fa4d64f5227dd5f86 --- config.example.json | 1 + include/142bot/bot.hpp | 2 ++ include/142bot/modules.hpp | 4 ++++ modules/mail/mail.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++ src/bot.cpp | 7 +++++++ src/main.cpp | 2 ++ src/modules.cpp | 10 +++++++++ 7 files changed, 78 insertions(+) create mode 100644 modules/mail/mail.cpp 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& 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 + +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; -- cgit v1.2.3