mirror of
https://github.com/supleed2/nanobot.git
synced 2025-01-01 19:05:49 +00:00
Add whois commands
TODO: commands are currently exact, add fuzzy finding
This commit is contained in:
parent
82e3eb76c1
commit
eb77798c35
65
src/cmds.rs
65
src/cmds.rs
|
@ -549,3 +549,68 @@ pub(crate) async fn delete_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// Unreachable, used to create whois command folder
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
subcommands("whois_by_id", "whois_by_nickname", "whois_by_realname")
|
||||
)]
|
||||
pub(crate) async fn whois(_ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
/// (Public) Get member info by Discord ID
|
||||
#[poise::command(slash_command, rename = "id")]
|
||||
pub(crate) async fn whois_by_id(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> {
|
||||
println!("Cmd: ({}) whois_by_id {id}", ctx.author().name);
|
||||
match db::get_member_by_id(&ctx.data().db, id.id.into()).await? {
|
||||
Some(m) => {
|
||||
ctx.send(|c| c.content(format!("{id}: {}", m.nickname)).ephemeral(true))
|
||||
.await?
|
||||
}
|
||||
None => ctx.say(format!("No member entry found for {id}")).await?,
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// (Public) Get member info by Nickname (Exact)
|
||||
#[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);
|
||||
// TODO: fuzzy finding
|
||||
match 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?
|
||||
}
|
||||
None => {
|
||||
ctx.say(format!("No member entry found for nickname {nickname}",))
|
||||
.await?
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// (Public) Get member info by Real Name (Exact)
|
||||
#[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);
|
||||
// TODO: fuzzy finding
|
||||
match 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?
|
||||
}
|
||||
None => {
|
||||
ctx.say(format!("No member entry found for realname {realname}",))
|
||||
.await?
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -136,6 +136,7 @@ async fn poise(
|
|||
cmds::get_manual(),
|
||||
cmds::add_manual(),
|
||||
cmds::delete_all_manual(),
|
||||
cmds::whois(),
|
||||
],
|
||||
event_handler: { |c, e, f, d| Box::pin(event_handler(c, e, f, d)) },
|
||||
..Default::default()
|
||||
|
@ -160,7 +161,7 @@ async fn poise(
|
|||
});
|
||||
|
||||
// Return NanoBot
|
||||
Ok(service::NanoBot { router, discord })
|
||||
Ok(service::NanoBot { discord, router })
|
||||
}
|
||||
|
||||
async fn event_handler(
|
||||
|
@ -199,7 +200,7 @@ async fn event_handler(
|
|||
id if id.starts_with("verify-") => verify::manual_4(ctx, m, data, id).await?,
|
||||
_ => {
|
||||
println!("Unknown interaction, printing:\n{m:#?}");
|
||||
verify::unknown(ctx, m).await?
|
||||
verify::unknown(ctx, m).await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue