add custom role management

This commit is contained in:
2024-12-08 01:08:33 -05:00
parent b0ec64171f
commit f4a06a7b17
11 changed files with 250 additions and 3 deletions

View File

@@ -0,0 +1,37 @@
use crate::common::{Context, Error};
use sqlx::{PgConnection, Row};
use poise::serenity_prelude::{RoleId, UserId, GuildId};
mod register;
mod whois;
mod color;
mod name;
mod disown;
#[poise::command(
prefix_command,
slash_command,
subcommands(
"register::register",
"whois::whois",
"color::color",
"name::name",
"disown::disown",
)
)]
pub async fn role(_ctx: Context<'_>) -> Result<(), Error> {
Ok(())
}
pub async fn get_user_role(_ctx: Context<'_>, user: UserId, guild: GuildId, db: &mut PgConnection) -> Result<Option<RoleId>, Error> {
match sqlx::query("SELECT roleid FROM selfroles WHERE userid = $1 AND guildid = $2")
.bind(user.get() as i64)
.bind(guild.get() as i64)
.fetch_one(db).await
{
Ok(row) => Ok(Some(RoleId::new(row.try_get::<i64, usize>(0)? as u64))),
Err(sqlx::Error::RowNotFound) => Ok(None),
Err(e) => return Err(Box::new(e)),
}
}