Add set_members_non_fresher command

Set all members to non-fresher
This commit is contained in:
Aadi Desai 2023-09-26 02:04:31 +01:00
parent eb16506e23
commit 40cd160fa1
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
4 changed files with 36 additions and 0 deletions

View file

@ -0,0 +1,12 @@
{
"db_name": "PostgreSQL",
"query": "update members set fresher='f'",
"describe": {
"columns": [],
"parameters": {
"Left": []
},
"nullable": []
},
"hash": "cec6db96b0061381aa39fc43ab63548b5298f7bf8cb67ed0c11d809dbb5a5fe3"
}

View file

@ -407,6 +407,21 @@ pub(crate) async fn edit_member_fresher(
}
Ok(())
}
/// Set all members to non-freshers
#[poise::command(slash_command)]
pub(crate) async fn set_members_non_fresher(ctx: ACtx<'_>) -> Result<(), Error> {
println!("Cmd: ({}) set_members_non_fresher", ctx.author().name);
let updated = db::set_members_non_fresher(&ctx.data().db).await?;
ctx.say(format!("{updated} updated to non-fresher, removing roles"))
.await?;
for mut m in ctx.data().server.members(ctx.http(), None, None).await? {
let _ = m.remove_role(ctx.http(), ctx.data().fresher).await;
}
ctx.say("Roles removed").await?;
Ok(())
}
/// Get the number of pending members in the pending table
#[poise::command(slash_command)]
pub(crate) async fn count_pending(ctx: ACtx<'_>) -> Result<(), Error> {

View file

@ -241,3 +241,11 @@ pub(crate) async fn edit_member_fresher(
.rows_affected();
Ok(r == 1)
}
/// Set all members to non-freshers
pub(crate) async fn set_members_non_fresher(pool: &sqlx::PgPool) -> Result<u64, Error> {
Ok(sqlx::query!("update members set fresher='f'")
.execute(pool)
.await?
.rows_affected())
}

View file

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