From 201fd6765d1e33a541d9d1dc87969dda9aea1113 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Sat, 10 Jun 2023 09:55:50 -0400 Subject: mail: Finish mail alerting module Will allow for semi-automated alerts whenever there's mail for someone. --- modules/mail/mail.cpp | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) (limited to 'modules/mail') diff --git a/modules/mail/mail.cpp b/modules/mail/mail.cpp index 9ec170a..503c4eb 100644 --- a/modules/mail/mail.cpp +++ b/modules/mail/mail.cpp @@ -1,19 +1,22 @@ #include <142bot/modules.hpp> #include <142bot/util.hpp> #include +#include class MailModule: public Module { public: MailModule(Bot* creator, ModuleLoader* ml) : Module(creator, ml) { - ml->attach({I_OnSlashCommand, I_OnFormSubmit}, this); + ml->attach({I_OnSlashCommand}, 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->guild_command_create(dpp::slashcommand("mailalert", "Alert a resident that they have mail", id) + .add_option(dpp::command_option(dpp::co_string, "sender", "Who sent the mail?", true)) + .add_option(dpp::command_option(dpp::co_user, "recipient", "Who's the mail for?", true)), creator->cfg["main_guild"]); creator->core->log(dpp::ll_info, "Registered mailalert"); } virtual std::string version() { - return "0.1.0"; + return "0.1.1"; } virtual std::string description() { @@ -22,31 +25,25 @@ class MailModule: public Module { 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) - ); + dpp::snowflake recipient = std::get(event.get_parameter("recipient")); + std::string sender = std::get(event.get_parameter("sender")); + + auto rec = dpp::find_guild_member(bot->cfg.value("main_guild", ""), recipient); + auto roles = rec.roles; + for (int i = 0; i < roles.size(); ++i) { + if (roles[i] == 1083010579406536705u) { + std::string msg = fmt::format("**ALERT. ALERT.**\nMAIL STORAGE LEVELS CRITICAL. NEW MAIL FOR...\n\n{}...\n\nFROM...\n\n{}", rec.get_mention(), sender); + event.reply(dpp::message(msg).set_allowed_mentions(true, false, false, false, {}, {})); + return true; + } + } + + event.reply(dpp::message("**USER NOT RESIDENT. PLEASE TRY AGAIN.**").set_flags(dpp::m_ephemeral)); } return true; } - bool OnFormSubmit(const dpp::form_submit_t &event) { - return true; - } }; ENTRYPOINT(MailModule) -- cgit v1.2.3