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