Skip to content

Commit

Permalink
imrpovement in player autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
B-2U committed Jul 19, 2024
1 parent 7b49cc3 commit 38afad4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/cmds/setting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ pub async fn link(
#[description = "your game server & ign"]
player: String, // the String is a Serialized PartialPlayer struct
) -> Result<(), Error> {
let api = WowsApi::new(&ctx);
let partial_player = {
let (region, ign) = parse_region_ign(&player)?;
cache_methods::player(WowsApi::new(&ctx), &region, &ign).await?
cache_methods::player(&api, &region, &ign).await?
};
let api = WowsApi::new(&ctx);
let player = partial_player.full_player(&api).await?;
{
let mut guard = ctx.data().link.write().await;
Expand Down
2 changes: 1 addition & 1 deletion src/dc_utils/auto_complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub async fn player(ctx: Context<'_>, input: &str) -> Vec<AutocompleteChoice> {
candidates
.into_iter()
.map(|vortex_p| {
let output = format!("[{}] {}", region, vortex_p.name);
let output = format!("{} ({})", vortex_p.name, region);
AutocompleteChoice::new(output.clone(), output)
})
.collect()
Expand Down
2 changes: 1 addition & 1 deletion src/utils/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
/// # Error
/// [`IsacInfo::GeneralError`] if received a malformed input
pub fn parse_region_ign(input: &str) -> Result<(Region, String), IsacError> {
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"\[?(\w+)\]?\s+(\w+)").unwrap());
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"(\w+)\s+\((\w+)\)").unwrap());
let (_, [region_str, ign]) = RE
.captures(input)
.ok_or(IsacInfo::GeneralError {
Expand Down

0 comments on commit 38afad4

Please sign in to comment.