new role management commands, bug fix, table restructuring, better output

This commit is contained in:
2024-12-08 12:15:54 -05:00
parent 8f764a2270
commit 0def108010
10 changed files with 97 additions and 35 deletions

View File

@@ -0,0 +1,39 @@
use crate::common::{self, Context, Error};
use poise::serenity_prelude as serenity;
/// force remove someone's role (this does not delete the role)
#[poise::command(slash_command, prefix_command, required_permissions = "MANAGE_ROLES")]
pub async fn remove(ctx: Context<'_>, user: serenity::User) -> Result<(), Error> {
let data = ctx.data();
let mut db = data.database.lock().await;
let db = db.as_mut();
if let Some(guild) = ctx.guild_id() {
match super::get_user_role(user.id, guild, db).await? {
Some(role) => {
sqlx::query("DELETE FROM selfroles WHERE userid = $1 AND guildid = $2")
.bind(user.id.get() as i64)
.bind(guild.get() as i64)
.execute(db).await?;
let member = guild.member(ctx, user.id).await?;
member.remove_role(ctx, role).await?;
let role = guild.role(ctx, role).await?;
common::no_ping_reply(&ctx, format!("{} has had {} removed.", user, role)).await?;
Ok(())
},
None => {
common::no_ping_reply(&ctx, format!("{} does not have a personal role to remove.", user)).await?;
Ok(())
}
}
} else {
ctx.reply("This command can only be run in a guild!").await?;
Ok(())
}
}