remove mod_role and fix some weird type errors?

This commit is contained in:
Tanner Sommers 2024-11-25 19:42:05 -06:00
parent eab02cd2c2
commit 95089e8a59
3 changed files with 25 additions and 57 deletions

View File

@ -55,8 +55,7 @@ pub async fn submit(
// Send a messasge to the mod-logs channel with a ping that a new vouch has been submitted // Send a messasge to the mod-logs channel with a ping that a new vouch has been submitted
let log_msg = format!( let log_msg = format!(
"{} {}\n:notepad_spiral: A new vouch has been submitted for {} by {}, please either approve or deny this vouch.", "{}\n:notepad_spiral: A new vouch has been submitted for {} by {}, please either approve or deny this vouch.",
serenity::model::id::RoleId::new(ctx.data().config.roles.mod_role).mention(),
serenity::model::id::RoleId::new(ctx.data().config.roles.admin).mention(), serenity::model::id::RoleId::new(ctx.data().config.roles.admin).mention(),
user.clone().mention(), user.clone().mention(),
ctx.author().mention() ctx.author().mention()
@ -70,10 +69,7 @@ pub async fn submit(
.send_message( .send_message(
ctx.serenity_context(), ctx.serenity_context(),
CreateMessage::new().content(log_msg).allowed_mentions( CreateMessage::new().content(log_msg).allowed_mentions(
CreateAllowedMentions::new().roles(vec![ CreateAllowedMentions::new().roles(vec![ctx.data().config.roles.admin]),
ctx.data().config.roles.mod_role,
ctx.data().config.roles.admin,
]),
), ),
) )
.await?; .await?;
@ -98,10 +94,11 @@ pub async fn approve(
match author_user { match author_user {
Some(author_user) => { Some(author_user) => {
// Check if the author is an admin // Check if the author is an admin
if !author_user.roles.iter().any(|role_id| { if !author_user
*role_id == ctx.data().config.roles.admin .roles
|| *role_id == ctx.data().config.roles.mod_role .iter()
}) { .any(|role_id| *role_id == ctx.data().config.roles.admin)
{
ctx.say(":x: You must be an admin to approve vouches!") ctx.say(":x: You must be an admin to approve vouches!")
.await?; .await?;
return Ok(()); return Ok(());
@ -207,10 +204,11 @@ pub async fn deny(
match author_user { match author_user {
Some(author_user) => { Some(author_user) => {
// Check if the author is an admin // Check if the author is an admin
if !author_user.roles.iter().any(|role_id| { if !author_user
*role_id == ctx.data().config.roles.admin .roles
|| *role_id == ctx.data().config.roles.mod_role .iter()
}) { .any(|role_id| *role_id == ctx.data().config.roles.admin)
{
ctx.say(":x: You must be an admin to deny vouches!").await?; ctx.say(":x: You must be an admin to deny vouches!").await?;
return Ok(()); return Ok(());
} }

View File

@ -34,26 +34,6 @@ impl DatabaseController {
} }
} }
async fn get_user_by_id(&self, id: u64) -> Result<Option<User>, sqlx::Error> {
let user = sqlx::query!("SELECT * FROM users WHERE id = ?", id)
.fetch_optional(&self.db)
.await?;
match user {
Some(user) => Ok(Some(User {
id: user.id,
discord_id: user
.discord_id
.parse::<u64>()
.map_err(|_| sqlx::Error::Decode("Failed to parse discord_id".into()))?,
actions_allowed: user.actions_allowed == Some(1),
about: user.about,
pronouns: user.pronouns,
})),
None => Ok(None),
}
}
pub async fn create_user(&self, discord_id: u64) -> Result<User, sqlx::Error> { pub async fn create_user(&self, discord_id: u64) -> Result<User, sqlx::Error> {
let user = sqlx::query!( let user = sqlx::query!(
"INSERT INTO users (discord_id) VALUES (?)", "INSERT INTO users (discord_id) VALUES (?)",
@ -85,14 +65,6 @@ impl DatabaseController {
Ok(()) Ok(())
} }
pub async fn delete_user(&self, user: User) -> Result<(), sqlx::Error> {
sqlx::query!("DELETE FROM users WHERE id = ?", user.id)
.execute(&self.db)
.await?;
Ok(())
}
pub async fn delete_user_by_discord_id(&self, discord_id: u64) -> Result<(), sqlx::Error> { pub async fn delete_user_by_discord_id(&self, discord_id: u64) -> Result<(), sqlx::Error> {
sqlx::query!("DELETE FROM users WHERE discord_id = ?", discord_id) sqlx::query!("DELETE FROM users WHERE discord_id = ?", discord_id)
.execute(&self.db) .execute(&self.db)
@ -140,20 +112,20 @@ impl DatabaseController {
} }
pub async fn quote_get_random(&self) -> Result<Option<Quote>, sqlx::Error> { pub async fn quote_get_random(&self) -> Result<Option<Quote>, sqlx::Error> {
let quote = sqlx::query!("SELECT * FROM quotes ORDER BY RAND() LIMIT 1") let quote =
.fetch_optional(&self.db) sqlx::query!("SELECT * FROM quotes ORDER BY RAND() LIMIT 1").fetch_one(&self.db);
.await?;
match quote { match quote.await {
Some(quote) => Ok(Some(Quote { Ok(q) => Ok(Some(Quote {
quote_id: quote.quote_id, quote_id: q.quote_id,
user_id: quote.user_id, user_id: q.user_id,
username: quote.username, username: q.username,
quote: quote.quote, quote: q.quote,
added_by: quote.added_by, added_by: q.added_by,
added_at: Some(quote.added_at), added_at: q.added_at,
})), })),
None => Ok(None), Err(sqlx::Error::RowNotFound) => Ok(None),
Err(e) => Err(e),
} }
} }
@ -170,7 +142,7 @@ impl DatabaseController {
username: q.username, username: q.username,
quote: q.quote, quote: q.quote,
added_by: q.added_by, added_by: q.added_by,
added_at: Some(q.added_at), added_at: q.added_at,
}); });
} }

View File

@ -108,7 +108,6 @@ struct Channels {
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
struct Roles { struct Roles {
admin: u64, admin: u64,
mod_role: u64,
silly_role: u64, silly_role: u64,
} }
@ -144,7 +143,6 @@ async fn main() {
}, },
roles: Roles { roles: Roles {
admin: 0, admin: 0,
mod_role: 0,
silly_role: 0, silly_role: 0,
}, },
}; };