Switch all cmds to use Member instead of User

This commit is contained in:
Aadi Desai 2023-09-26 02:05:12 +01:00
parent 40cd160fa1
commit c3f9ba6626
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM

View file

@ -163,9 +163,9 @@ pub(crate) async fn get_member(_ctx: ACtx<'_>) -> Result<(), Error> {
/// Get member info by Discord ID /// Get member info by Discord ID
#[poise::command(slash_command, rename = "id")] #[poise::command(slash_command, rename = "id")]
pub(crate) async fn get_member_by_id(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> { pub(crate) async fn get_member_by_id(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> {
println!("Cmd: ({}) get_member_by_id {id}", ctx.author().name); println!("Cmd: ({}) get_member_by_id {id}", ctx.author().name);
match db::get_member_by_id(&ctx.data().db, id.id.into()).await? { match db::get_member_by_id(&ctx.data().db, id.user.id.into()).await? {
Some(m) => { Some(m) => {
ctx.say(format!("Member info for {id}:\n```rust\n{m:#?}\n```")) ctx.say(format!("Member info for {id}:\n```rust\n{m:#?}\n```"))
.await? .await?
@ -279,7 +279,7 @@ pub(crate) async fn add_member(
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn insert_member_from_pending( pub(crate) async fn insert_member_from_pending(
ctx: ACtx<'_>, ctx: ACtx<'_>,
id: serenity::User, id: serenity::Member,
nickname: String, nickname: String,
fresher: bool, fresher: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
@ -287,7 +287,9 @@ pub(crate) async fn insert_member_from_pending(
"Cmd: ({}) insert_member_from_pending {id}", "Cmd: ({}) insert_member_from_pending {id}",
ctx.author().name ctx.author().name
); );
match db::insert_member_from_pending(&ctx.data().db, id.id.into(), &nickname, fresher).await { match db::insert_member_from_pending(&ctx.data().db, id.user.id.into(), &nickname, fresher)
.await
{
Ok(()) => { Ok(()) => {
ctx.say(format!("Member moved from pending to members table: {id}")) ctx.say(format!("Member moved from pending to members table: {id}"))
.await? .await?
@ -301,13 +303,13 @@ pub(crate) async fn insert_member_from_pending(
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn insert_member_from_manual( pub(crate) async fn insert_member_from_manual(
ctx: ACtx<'_>, ctx: ACtx<'_>,
id: serenity::User, id: serenity::Member,
) -> Result<(), Error> { ) -> Result<(), Error> {
println!( println!(
"Cmd: ({}) insert_member_from_manual {id}", "Cmd: ({}) insert_member_from_manual {id}",
ctx.author().name ctx.author().name
); );
match db::insert_member_from_manual(&ctx.data().db, id.id.into()).await { match db::insert_member_from_manual(&ctx.data().db, id.user.id.into()).await {
Ok(()) => { Ok(()) => {
ctx.say(format!("Member moved from manual to members table: {id}")) ctx.say(format!("Member moved from manual to members table: {id}"))
.await? .await?
@ -434,9 +436,9 @@ pub(crate) async fn count_pending(ctx: ACtx<'_>) -> Result<(), Error> {
/// Delete pending member info by Discord ID /// Delete pending member info by Discord ID
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn delete_pending(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> { pub(crate) async fn delete_pending(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> {
println!("Cmd: ({}) delete_pending {id}", ctx.author().name); println!("Cmd: ({}) delete_pending {id}", ctx.author().name);
if db::delete_pending_by_id(&ctx.data().db, id.id.into()).await? { if db::delete_pending_by_id(&ctx.data().db, id.user.id.into()).await? {
ctx.say(format!("Successfully deleted pending member info for {id}")) ctx.say(format!("Successfully deleted pending member info for {id}"))
.await? .await?
} else { } else {
@ -490,9 +492,9 @@ pub(crate) async fn get_all_pending(ctx: ACtx<'_>) -> Result<(), Error> {
/// Get pending member info by Discord ID /// Get pending member info by Discord ID
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn get_pending(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> { pub(crate) async fn get_pending(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> {
println!("Cmd: ({}) get_pending {id}", ctx.author().name); println!("Cmd: ({}) get_pending {id}", ctx.author().name);
match db::get_pending_by_id(&ctx.data().db, id.id.into()).await? { match db::get_pending_by_id(&ctx.data().db, id.user.id.into()).await? {
Some(p) => { Some(p) => {
ctx.say(format!("Pending info for {id}:\n```rust\n{p:#?}\n```")) ctx.say(format!("Pending info for {id}:\n```rust\n{p:#?}\n```"))
.await? .await?
@ -506,7 +508,7 @@ pub(crate) async fn get_pending(ctx: ACtx<'_>, id: serenity::User) -> Result<(),
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn add_pending( pub(crate) async fn add_pending(
ctx: ACtx<'_>, ctx: ACtx<'_>,
id: serenity::User, id: serenity::Member,
shortcode: String, shortcode: String,
realname: String, realname: String,
) -> Result<(), Error> { ) -> Result<(), Error> {
@ -517,7 +519,7 @@ pub(crate) async fn add_pending(
db::insert_pending( db::insert_pending(
&ctx.data().db, &ctx.data().db,
PendingMember { PendingMember {
discord_id: id.id.into(), discord_id: id.user.id.into(),
shortcode, shortcode,
realname, realname,
}, },
@ -567,9 +569,9 @@ pub(crate) async fn count_manual(ctx: ACtx<'_>) -> Result<(), Error> {
/// Delete manual member info by Discord ID /// Delete manual member info by Discord ID
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn delete_manual(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> { pub(crate) async fn delete_manual(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> {
println!("Cmd: ({}) delete_manual {id}", ctx.author().name); println!("Cmd: ({}) delete_manual {id}", ctx.author().name);
if db::delete_manual_by_id(&ctx.data().db, id.id.into()).await? { if db::delete_manual_by_id(&ctx.data().db, id.user.id.into()).await? {
ctx.say(format!("Successfully deleted manual member info for {id}")) ctx.say(format!("Successfully deleted manual member info for {id}"))
.await? .await?
} else { } else {
@ -623,9 +625,9 @@ pub(crate) async fn get_all_manual(ctx: ACtx<'_>) -> Result<(), Error> {
/// Get manual member info by Discord ID /// Get manual member info by Discord ID
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn get_manual(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> { pub(crate) async fn get_manual(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> {
println!("Cmd: ({}) get_manual {id}", ctx.author().name); println!("Cmd: ({}) get_manual {id}", ctx.author().name);
match db::get_manual_by_id(&ctx.data().db, id.id.into()).await? { match db::get_manual_by_id(&ctx.data().db, id.user.id.into()).await? {
Some(m) => { Some(m) => {
ctx.say(format!("Manual info for {id}:\n```rust\n{m:#?}\n```")) ctx.say(format!("Manual info for {id}:\n```rust\n{m:#?}\n```"))
.await? .await?
@ -639,7 +641,7 @@ pub(crate) async fn get_manual(ctx: ACtx<'_>, id: serenity::User) -> Result<(),
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn add_manual( pub(crate) async fn add_manual(
ctx: ACtx<'_>, ctx: ACtx<'_>,
id: serenity::User, id: serenity::Member,
shortcode: String, shortcode: String,
nickname: String, nickname: String,
realname: String, realname: String,
@ -652,7 +654,7 @@ pub(crate) async fn add_manual(
db::insert_manual( db::insert_manual(
&ctx.data().db, &ctx.data().db,
ManualMember { ManualMember {
discord_id: id.id.into(), discord_id: id.user.id.into(),
shortcode, shortcode,
nickname, nickname,
realname, realname,
@ -703,9 +705,9 @@ pub(crate) async fn whois(_ctx: ACtx<'_>) -> Result<(), Error> {
/// (Public) Get member info by Discord ID /// (Public) Get member info by Discord ID
#[poise::command(slash_command, rename = "id")] #[poise::command(slash_command, rename = "id")]
pub(crate) async fn whois_by_id(ctx: ACtx<'_>, id: serenity::User) -> Result<(), Error> { pub(crate) async fn whois_by_id(ctx: ACtx<'_>, id: serenity::Member) -> Result<(), Error> {
println!("Cmd: ({}) whois_by_id {id}", ctx.author().name); println!("Cmd: ({}) whois_by_id {id}", ctx.author().name);
match db::get_member_by_id(&ctx.data().db, id.id.into()).await? { match db::get_member_by_id(&ctx.data().db, id.user.id.into()).await? {
Some(m) => { Some(m) => {
ctx.send(|c| c.content(format!("{id}: {}", m.nickname)).ephemeral(true)) ctx.send(|c| c.content(format!("{id}: {}", m.nickname)).ephemeral(true))
.await? .await?