From c72b1e97dd6c856ef76ec3f808b05ceeec6f867d Mon Sep 17 00:00:00 2001 From: Emilia Jaser Date: Sat, 10 Feb 2024 14:03:50 +0100 Subject: [PATCH] Fix deduplication --- src/bot/commands/subject.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/bot/commands/subject.rs b/src/bot/commands/subject.rs index 60fff04..b8d2795 100644 --- a/src/bot/commands/subject.rs +++ b/src/bot/commands/subject.rs @@ -1,5 +1,7 @@ //! TODO: Permissions +use std::collections::HashSet; + use futures::future::join_all; use poise::serenity_prelude::{GuildId, RoleId}; use sqlx::{MySql, Pool}; @@ -154,11 +156,11 @@ async fn get_available_subjects( let subjects = join_all(subjects).await; - let flattened_subjects: Vec = subjects.iter() - .flatten().flatten().cloned().dedup() - .collect(); - - flattened_subjects + subjects.iter() + .flatten().flatten().cloned() + .sorted_by_key(|subject| subject.id) + .dedup() + .collect() } /// Parses subject names/ids from user input, then