aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCara Salter <cara@devcara.com>2023-06-10 09:55:50 -0400
committerCara Salter <cara@devcara.com>2023-06-10 09:59:50 -0400
commit201fd6765d1e33a541d9d1dc87969dda9aea1113 (patch)
tree01a9ee8f27190e8b7a27aeefdaeac2c535ee2bc5
parent6136631d2dcd9b1f561fa589acabcda7de8e2f36 (diff)
download142bot-201fd6765d1e33a541d9d1dc87969dda9aea1113.tar.gz
142bot-201fd6765d1e33a541d9d1dc87969dda9aea1113.zip
mail: Finish mail alerting module0.6
Will allow for semi-automated alerts whenever there's mail for someone.
-rw-r--r--modules/mail/mail.cpp43
1 files changed, 20 insertions, 23 deletions
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 <dpp/dpp.h>
+#include <fmt/format.h>
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<dpp::snowflake>(event.get_parameter("recipient"));
+ std::string sender = std::get<std::string>(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)