diff --git a/Cargo.lock b/Cargo.lock index 71080e2..3766b22 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -776,15 +776,6 @@ dependencies = [ "windows-sys 0.42.0", ] -[[package]] -name = "isolang" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b64fd6448ee8a45ce6e4365c58e4fa7d8740cba2ed70db3e9ab4879ebd93eaaa" -dependencies = [ - "phf", -] - [[package]] name = "itoa" version = "1.0.5" @@ -1082,24 +1073,6 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" -[[package]] -name = "phf" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" -dependencies = [ - "phf_shared", -] - -[[package]] -name = "phf_shared" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" -dependencies = [ - "siphasher", -] - [[package]] name = "pin-project-lite" version = "0.2.9" @@ -1343,14 +1316,13 @@ dependencies = [ [[package]] name = "scootaloo" -version = "1.1.4" +version = "1.1.5" dependencies = [ "base64", "clap", "egg-mode", "futures", "html-escape", - "isolang", "log", "megalodon", "mime", @@ -1523,12 +1495,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "siphasher" -version = "0.3.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" - [[package]] name = "slab" version = "0.4.7" diff --git a/Cargo.toml b/Cargo.toml index 278c292..b97c17b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scootaloo" -version = "1.1.4" +version = "1.1.5" authors = ["VC "] edition = "2021" @@ -14,7 +14,6 @@ toml = "^0.5" clap = "^4" egg-mode = "^0.16" rusqlite = "^0.27" -isolang = "^2" tokio = { version = "^1", features = ["rt"]} futures = "^0.3" megalodon = "^0.3.6" diff --git a/src/config.rs b/src/config.rs index a14fd5a..e83aed4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -43,10 +43,10 @@ pub struct ScootalooConfig { /// Parses the TOML file into a Config Struct pub fn parse_toml(toml_file: &str) -> Config { let toml_config = read_to_string(toml_file) - .unwrap_or_else(|e| panic!("Cannot open config file {}: {}", toml_file, e)); + .unwrap_or_else(|e| panic!("Cannot open config file {toml_file}: {e}")); let config: Config = toml::from_str(&toml_config) - .unwrap_or_else(|e| panic!("Cannot parse TOML file {}: {}", toml_file, e)); + .unwrap_or_else(|e| panic!("Cannot parse TOML file {toml_file}: {e}")); config } diff --git a/src/error.rs b/src/error.rs index 084dd41..ab09904 100644 --- a/src/error.rs +++ b/src/error.rs @@ -30,12 +30,12 @@ impl Display for ScootalooError { impl From> for ScootalooError { fn from(error: Box) -> Self { - ScootalooError::new(&format!("Error in a subset crate: {}", error)) + ScootalooError::new(&format!("Error in a subset crate: {error}")) } } impl From for ScootalooError { fn from(error: megalodonError) -> Self { - ScootalooError::new(&format!("Error in megalodon crate: {}", error)) + ScootalooError::new(&format!("Error in megalodon crate: {error}")) } } diff --git a/src/lib.rs b/src/lib.rs index b8cce0a..2024202 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,6 @@ use state::{read_state, write_state, TweetToToot}; use futures::StreamExt; use html_escape::decode_html_entities; -use isolang::Language; use log::info; use megalodon::{ megalodon::PostStatusInputOptions, megalodon::UpdateCredentialsInputOptions, Megalodon, @@ -204,9 +203,7 @@ pub async fn run(config: Config) { // language if any if let Some(l) = &tweet.lang { - if let Some(r) = Language::from_639_1(l) { - post_status.language = Some(r.to_string()); - } + post_status.language = Some(l.to_string()); } // can be activated for test purposes @@ -238,8 +235,8 @@ pub async fn run(config: Config) { // launch and wait for every handle while let Some(result) = stream.next().await { match result { - Ok(Err(e)) => eprintln!("Error within thread: {}", e), - Err(e) => eprintln!("Error with thread: {}", e), + Ok(Err(e)) => eprintln!("Error within thread: {e}"), + Err(e) => eprintln!("Error with thread: {e}"), _ => (), } } @@ -307,8 +304,8 @@ pub async fn profile(config: Config, bot: Option) { while let Some(result) = stream.next().await { match result { - Ok(Err(e)) => eprintln!("Error within thread: {}", e), - Err(e) => eprintln!("Error with thread: {}", e), + Ok(Err(e)) => eprintln!("Error within thread: {e}"), + Err(e) => eprintln!("Error with thread: {e}"), _ => (), } } diff --git a/src/main.rs b/src/main.rs index 2ce738f..4da8fff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,10 +63,7 @@ fn main() { .short('c') .long("config") .value_name("CONFIG_FILE") - .help(format!( - "TOML config file for scootaloo (default {})", - DEFAULT_CONFIG_PATH - )) + .help("TOML config file for scootaloo") .default_value(DEFAULT_CONFIG_PATH) .num_args(1) .display_order(1), @@ -81,7 +78,7 @@ fn main() { .short('c') .long("config") .value_name("CONFIG_FILE") - .help(format!("TOML config file for scootaloo (default {})", DEFAULT_CONFIG_PATH)) + .help("TOML config file for scootaloo") .default_value(DEFAULT_CONFIG_PATH) .num_args(1) .display_order(1), @@ -104,7 +101,7 @@ fn main() { .short('c') .long("config") .value_name("CONFIG_FILE") - .help(format!("TOML config file for scootaloo (default {})", DEFAULT_CONFIG_PATH)) + .help("TOML config file for scootaloo") .default_value(DEFAULT_CONFIG_PATH) .num_args(1) .display_order(1), diff --git a/src/mastodon.rs b/src/mastodon.rs index 140be04..25e8f70 100644 --- a/src/mastodon.rs +++ b/src/mastodon.rs @@ -83,7 +83,7 @@ pub fn associate_urls(urls: &[UrlEntity], re: &Option) -> HashMap, alts: &HashMap) { for val in urls.values_mut() { for (k, v) in alts { - *val = val.replace(&format!("/{}/", k), &format!("/{}/", v)); + *val = val.replace(&format!("/{k}/"), &format!("/{v}/")); } } } @@ -120,7 +120,7 @@ pub fn replace_tweet_by_toot( twitter_screen_name.to_lowercase(), tweet_id )) { - *val = format!("{}/@{}/{}", base_url, mastodon_screen_name, toot_id); + *val = format!("{base_url}/@{mastodon_screen_name}/{toot_id}"); } } } @@ -184,7 +184,7 @@ pub async fn register(host: &str, screen_name: &str) { let url = app_data.url.expect("Cannot generate registration URI!"); - println!("Click this link to authorize on Mastodon: {}", url); + println!("Click this link to authorize on Mastodon: {url}"); println!("Paste the returned authorization code: "); let mut input = String::new(); diff --git a/src/state.rs b/src/state.rs index 99aaa05..fdeb7a3 100644 --- a/src/state.rs +++ b/src/state.rs @@ -21,8 +21,8 @@ pub fn read_state( ) -> Result, Box> { debug!("Reading tweet_id {:?}", s); let query: String = match s { - Some(i) => format!("SELECT * FROM tweet_to_toot WHERE tweet_id = {} and twitter_screen_name = \"{}\"", i, n), - None => format!("SELECT * FROM tweet_to_toot WHERE twitter_screen_name = \"{}\" ORDER BY tweet_id DESC LIMIT 1", n), + Some(i) => format!("SELECT * FROM tweet_to_toot WHERE tweet_id = {i} and twitter_screen_name = \"{n}\""), + None => format!("SELECT * FROM tweet_to_toot WHERE twitter_screen_name = \"{n}\" ORDER BY tweet_id DESC LIMIT 1"), }; let mut stmt = conn.prepare(&query)?; @@ -78,8 +78,7 @@ pub fn migrate_db(d: &str, s: &str) -> Result<(), Box> { &format!( "ALTER TABLE tweet_to_toot ADD COLUMN twitter_screen_name TEXT NOT NULL - DEFAULT \"{}\"", - s + DEFAULT \"{s}\"" ), [], ); diff --git a/src/util.rs b/src/util.rs index 88029ba..0e5f063 100644 --- a/src/util.rs +++ b/src/util.rs @@ -112,12 +112,12 @@ pub async fn base64_media(u: &str) -> Result> { let content_type = response .headers() .get("content-type") - .ok_or_else(|| ScootalooError::new(&format!("Cannot get media content type for {}", u)))? + .ok_or_else(|| ScootalooError::new(&format!("Cannot get media content type for {u}")))? .to_str()?; let encoded_f = encode(buffer); - Ok(format!("data:{};base64,{}", content_type, encoded_f)) + Ok(format!("data:{content_type};base64,{encoded_f}")) } /// Gets and caches Twitter Media inside the determined temp dir @@ -134,19 +134,17 @@ pub async fn cache_media(u: &str, t: &str) -> Result> { .path_segments() .ok_or_else(|| { ScootalooError::new(&format!( - "Cannot determine the destination filename for {}", - u + "Cannot determine the destination filename for {u}" )) })? .last() .ok_or_else(|| { ScootalooError::new(&format!( - "Cannot determine the destination filename for {}", - u + "Cannot determine the destination filename for {u}" )) })?; - let dest_filepath = format!("{}/{}", t, dest_filename); + let dest_filepath = format!("{t}/{dest_filename}"); let mut dest_file = File::create(&dest_filepath).await?;