added mention blocker to everything

This commit is contained in:
jellywx 2021-11-15 07:51:38 +00:00
parent ebd1efa990
commit 610779a293
2 changed files with 37 additions and 21 deletions

View File

@ -8,6 +8,7 @@ use crate::{
}, },
consts::{EMBED_DESCRIPTION_MAX_LENGTH, SELECT_MAX_ENTRIES, THEME_COLOR}, consts::{EMBED_DESCRIPTION_MAX_LENGTH, SELECT_MAX_ENTRIES, THEME_COLOR},
framework::{CommandInvoke, CommandOptions, CreateGenericResponse}, framework::{CommandInvoke, CommandOptions, CreateGenericResponse},
hooks::CHECK_GUILD_PERMISSIONS_HOOK,
SQLPool, SQLPool,
}; };
@ -49,6 +50,7 @@ use crate::{
)] )]
#[subcommand("view")] #[subcommand("view")]
#[description("View and remove from your personal todo list")] #[description("View and remove from your personal todo list")]
#[hook(CHECK_GUILD_PERMISSIONS_HOOK)]
async fn todo(ctx: &Context, invoke: &mut CommandInvoke, args: CommandOptions) { async fn todo(ctx: &Context, invoke: &mut CommandInvoke, args: CommandOptions) {
if invoke.guild_id().is_none() && args.subcommand_group != Some("user".to_string()) { if invoke.guild_id().is_none() && args.subcommand_group != Some("user".to_string()) {
let _ = invoke let _ = invoke
@ -106,7 +108,7 @@ WHERE users.user <=> ? AND channels.channel <=> ? AND guilds.guild <=> ?",
let resp = show_todo_page(&values, 0, keys.0, keys.1, keys.2); let resp = show_todo_page(&values, 0, keys.0, keys.1, keys.2);
let _ = invoke.respond(&ctx, resp).await; invoke.respond(&ctx, resp).await.unwrap();
} }
} }
} }
@ -193,33 +195,43 @@ pub fn show_todo_page(
"Server" "Server"
}; };
let todo_selector = if todo_ids.is_empty() {
ComponentDataModel::TodoSelector(TodoSelector { page, user_id, channel_id, guild_id }); CreateGenericResponse::new().embed(|e| {
CreateGenericResponse::new()
.embed(|e| {
e.title(format!("{} Todo List", title)) e.title(format!("{} Todo List", title))
.description(display) .description("Todo List Empty!")
.footer(|f| f.text(format!("Page {} of {}", page + 1, pages))) .footer(|f| f.text(format!("Page {} of {}", page + 1, pages)))
.color(*THEME_COLOR) .color(*THEME_COLOR)
}) })
.components(|comp| { } else {
pager.create_button_row(pages, comp); let todo_selector =
ComponentDataModel::TodoSelector(TodoSelector { page, user_id, channel_id, guild_id });
comp.create_action_row(|row| { CreateGenericResponse::new()
row.create_select_menu(|menu| { .embed(|e| {
menu.custom_id(todo_selector.to_custom_id()).options(|opt| { e.title(format!("{} Todo List", title))
for (count, (id, disp)) in todo_ids.iter().zip(&display_vec).enumerate() { .description(display)
opt.create_option(|o| { .footer(|f| f.text(format!("Page {} of {}", page + 1, pages)))
o.label(format!("Mark {} complete", count + first_num)) .color(*THEME_COLOR)
.value(id) })
.description(disp.split_once(" ").unwrap_or(("", "")).1) .components(|comp| {
}); pager.create_button_row(pages, comp);
}
opt comp.create_action_row(|row| {
row.create_select_menu(|menu| {
menu.custom_id(todo_selector.to_custom_id()).options(|opt| {
for (count, (id, disp)) in todo_ids.iter().zip(&display_vec).enumerate()
{
opt.create_option(|o| {
o.label(format!("Mark {} complete", count + first_num))
.value(id)
.description(disp.split_once(" ").unwrap_or(("", "")).1)
});
}
opt
})
}) })
}) })
}) })
}) }
} }

View File

@ -162,6 +162,7 @@ impl CommandInvoke {
InvokeModel::Slash(i) => { InvokeModel::Slash(i) => {
if self.already_responded { if self.already_responded {
i.create_followup_message(http, |d| { i.create_followup_message(http, |d| {
d.allowed_mentions(|m| m.empty_parse());
d.content(generic_response.content); d.content(generic_response.content);
if let Some(embed) = generic_response.embed { if let Some(embed) = generic_response.embed {
@ -181,6 +182,7 @@ impl CommandInvoke {
.map(|_| ()) .map(|_| ())
} else if self.deferred { } else if self.deferred {
i.edit_original_interaction_response(http, |d| { i.edit_original_interaction_response(http, |d| {
d.allowed_mentions(|m| m.empty_parse());
d.content(generic_response.content); d.content(generic_response.content);
if let Some(embed) = generic_response.embed { if let Some(embed) = generic_response.embed {
@ -202,6 +204,7 @@ impl CommandInvoke {
i.create_interaction_response(http, |r| { i.create_interaction_response(http, |r| {
r.kind(InteractionResponseType::ChannelMessageWithSource) r.kind(InteractionResponseType::ChannelMessageWithSource)
.interaction_response_data(|d| { .interaction_response_data(|d| {
d.allowed_mentions(|m| m.empty_parse());
d.content(generic_response.content); d.content(generic_response.content);
if let Some(embed) = generic_response.embed { if let Some(embed) = generic_response.embed {
@ -225,6 +228,7 @@ impl CommandInvoke {
InvokeModel::Component(i) => i InvokeModel::Component(i) => i
.create_interaction_response(http, |r| { .create_interaction_response(http, |r| {
r.kind(InteractionResponseType::UpdateMessage).interaction_response_data(|d| { r.kind(InteractionResponseType::UpdateMessage).interaction_response_data(|d| {
d.allowed_mentions(|m| m.empty_parse());
d.content(generic_response.content); d.content(generic_response.content);
if let Some(embed) = generic_response.embed { if let Some(embed) = generic_response.embed {