Make users only pinged once when using notify

This commit is contained in:
Victor Mignot 2023-05-02 18:46:43 +02:00
parent 1583bfb8dd
commit 9e171efd4c
No known key found for this signature in database
GPG key ID: FFE4EF056FB5E0D0

View file

@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{collections::HashSet, sync::Arc};
use log::debug;
@ -99,6 +99,7 @@ impl BotCommand for TagNotifyCommand {
let user_selection = selector.get_user_selection().await?;
if let Some(selection) = user_selection {
let mut users_to_ping: HashSet<String> = HashSet::new();
let mut answer = String::new();
for selected_tag in selection {
let t = match guild.tags.iter().find(|s| s.name == selected_tag) {
@ -112,7 +113,7 @@ impl BotCommand for TagNotifyCommand {
match user_id.parse::<u64>() {
Ok(id) => match &UserId(id).to_user(&context).await {
Ok(e) => {
answer += &e.mention().to_string();
users_to_ping.insert(e.mention().to_string());
}
Err(_e) => {}
},
@ -120,6 +121,11 @@ impl BotCommand for TagNotifyCommand {
}
}
}
for user in users_to_ping {
answer.push_str(user.as_str());
}
let mut response = match self.interaction.get_interaction_response(&context).await {
Ok(r) => Ok(r),
Err(_e) => Err(CommandExecutionError::ContextRetrievalError(