diff --git a/src/commands/vouch.rs b/src/commands/vouch.rs index b6e015c..629d77a 100644 --- a/src/commands/vouch.rs +++ b/src/commands/vouch.rs @@ -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 let log_msg = format!( - "{} {}\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(), + "{}\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.admin).mention(), user.clone().mention(), ctx.author().mention() @@ -70,10 +69,7 @@ pub async fn submit( .send_message( ctx.serenity_context(), CreateMessage::new().content(log_msg).allowed_mentions( - CreateAllowedMentions::new().roles(vec![ - ctx.data().config.roles.mod_role, - ctx.data().config.roles.admin, - ]), + CreateAllowedMentions::new().roles(vec![ctx.data().config.roles.admin]), ), ) .await?; @@ -98,10 +94,11 @@ pub async fn approve( match author_user { Some(author_user) => { // Check if the author is an admin - if !author_user.roles.iter().any(|role_id| { - *role_id == ctx.data().config.roles.admin - || *role_id == ctx.data().config.roles.mod_role - }) { + if !author_user + .roles + .iter() + .any(|role_id| *role_id == ctx.data().config.roles.admin) + { ctx.say(":x: You must be an admin to approve vouches!") .await?; return Ok(()); @@ -207,10 +204,11 @@ pub async fn deny( match author_user { Some(author_user) => { // Check if the author is an admin - if !author_user.roles.iter().any(|role_id| { - *role_id == ctx.data().config.roles.admin - || *role_id == ctx.data().config.roles.mod_role - }) { + if !author_user + .roles + .iter() + .any(|role_id| *role_id == ctx.data().config.roles.admin) + { ctx.say(":x: You must be an admin to deny vouches!").await?; return Ok(()); } diff --git a/src/handlers/db.rs b/src/handlers/db.rs index 82d63ec..22c21fb 100644 --- a/src/handlers/db.rs +++ b/src/handlers/db.rs @@ -34,26 +34,6 @@ impl DatabaseController { } } - async fn get_user_by_id(&self, id: u64) -> Result, 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::() - .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 { let user = sqlx::query!( "INSERT INTO users (discord_id) VALUES (?)", @@ -85,14 +65,6 @@ impl DatabaseController { 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> { sqlx::query!("DELETE FROM users WHERE discord_id = ?", discord_id) .execute(&self.db) @@ -140,20 +112,20 @@ impl DatabaseController { } pub async fn quote_get_random(&self) -> Result, sqlx::Error> { - let quote = sqlx::query!("SELECT * FROM quotes ORDER BY RAND() LIMIT 1") - .fetch_optional(&self.db) - .await?; + let quote = + sqlx::query!("SELECT * FROM quotes ORDER BY RAND() LIMIT 1").fetch_one(&self.db); - match quote { - Some(quote) => Ok(Some(Quote { - quote_id: quote.quote_id, - user_id: quote.user_id, - username: quote.username, - quote: quote.quote, - added_by: quote.added_by, - added_at: Some(quote.added_at), + match quote.await { + Ok(q) => Ok(Some(Quote { + quote_id: q.quote_id, + user_id: q.user_id, + username: q.username, + quote: q.quote, + added_by: q.added_by, + 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, quote: q.quote, added_by: q.added_by, - added_at: Some(q.added_at), + added_at: q.added_at, }); } diff --git a/src/main.rs b/src/main.rs index f4cc8d9..ac15d7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -108,7 +108,6 @@ struct Channels { #[derive(Deserialize, Serialize)] struct Roles { admin: u64, - mod_role: u64, silly_role: u64, } @@ -144,7 +143,6 @@ async fn main() { }, roles: Roles { admin: 0, - mod_role: 0, silly_role: 0, }, };