Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
katsumi143 committed Dec 7, 2023
1 parent 3cf4c7c commit 8496e4d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion mellow/src/commands/syncing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
2 changes: 1 addition & 1 deletion mellow/src/discord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ static CLIENT: Lazy<Client> = Lazy::new(||
);

pub async fn edit_original_response(token: impl Into<String>, 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()
Expand Down
2 changes: 1 addition & 1 deletion mellow/src/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions mellow/src/syncing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct ConnectionMetadata {
pub roblox_memberships: Vec<RobloxMembership>
}

pub async fn get_connection_metadata(users: &Vec<UserResponse>, server: &Server) -> ConnectionMetadata {
pub async fn get_connection_metadata(users: &[UserResponse], server: &Server) -> ConnectionMetadata {
let mut roblox_memberships: Vec<RobloxMembership> = vec![];
let mut group_ids: Vec<String> = vec![];
for action in server.actions.iter() {
Expand Down Expand Up @@ -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<String> = action.metadata["items"].as_array().unwrap().into_iter().map(|x| x.as_str().unwrap().to_string()).collect();
let items: Vec<String> = 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<String> = items.into_iter().filter(|x| !member.roles.iter().any(|e| e == x)).collect();
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 8496e4d

Please sign in to comment.