Skip to content

Commit

Permalink
bug fix :(
Browse files Browse the repository at this point in the history
  • Loading branch information
B-2U committed Jul 21, 2024
1 parent 7282476 commit 30d0f3e
Showing 1 changed file with 7 additions and 30 deletions.
37 changes: 7 additions & 30 deletions src/dc_utils/auto_complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub async fn player(ctx: Context<'_>, input: &str) -> Vec<AutocompleteChoice> {
.collect()
}

/// return a serialized [`AutoCompleteClan`] struct
/// return a formatted string, e.g. [PANTS] Dont Cap Kill All (ASIA)
pub async fn clan(ctx: Context<'_>, input: &str) -> Vec<AutocompleteChoice> {
let input: Vec<&str> = input.split_whitespace().collect();
let Some((region, clan_name)) = (match input.len() {
Expand All @@ -57,44 +57,21 @@ pub async fn clan(ctx: Context<'_>, input: &str) -> Vec<AutocompleteChoice> {
_ => Some((Region::parse(input[0]).unwrap_or_default(), input[1])),
}) else {
return [
(
"Example: VOR",
AutoCompleteClan {
tag: ClanTag::from("VOR"),
region: Region::Asia,
},
),
(
"Example: EU RAIN",
AutoCompleteClan {
tag: ClanTag::from("RAIN"),
region: Region::Eu,
},
),
(
"Example: NA RESIN",
AutoCompleteClan {
tag: ClanTag::from("RESIN"),
region: Region::Na,
},
),
("Example: VOR", "[PANTS] (ASIA)"),
("Example: EU RAIN", "[RAIN] (EU)"),
("Example: NA RESIN", "[RESIN] (NA)"),
]
.into_iter()
.map(|(name, value)| {
AutocompleteChoice::new(name.to_string(), serde_json::to_string(&value).unwrap())
})
.map(|(name, value)| AutocompleteChoice::new(name, value))
.collect();
};
let api = WowsApi::new(&ctx);
let candidates = api.clans(&region, clan_name).await.unwrap_or_default();
candidates
.into_iter()
.map(|clan| {
let auto_complete_clan: AutoCompleteClan = clan.clone().into();
AutocompleteChoice::new(
format!("[{}] {} ({})", clan, clan.name, clan.region),
serde_json::to_string(&auto_complete_clan).unwrap(),
)
let formatted_str = format!("[{}] {} ({})", clan, clan.name, clan.region);
AutocompleteChoice::new(formatted_str.clone(), formatted_str)
})
.collect()
}
Expand Down

0 comments on commit 30d0f3e

Please sign in to comment.