From a30e9915910ad69692752a8b926bdc7e521e0ec1 Mon Sep 17 00:00:00 2001 From: AnnsAnn Date: Tue, 19 Mar 2024 10:29:20 +0100 Subject: [PATCH] Make clippy happy --- sphene/src/commands/convert_url.rs | 10 +++---- sphene/src/message_handler.rs | 9 ++----- .../src/message_handler/interaction_event.rs | 27 +++++++------------ sphene/src/message_handler/message_event.rs | 10 +++---- 4 files changed, 18 insertions(+), 38 deletions(-) diff --git a/sphene/src/commands/convert_url.rs b/sphene/src/commands/convert_url.rs index 614b087..a4c216b 100644 --- a/sphene/src/commands/convert_url.rs +++ b/sphene/src/commands/convert_url.rs @@ -2,12 +2,8 @@ use poise::serenity_prelude::{CreateSelectMenuOption, Message}; use thorium::db::DBConn; use tokio::sync::Mutex; -use poise::serenity_prelude::{ - Context, CreateActionRow, CreateAllowedMentions, CreateMessage, - CreateSelectMenu, CreateSelectMenuKind, - MessageBuilder, UserId, -}; -use rust_i18n::t; + + use thorium::{bluesky, instagram, tiktok, twitter}; use crate::{ @@ -64,7 +60,7 @@ pub async fn convert_twitter_to(url: String, kind: &str) -> String { _ => twitter::UrlType::Unknown, }; - let mut new_msg = + let new_msg = twitter::convert_url_lazy(url.to_string(), twitter_urltype).await; format!( diff --git a/sphene/src/message_handler.rs b/sphene/src/message_handler.rs index 38d71d8..c922afd 100644 --- a/sphene/src/message_handler.rs +++ b/sphene/src/message_handler.rs @@ -18,13 +18,8 @@ pub async fn event_handler( FullEvent::Message { new_message } => { message_event::message(ctx, new_message.clone(), &data.db).await; } - FullEvent::InteractionCreate { interaction } => { - match interaction { - Interaction::Component(component) => { - interaction_event::interaction_create(ctx, component.clone(), &data.db).await; - } - _ => {} - } + FullEvent::InteractionCreate { interaction: Interaction::Component(component) } => { + interaction_event::interaction_create(ctx, component.clone(), &data.db).await; } _ => {} } diff --git a/sphene/src/message_handler/interaction_event.rs b/sphene/src/message_handler/interaction_event.rs index c6fabd4..ba5532f 100644 --- a/sphene/src/message_handler/interaction_event.rs +++ b/sphene/src/message_handler/interaction_event.rs @@ -1,21 +1,21 @@ use poise::serenity_prelude::{ - ComponentInteraction, ComponentInteractionDataKind, Context, CreateActionRow, CreateAllowedMentions, CreateInteractionResponse, CreateInteractionResponseFollowup, CreateInteractionResponseMessage, EditInteractionResponse, EditMessage + ComponentInteraction, ComponentInteractionDataKind, Context, CreateAllowedMentions, CreateInteractionResponse, CreateInteractionResponseFollowup, CreateInteractionResponseMessage, EditInteractionResponse, EditMessage }; use rust_i18n::t; use thorium::{bluesky, db::DBConn, instagram, tiktok, twitter}; use tokio::sync::Mutex; -use crate::utils::{REGEX_URL_EXTRACTOR}; +use crate::{commands::convert_url::convert_twitter_to, utils::REGEX_URL_EXTRACTOR}; pub async fn interaction_create(ctx: &Context, component: ComponentInteraction, dbconn: &Mutex) { let command = match &component.data.kind { ComponentInteractionDataKind::StringSelect { values, .. } => values[0].as_str(), - _ => return (), + _ => return , }; - let mut msg = &component.message; + let msg = &component.message; if !msg.author.bot { return; @@ -145,7 +145,7 @@ pub async fn interaction_create(ctx: &Context, component: ComponentInteraction, .to_string(); let mut new_msg: String = String::new(); - let mut twitter_urltype = twitter::UrlType::from_string(command); + let twitter_urltype = twitter::UrlType::from_string(command); let bluesky_urltype = bluesky::UrlType::from_string(command); let instagram_urltype = instagram::UrlType::from_string(command); let tiktok_urltype = tiktok::UrlType::from_string(command); @@ -159,19 +159,10 @@ pub async fn interaction_create(ctx: &Context, component: ComponentInteraction, } else if tiktok_urltype != tiktok::UrlType::Unknown { new_msg = tiktok::convert_url_lazy(extracted_url, tiktok_urltype).await; } else if command == "direct_vx" || command == "direct_fx" { - twitter_urltype = match command { - "direct_vx" => twitter::UrlType::Vxtwitter, - "direct_fx" => twitter::UrlType::Fxtwitter, - _ => twitter::UrlType::Unknown, - }; - - new_msg = - twitter::convert_url_lazy(extracted_url.to_string(), twitter_urltype).await; - new_msg = format!( - "<{}> ({})", - new_msg, - twitter::get_media_from_url(new_msg.clone()).await - ); + new_msg = convert_twitter_to( + extracted_url.to_string(), + command, + ).await } else if command == "direct_fxbsky" { new_msg = bluesky::convert_url_lazy( extracted_url.to_string(), diff --git a/sphene/src/message_handler/message_event.rs b/sphene/src/message_handler/message_event.rs index 75ab00c..2949bbd 100644 --- a/sphene/src/message_handler/message_event.rs +++ b/sphene/src/message_handler/message_event.rs @@ -1,18 +1,16 @@ -use std::convert; + use poise::serenity_prelude::{ Context, CreateActionRow, CreateAllowedMentions, CreateMessage, - CreateSelectMenu, CreateSelectMenuKind, CreateSelectMenuOption, Message, + CreateSelectMenu, CreateSelectMenuKind, Message, MessageBuilder, UserId, }; use rust_i18n::t; -use thorium::{bluesky, db::DBConn, instagram, tiktok, twitter}; +use thorium::{db::DBConn}; use tokio::sync::Mutex; use crate::{ - commands::convert_url::convert_url, options::{ - get_blueksy_options, get_instagram_options, get_tik_tok_options, get_twitter_options, - } + commands::convert_url::convert_url }; pub async fn message(context: &Context, msg: Message, dbconn: &Mutex) {