mirror of
https://github.com/supleed2/nanobot.git
synced 2024-12-22 06:05:50 +00:00
Add edit_member
commands
This commit is contained in:
parent
ef2be84ae0
commit
eb16506e23
|
@ -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"
|
||||
}
|
|
@ -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"
|
||||
}
|
|
@ -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"
|
||||
}
|
|
@ -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"
|
||||
}
|
90
src/cmds.rs
90
src/cmds.rs
|
@ -317,6 +317,96 @@ pub(crate) async fn insert_member_from_manual(
|
|||
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
|
||||
#[poise::command(slash_command)]
|
||||
pub(crate) async fn count_pending(ctx: ACtx<'_>) -> Result<(), Error> {
|
||||
|
|
|
@ -173,3 +173,71 @@ pub(crate) async fn insert_member_from_manual(pool: &sqlx::PgPool, id: i64) -> R
|
|||
.await?;
|
||||
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)
|
||||
}
|
||||
|
|
|
@ -121,6 +121,7 @@ async fn poise(
|
|||
cmds::add_member(),
|
||||
cmds::insert_member_from_pending(),
|
||||
cmds::insert_member_from_manual(),
|
||||
cmds::edit_member(),
|
||||
cmds::count_pending(),
|
||||
cmds::delete_pending(),
|
||||
cmds::get_all_pending(),
|
||||
|
|
Loading…
Reference in a new issue