More clippy::pedantic lints

Use `if let` rather than unnecessary match
This commit is contained in:
Aadi Desai 2023-09-25 23:07:22 +01:00
parent 83db8eb08f
commit ef2be84ae0
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM

View file

@ -614,34 +614,31 @@ pub(crate) async fn whois_by_id(ctx: ACtx<'_>, id: serenity::User) -> Result<(),
#[poise::command(slash_command, rename = "nick")] #[poise::command(slash_command, rename = "nick")]
pub(crate) async fn whois_by_nickname(ctx: ACtx<'_>, nickname: String) -> Result<(), Error> { pub(crate) async fn whois_by_nickname(ctx: ACtx<'_>, nickname: String) -> Result<(), Error> {
println!("Cmd: ({}) whois_by_nickname {nickname}", ctx.author().name); println!("Cmd: ({}) whois_by_nickname {nickname}", ctx.author().name);
match db::get_member_by_nickname(&ctx.data().db, &nickname).await? { if let Some(m) = db::get_member_by_nickname(&ctx.data().db, &nickname).await? {
Some(m) => { ctx.send(|c| {
c.content(format!("{nickname}: <@{}>", m.discord_id))
.ephemeral(true)
})
.await?;
} else {
let members = db::get_member_by_nickname_fuzzy(&ctx.data().db, &nickname, 3).await?;
if members.is_empty() {
ctx.send(|c| { ctx.send(|c| {
c.content(format!("{nickname}: <@{}>", m.discord_id)) c.content(format!("No member entry found for nickname {nickname}"))
.ephemeral(true) .ephemeral(true)
}) })
.await?; .await?;
} } else {
None => { ctx.send(|c| {
let members = db::get_member_by_nickname_fuzzy(&ctx.data().db, &nickname, 3).await?; c.ephemeral(true).content(format!(
if members.is_empty() { "Possible matches for {nickname}: {}",
ctx.send(|c| { members
c.content(format!("No member entry found for nickname {nickname}")) .iter()
.ephemeral(true) .map(|m| format!(" <@{}>", m.discord_id))
}) .collect::<String>()
.await?; ))
} else { })
ctx.send(|c| { .await?;
c.ephemeral(true).content(format!(
"Possible matches for {nickname}: {}",
members
.iter()
.map(|m| format!(" <@{}>", m.discord_id))
.collect::<String>()
))
})
.await?;
}
} }
} }
Ok(()) Ok(())
@ -651,34 +648,31 @@ pub(crate) async fn whois_by_nickname(ctx: ACtx<'_>, nickname: String) -> Result
#[poise::command(slash_command, rename = "name")] #[poise::command(slash_command, rename = "name")]
pub(crate) async fn whois_by_realname(ctx: ACtx<'_>, realname: String) -> Result<(), Error> { pub(crate) async fn whois_by_realname(ctx: ACtx<'_>, realname: String) -> Result<(), Error> {
println!("Cmd: ({}) whois_by_realname {realname}", ctx.author().name); println!("Cmd: ({}) whois_by_realname {realname}", ctx.author().name);
match db::get_member_by_realname(&ctx.data().db, &realname).await? { if let Some(m) = db::get_member_by_realname(&ctx.data().db, &realname).await? {
Some(m) => { ctx.send(|c| {
c.content(format!("{realname}: <@{}>", m.discord_id))
.ephemeral(true)
})
.await?;
} else {
let members = db::get_member_by_realname_fuzzy(&ctx.data().db, &realname, 3).await?;
if members.is_empty() {
ctx.send(|c| { ctx.send(|c| {
c.content(format!("{realname}: <@{}>", m.discord_id)) c.content(format!("No member entry found for realname {realname}"))
.ephemeral(true) .ephemeral(true)
}) })
.await?; .await?;
} } else {
None => { ctx.send(|c| {
let members = db::get_member_by_realname_fuzzy(&ctx.data().db, &realname, 3).await?; c.ephemeral(true).content(format!(
if members.is_empty() { "Possible matches for {realname}: {}",
ctx.send(|c| { members
c.content(format!("No member entry found for realname {realname}")) .iter()
.ephemeral(true) .map(|m| format!(" <@{}>", m.discord_id))
}) .collect::<String>()
.await?; ))
} else { })
ctx.send(|c| { .await?;
c.ephemeral(true).content(format!(
"Possible matches for {realname}: {}",
members
.iter()
.map(|m| format!(" <@{}>", m.discord_id))
.collect::<String>()
))
})
.await?;
}
} }
}; };
Ok(()) Ok(())