Add edit_member commands

This commit is contained in:
Aadi Desai 2023-09-26 02:03:48 +01:00
parent ef2be84ae0
commit eb16506e23
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
7 changed files with 219 additions and 0 deletions

View file

@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "update members set shortcode=$2 where discord_id=$1",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int8",
"Varchar"
]
},
"nullable": []
},
"hash": "47b151a290d22d28f0a94d133fa9d3f49e4b2e84b963c39d7c7ec11747686b2e"
}

View file

@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "update members set realname=$2 where discord_id=$1",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int8",
"Text"
]
},
"nullable": []
},
"hash": "633c1689a307166ef14a50ba73f39e84b3ef7d85354935afb518a5e27725faf3"
}

View file

@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "update members set fresher=$2 where discord_id=$1",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int8",
"Bool"
]
},
"nullable": []
},
"hash": "a47209085843dc7f53757d6d85566ff613de2bf6f734af92107f0a63ca1fa587"
}

View file

@ -0,0 +1,15 @@
{
"db_name": "PostgreSQL",
"query": "update members set nickname=$2 where discord_id=$1",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Int8",
"Text"
]
},
"nullable": []
},
"hash": "f30cb7ef78972140baa0b542c0845737e7f6843744bcc2fc84b783e1dbb2488c"
}

View file

@ -317,6 +317,96 @@ pub(crate) async fn insert_member_from_manual(
Ok(()) Ok(())
} }
/// Unreachable, used to create edit_member command folder
#[poise::command(
slash_command,
subcommands(
"edit_member_shortcode",
"edit_member_nickname",
"edit_member_realname",
"edit_member_fresher",
)
)]
pub(crate) async fn edit_member(_ctx: ACtx<'_>) -> Result<(), Error> {
unreachable!()
}
/// Edit member Shortcode
#[poise::command(slash_command, rename = "shortcode")]
pub(crate) async fn edit_member_shortcode(
ctx: ACtx<'_>,
id: serenity::Member,
shortcode: String,
) -> Result<(), Error> {
println!(
"Cmd: ({}) edit_member_shortcode {shortcode}",
ctx.author().name
);
if db::edit_member_shortcode(&ctx.data().db, id.user.id.into(), &shortcode).await? {
ctx.say(format!("{id} Shortcode updated to {shortcode}"))
.await?;
} else {
ctx.say(format!("Failed to update Shortcode for {id}"))
.await?;
}
Ok(())
}
/// Edit member Nickname
#[poise::command(slash_command, rename = "nick")]
pub(crate) async fn edit_member_nickname(
ctx: ACtx<'_>,
id: serenity::Member,
nickname: String,
) -> Result<(), Error> {
println!(
"Cmd: ({}) edit_member_nickname {nickname}",
ctx.author().name
);
if db::edit_member_nickname(&ctx.data().db, id.user.id.into(), &nickname).await? {
ctx.say(format!("{id} Nick updated to {nickname}")).await?;
} else {
ctx.say(format!("Failed to update Nick for {id}")).await?;
}
Ok(())
}
/// Edit member Real Name
#[poise::command(slash_command, rename = "name")]
pub(crate) async fn edit_member_realname(
ctx: ACtx<'_>,
id: serenity::Member,
realname: String,
) -> Result<(), Error> {
println!(
"Cmd: ({}) edit_member_realname {realname}",
ctx.author().name
);
if db::edit_member_realname(&ctx.data().db, id.user.id.into(), &realname).await? {
ctx.say(format!("{id} Name updated to {realname}")).await?;
} else {
ctx.say(format!("Failed to update Name for {id}")).await?;
}
Ok(())
}
/// Edit member fresher status
#[poise::command(slash_command, rename = "fresher")]
pub(crate) async fn edit_member_fresher(
ctx: ACtx<'_>,
id: serenity::Member,
fresher: bool,
) -> Result<(), Error> {
println!("Cmd: ({}) edit_member_fresher {fresher}", ctx.author().name);
if db::edit_member_fresher(&ctx.data().db, id.user.id.into(), fresher).await? {
ctx.say(format!("{id} Fresher status updated to {fresher}"))
.await?;
} else {
ctx.say(format!("Failed to update Fresher status for {id}"))
.await?;
}
Ok(())
}
/// Get the number of pending members in the pending table /// Get the number of pending members in the pending table
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub(crate) async fn count_pending(ctx: ACtx<'_>) -> Result<(), Error> { pub(crate) async fn count_pending(ctx: ACtx<'_>) -> Result<(), Error> {

View file

@ -173,3 +173,71 @@ pub(crate) async fn insert_member_from_manual(pool: &sqlx::PgPool, id: i64) -> R
.await?; .await?;
Ok(()) Ok(())
} }
/// Edit member shortcode field
pub(crate) async fn edit_member_shortcode(
pool: &sqlx::PgPool,
id: i64,
shortcode: &str,
) -> Result<bool, Error> {
let r = sqlx::query!(
"update members set shortcode=$2 where discord_id=$1",
id,
shortcode
)
.execute(pool)
.await?
.rows_affected();
Ok(r == 1)
}
/// Edit member nickname field
pub(crate) async fn edit_member_nickname(
pool: &sqlx::PgPool,
id: i64,
nickname: &str,
) -> Result<bool, Error> {
let r = sqlx::query!(
"update members set nickname=$2 where discord_id=$1",
id,
nickname
)
.execute(pool)
.await?
.rows_affected();
Ok(r == 1)
}
/// Edit member realname field
pub(crate) async fn edit_member_realname(
pool: &sqlx::PgPool,
id: i64,
realname: &str,
) -> Result<bool, Error> {
let r = sqlx::query!(
"update members set realname=$2 where discord_id=$1",
id,
realname
)
.execute(pool)
.await?
.rows_affected();
Ok(r == 1)
}
/// Edit member fresher field
pub(crate) async fn edit_member_fresher(
pool: &sqlx::PgPool,
id: i64,
fresher: bool,
) -> Result<bool, Error> {
let r = sqlx::query!(
"update members set fresher=$2 where discord_id=$1",
id,
fresher
)
.execute(pool)
.await?
.rows_affected();
Ok(r == 1)
}

View file

@ -121,6 +121,7 @@ async fn poise(
cmds::add_member(), cmds::add_member(),
cmds::insert_member_from_pending(), cmds::insert_member_from_pending(),
cmds::insert_member_from_manual(), cmds::insert_member_from_manual(),
cmds::edit_member(),
cmds::count_pending(), cmds::count_pending(),
cmds::delete_pending(), cmds::delete_pending(),
cmds::get_all_pending(), cmds::get_all_pending(),