From 8496e4daac26b049c91e956c93b50fd296626b8a Mon Sep 17 00:00:00 2001 From: katsumi143 <32640219+katsumi143@users.noreply.github.com> Date: Thu, 7 Dec 2023 14:37:57 +1000 Subject: [PATCH] improve code --- mellow/src/commands/syncing.rs | 2 +- mellow/src/discord.rs | 2 +- mellow/src/interaction.rs | 2 +- mellow/src/syncing.rs | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mellow/src/commands/syncing.rs b/mellow/src/commands/syncing.rs index 2a1203c..aeddd8c 100644 --- a/mellow/src/commands/syncing.rs +++ b/mellow/src/commands/syncing.rs @@ -59,7 +59,7 @@ pub async fn sync_with_token(user: UserResponse, member: DiscordMember, guild_id pub async fn sync(interaction: InteractionPayload) -> SlashResponse { let guild_id = interaction.guild_id.clone().unwrap(); let member = interaction.member.unwrap(); - if let Some(user) = get_users_by_discord(vec![member.user.id.clone()], guild_id.clone()).await.into_iter().nth(0) { + if let Some(user) = get_users_by_discord(vec![member.user.id.clone()], guild_id.clone()).await.into_iter().next() { tokio::spawn(async move { sync_with_token(user, member, &guild_id, &interaction.token).await; }); diff --git a/mellow/src/discord.rs b/mellow/src/discord.rs index 52dd671..0761c23 100644 --- a/mellow/src/discord.rs +++ b/mellow/src/discord.rs @@ -17,7 +17,7 @@ static CLIENT: Lazy = Lazy::new(|| ); pub async fn edit_original_response(token: impl Into, payload: InteractionResponseData) { - CLIENT.patch(format!("https://discord.com/api/v10/webhooks/{}/{}/messages/@original", APP_ID.to_string(), token.into())) + CLIENT.patch(format!("https://discord.com/api/v10/webhooks/{}/{}/messages/@original", APP_ID, token.into())) .body(serde_json::to_string(&payload).unwrap()) .header("content-type", "application/json") .send() diff --git a/mellow/src/interaction.rs b/mellow/src/interaction.rs index 061f50f..84e33d3 100644 --- a/mellow/src/interaction.rs +++ b/mellow/src/interaction.rs @@ -179,7 +179,7 @@ fn parse_body(body: String, signature: &str, timestamp: &str) -> String { .unwrap(); public_key.verify( format!("{}{}", timestamp, body).as_bytes(), - &hex::decode(&signature) + &hex::decode(signature) .map(|vec| Signature::from_bytes(&vec.try_into().unwrap())) .unwrap() ).unwrap(); diff --git a/mellow/src/syncing.rs b/mellow/src/syncing.rs index 3f70ec4..ca24bb1 100644 --- a/mellow/src/syncing.rs +++ b/mellow/src/syncing.rs @@ -44,7 +44,7 @@ pub struct ConnectionMetadata { pub roblox_memberships: Vec } -pub async fn get_connection_metadata(users: &Vec, server: &Server) -> ConnectionMetadata { +pub async fn get_connection_metadata(users: &[UserResponse], server: &Server) -> ConnectionMetadata { let mut roblox_memberships: Vec = vec![]; let mut group_ids: Vec = vec![]; for action in server.actions.iter() { @@ -95,7 +95,7 @@ pub async fn sync_member(user: Option<&User>, member: &DiscordMember, server: &S let met = member_meets_action_requirements(user, action, &actions2, &connection_metadata, &mut requirement_cache, &mut used_connections).await; match action.kind { ProfileSyncActionKind::GiveRoles => { - let items: Vec = action.metadata["items"].as_array().unwrap().into_iter().map(|x| x.as_str().unwrap().to_string()).collect(); + let items: Vec = action.metadata["items"].as_array().unwrap().iter().map(|x| x.as_str().unwrap().to_string()).collect(); if met { if !items.iter().all(|x| member.roles.iter().any(|e| e == x)) { let filtered: Vec = items.into_iter().filter(|x| !member.roles.iter().any(|e| e == x)).collect(); @@ -235,7 +235,7 @@ pub async fn create_sign_up(user_id: String, guild_id: String, interaction_token pub async fn finish_sign_up(discord_id: String) { if let Some(item) = SIGN_UPS.read().await.iter().find(|x| x.user_id == discord_id) { if SystemTime::now().duration_since(item.created_at).unwrap().as_secs() < 891 { - if let Some(user) = get_users_by_discord(vec![discord_id.clone()], item.guild_id.clone()).await.into_iter().nth(0) { + if let Some(user) = get_users_by_discord(vec![discord_id.clone()], item.guild_id.clone()).await.into_iter().next() { let member = get_member(&item.guild_id, &discord_id).await; commands::syncing::sync_with_token(user, member, &item.guild_id, &item.interaction_token).await; }