this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: apply clippy suggestions

isabel 0c3e6594 300fe506

+116 -102
+7
src/commands/fun/height.rs
··· 17 17 let total_inches = rand::rng().random_range(49..=101); 18 18 let feet = total_inches / 12; 19 19 let inches = total_inches % 12; 20 + 21 + #[allow( 22 + clippy::cast_possible_truncation, 23 + clippy::cast_sign_loss, 24 + clippy::cast_precision_loss 25 + )] 20 26 let cm = (total_inches as f32 * 2.54) as u32; 27 + 21 28 (feet, inches, cm) 22 29 } 23 30 };
+8 -1
src/commands/moderation/timeout.rs
··· 85 85 return Ok(()); 86 86 } 87 87 88 + let seconds = i64::try_from(seconds); 89 + if seconds.is_err() { 90 + ctx.say("Duration value is too large!").await?; 91 + return Ok(()); 92 + } 93 + 94 + // safer unwrap then cloudflare lol 88 95 let timeout_until = 89 - Timestamp::from_unix_timestamp(Timestamp::now().unix_timestamp() + seconds as i64)?; 96 + Timestamp::from_unix_timestamp(Timestamp::now().unix_timestamp() + seconds.unwrap())?; 90 97 91 98 guild 92 99 .member(ctx, user.id)
+1
src/commands/nix/mod.rs
··· 1 + #[allow(clippy::module_inception)] 1 2 pub mod nix; 2 3 pub mod nixpkg; 3 4 pub mod nixpkgs;
+2 -3
src/commands/nix/nixpkg.rs
··· 1 1 use crate::types::Context; 2 2 use color_eyre::eyre::{Result, eyre}; 3 - use once_cell::sync::Lazy; 4 3 use poise::{CreateReply, serenity_prelude::CreateEmbed}; 5 4 use rusqlite::{Connection, params}; 6 5 use std::sync::Mutex; 7 6 8 - static DB: Lazy<Mutex<Connection>> = Lazy::new(|| { 7 + static DB: std::sync::LazyLock<Mutex<Connection>> = std::sync::LazyLock::new(|| { 9 8 let db_path = std::env::var("NIXPKGS_DB").unwrap_or_else(|_| "nixpkgs.db".to_string()); 10 9 Mutex::new(Connection::open(db_path).expect("Failed to open database")) 11 10 }); ··· 97 96 .unwrap_or_else(|| "Unknown".to_string()), 98 97 github: row 99 98 .get::<_, Option<String>>(1)? 100 - .unwrap_or_else(|| "".to_string()), 99 + .unwrap_or_else(String::new), 101 100 }) 102 101 })? 103 102 .filter_map(Result::ok)
+48 -57
src/commands/user/color_me.rs
··· 1 1 use crate::types::Context; 2 2 use color_eyre::eyre::Result; 3 - use poise::CreateReply; 4 3 use poise::serenity_prelude::{Colour, EditRole}; 4 + use poise::CreateReply; 5 5 6 6 /// Change your display color or remove your color role. 7 7 #[poise::command(slash_command)] ··· 9 9 ctx: Context<'_>, 10 10 #[description = "Hex color code (e.g., #FF5733 or FF5733)"] color: Option<String>, 11 11 ) -> Result<()> { 12 - let guild_id = match ctx.guild_id() { 13 - Some(id) => id, 14 - None => { 15 - ctx.send( 16 - CreateReply::default() 17 - .content("This command can only be used in a server.") 18 - .ephemeral(true), 19 - ) 20 - .await?; 21 - return Ok(()); 22 - } 12 + let Some(guild_id) = ctx.guild_id() else { 13 + ctx.send( 14 + CreateReply::default() 15 + .content("This command can only be used in a server.") 16 + .ephemeral(true), 17 + ) 18 + .await?; 19 + return Ok(()); 23 20 }; 24 21 25 22 let member = guild_id.member(ctx.http(), ctx.author().id).await?; ··· 36 33 Some(color_str) => { 37 34 // parse the hex color 38 35 let color_str = color_str.trim_start_matches('#'); 39 - let color_value = match u32::from_str_radix(color_str, 16) { 40 - Ok(val) => val, 41 - Err(_) => { 42 - ctx.send( 43 - CreateReply::default() 44 - .content("Invalid hex color! Please provide a valid hex color code (e.g., #FF5733 or FF5733).") 45 - .ephemeral(true), 46 - ) 47 - .await?; 48 - return Ok(()); 49 - } 36 + let Ok(color_value) = u32::from_str_radix(color_str, 16) else { 37 + ctx.send( 38 + CreateReply::default() 39 + .content("Invalid hex color! Please provide a valid hex color code (e.g., #FF5733 or FF5733).") 40 + .ephemeral(true), 41 + ) 42 + .await?; 43 + return Ok(()); 50 44 }; 51 45 52 - let colour = Colour::new(color_value); 46 + let colour_picked = Colour::new(color_value); 53 47 54 - match existing_role { 55 - Some((role_id, _)) => { 56 - // update existing role 57 - guild_id 58 - .edit_role(ctx.http(), role_id, EditRole::new().colour(colour.0)) 59 - .await?; 60 - ctx.send( 61 - CreateReply::default() 62 - .content(format!("Updated your color to `#{color_str}`! <3")) 63 - .ephemeral(true), 48 + if let Some((role_id, _)) = existing_role { 49 + // update existing role 50 + guild_id 51 + .edit_role(ctx.http(), role_id, EditRole::new().colour(colour_picked.0)) 52 + .await?; 53 + ctx.send( 54 + CreateReply::default() 55 + .content(format!("Updated your color to `#{color_str}`! <3")) 56 + .ephemeral(true), 57 + ) 58 + .await?; 59 + } else { 60 + // or else create new role 61 + let new_role = guild_id 62 + .create_role( 63 + ctx.http(), 64 + EditRole::new() 65 + .name(username) 66 + .colour(colour_picked.0) 67 + .hoist(false) 68 + .mentionable(false), 64 69 ) 65 70 .await?; 66 - } 67 - None => { 68 - // or else create new role 69 - let new_role = guild_id 70 - .create_role( 71 - ctx.http(), 72 - EditRole::new() 73 - .name(username) 74 - .colour(colour.0) 75 - .hoist(false) 76 - .mentionable(false), 77 - ) 78 - .await?; 79 71 80 - member.add_role(ctx.http(), new_role.id).await?; 72 + member.add_role(ctx.http(), new_role.id).await?; 81 73 82 - ctx.send( 83 - CreateReply::default() 84 - .content(format!( 85 - "Created a new role and set your color to `#{color_str}`! <3" 86 - )) 87 - .ephemeral(true), 88 - ) 89 - .await?; 90 - } 74 + ctx.send( 75 + CreateReply::default() 76 + .content(format!( 77 + "Created a new role and set your color to `#{color_str}`! <3" 78 + )) 79 + .ephemeral(true), 80 + ) 81 + .await?; 91 82 } 92 83 } 93 84 None => {
+50 -41
src/main.rs
··· 23 23 let html = response.text().await?; 24 24 25 25 let url_regex = 26 - regex::Regex::new(r#"<a href='([^']+/packages\.json\.br)'>packages\.json\.br</a>"#)?; 26 + regex::Regex::new(r"<a href='([^']+/packages\.json\.br)'>packages\.json\.br</a>")?; 27 27 let hash_regex = regex::Regex::new( 28 - r#"packages\.json\.br</a></td><td align='right'>\d+</td><td><tt>([a-f0-9]{64})</tt>"#, 28 + r"packages\.json\.br</a></td><td align='right'>\d+</td><td><tt>([a-f0-9]{64})</tt>", 29 29 )?; 30 30 31 31 let url = url_regex ··· 36 36 if path.starts_with("http") { 37 37 path.to_string() 38 38 } else if path.starts_with('/') { 39 - format!("https://releases.nixos.org{}", path) 39 + format!("https://releases.nixos.org{path}") 40 40 } else { 41 - format!("https://releases.nixos.org/{}", path) 41 + format!("https://releases.nixos.org/{path}") 42 42 } 43 43 }) 44 44 .ok_or_else(|| color_eyre::eyre::eyre!("Could not find packages.json.br URL"))?; ··· 63 63 Ok(()) 64 64 } 65 65 66 + #[allow(clippy::too_many_lines)] 66 67 async fn ensure_nixpkgs_database() -> Result<()> { 67 68 let db_path = env::var("NIXPKGS_DB").unwrap_or_else(|_| "nixpkgs.db".to_string()); 68 69 ··· 179 180 serde_json::Value::Object(obj) => obj 180 181 .get("spdxId") 181 182 .and_then(|v| v.as_str()) 182 - .map(|s| s.to_string()), 183 + .map(std::string::ToString::to_string), 183 184 serde_json::Value::Array(arr) => { 184 185 let ids: Vec<&str> = arr 185 186 .iter() ··· 207 208 pkg_data 208 209 .get("pname") 209 210 .and_then(|v| v.as_str()) 210 - .map(|s| s.to_string()), 211 + .map(std::string::ToString::to_string), 211 212 pkg_data 212 213 .get("version") 213 214 .and_then(|v| v.as_str()) 214 - .map(|s| s.to_string()), 215 + .map(std::string::ToString::to_string), 215 216 pkg_data 216 217 .get("name") 217 218 .and_then(|v| v.as_str()) 218 - .map(|s| s.to_string()), 219 + .map(std::string::ToString::to_string), 219 220 pkg_data 220 221 .get("system") 221 222 .and_then(|v| v.as_str()) 222 - .map(|s| s.to_string()), 223 + .map(std::string::ToString::to_string), 223 224 pkg_data 224 225 .get("outputName") 225 226 .and_then(|v| v.as_str()) 226 - .map(|s| s.to_string()), 227 - meta.get("available") 228 - .and_then(|v| v.as_bool()) 229 - .unwrap_or(false) as i32, 230 - meta.get("broken") 231 - .and_then(|v| v.as_bool()) 232 - .unwrap_or(false) as i32, 227 + .map(std::string::ToString::to_string), 228 + i32::from( 229 + meta.get("available") 230 + .and_then(serde_json::Value::as_bool) 231 + .unwrap_or(false), 232 + ), 233 + i32::from( 234 + meta.get("broken") 235 + .and_then(serde_json::Value::as_bool) 236 + .unwrap_or(false), 237 + ), 233 238 meta.get("description") 234 239 .and_then(|v| v.as_str()) 235 - .map(|s| s.to_string()), 236 - homepage.map(|s| s.to_string()), 237 - meta.get("insecure") 238 - .and_then(|v| v.as_bool()) 239 - .unwrap_or(false) as i32, 240 - meta.get("unfree") 241 - .and_then(|v| v.as_bool()) 242 - .unwrap_or(false) as i32, 243 - meta.get("unsupported") 244 - .and_then(|v| v.as_bool()) 245 - .unwrap_or(false) as i32, 240 + .map(std::string::ToString::to_string), 241 + homepage.map(std::string::ToString::to_string), 242 + i32::from( 243 + meta.get("insecure") 244 + .and_then(serde_json::Value::as_bool) 245 + .unwrap_or(false), 246 + ), 247 + i32::from( 248 + meta.get("unfree") 249 + .and_then(serde_json::Value::as_bool) 250 + .unwrap_or(false), 251 + ), 252 + i32::from( 253 + meta.get("unsupported") 254 + .and_then(serde_json::Value::as_bool) 255 + .unwrap_or(false), 256 + ), 246 257 meta.get("position") 247 258 .and_then(|v| v.as_str()) 248 - .map(|s| s.to_string()), 259 + .map(std::string::ToString::to_string), 249 260 meta.get("longDescription") 250 261 .and_then(|v| v.as_str()) 251 - .map(|s| s.to_string()), 262 + .map(std::string::ToString::to_string), 252 263 meta.get("mainProgram") 253 264 .and_then(|v| v.as_str()) 254 - .map(|s| s.to_string()), 265 + .map(std::string::ToString::to_string), 255 266 license_spdx, 256 267 None::<String>, 257 268 0, ··· 265 276 pkg_name.clone(), 266 277 obj.get("name") 267 278 .and_then(|v| v.as_str()) 268 - .map(|s| s.to_string()), 279 + .map(std::string::ToString::to_string), 269 280 obj.get("email") 270 281 .and_then(|v| v.as_str()) 271 - .map(|s| s.to_string()), 282 + .map(std::string::ToString::to_string), 272 283 obj.get("github") 273 284 .and_then(|v| v.as_str()) 274 - .map(|s| s.to_string()), 275 - obj.get("githubId").and_then(|v| v.as_i64()), 285 + .map(std::string::ToString::to_string), 286 + obj.get("githubId").and_then(serde_json::Value::as_i64), 276 287 obj.get("matrix") 277 288 .and_then(|v| v.as_str()) 278 - .map(|s| s.to_string()), 289 + .map(std::string::ToString::to_string), 279 290 )); 280 291 } 281 292 } ··· 302 313 } 303 314 tx.commit()?; 304 315 305 - println!( 306 - "Progress: {}/{} ({:.1}%)", 307 - count, 308 - total, 309 - (count as f64 / total as f64) * 100.0 310 - ); 316 + #[allow(clippy::cast_precision_loss)] 317 + let progress = (f64::from(count) / total as f64) * 100.0; 318 + 319 + println!("Progress: {count}/{total} ({progress:.1}%)"); 311 320 package_batch.clear(); 312 321 maintainer_batch.clear(); 313 322 }