this repo has no description
1
fork

Configure Feed

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

feat: nixpkg command

isabel 39787f1f 44072124

+105 -5
+1 -2
src/commands/fun/mod.rs
··· 2 2 pub mod chance; 3 3 pub mod height; 4 4 pub mod kittysay; 5 - pub mod nix; 6 - pub mod pet; 5 + pub mod pet;
src/commands/fun/nix.rs src/commands/nix/nix.rs
-1
src/commands/misc/mod.rs
··· 1 - pub mod nixpkgs; 2 1 pub mod crates;
src/commands/misc/nixpkgs.rs src/commands/nix/nixpkgs.rs
+1
src/commands/mod.rs
··· 2 2 pub mod fun; 3 3 pub mod misc; 4 4 pub mod moderation; 5 + pub mod nix; 5 6 pub mod user;
+3
src/commands/nix/mod.rs
··· 1 + pub mod nix; 2 + pub mod nixpkg; 3 + pub mod nixpkgs;
+96
src/commands/nix/nixpkg.rs
··· 1 + use crate::types::Context; 2 + use color_eyre::eyre::Result; 3 + use poise::{serenity_prelude::CreateEmbed, CreateReply}; 4 + use std::process::Command; 5 + 6 + #[derive(serde::Deserialize)] 7 + struct PackageMeta { 8 + name: String, 9 + description: String, 10 + homepage: Option<String>, 11 + license: License, 12 + maintainers: Vec<Maintainers>, 13 + position: String, 14 + // broken: bool, 15 + insecure: bool, 16 + unfree: bool, 17 + } 18 + 19 + #[derive(serde::Deserialize)] 20 + struct License { 21 + #[serde(rename = "spdxId")] 22 + spdx_id: String, 23 + } 24 + 25 + #[derive(serde::Deserialize)] 26 + struct Maintainers { 27 + name: String, 28 + // email: Option<String>, 29 + } 30 + 31 + /// Track nixpkgs PRs 32 + #[poise::command( 33 + slash_command, 34 + install_context = "Guild|User", 35 + interaction_context = "Guild|BotDm|PrivateChannel" 36 + )] 37 + pub async fn nixpkg( 38 + ctx: Context<'_>, 39 + #[description = "package name"] package: String, 40 + ) -> Result<()> { 41 + let pkg = 42 + Command::new("nix") 43 + .args([ 44 + "eval", 45 + "--impure", 46 + "--json", 47 + "--expr", 48 + &format!( 49 + "with import <nixpkgs> {{ config.allowUnfree = true; }}; pkgs.{package}.meta", 50 + ), 51 + ]) 52 + .output()?; 53 + 54 + if !pkg.status.success() { 55 + ctx.say("Package not found or an error occurred.").await?; 56 + ctx.say(format!("Error: {}", String::from_utf8_lossy(&pkg.stderr))) 57 + .await?; 58 + return Ok(()); 59 + } 60 + 61 + let pkg: PackageMeta = serde_json::from_slice(&pkg.stdout)?; 62 + 63 + let file = &pkg.position[51..]; 64 + let fin_file = file 65 + .split_once(':') 66 + .map_or_else(|| file.to_string(), |(before, _)| before.to_string()); 67 + 68 + let embed = CreateEmbed::new() 69 + .title(pkg.name) 70 + .url(format!( 71 + "https://github.com/nixos/nixpkgs/blob/master/{fin_file}" 72 + )) 73 + .description(pkg.description) 74 + .field( 75 + "Homepage", 76 + pkg.homepage.unwrap_or_else(|| "N/A".to_string()), 77 + false, 78 + ) 79 + .field("license", pkg.license.spdx_id, true) 80 + .field("insecure", pkg.insecure.to_string(), true) 81 + .field("unfree", pkg.unfree.to_string(), true) 82 + .field( 83 + "maintainers", 84 + pkg.maintainers 85 + .iter() 86 + .map(|m| m.name.clone()) 87 + .collect::<Vec<String>>() 88 + .join(", "), 89 + false, 90 + ) 91 + .color(0x00DE_A586); 92 + 93 + ctx.send(CreateReply::default().embed(embed)).await?; 94 + 95 + Ok(()) 96 + }
+4 -2
src/main.rs
··· 34 34 commands::bot::ping::ping(), 35 35 commands::bot::bot::botinfo(), 36 36 // misc commands 37 - commands::misc::nixpkgs::nixpkgs(), 38 37 commands::misc::crates::crates(), 39 38 // moderation commands 40 39 commands::moderation::ban::ban(), 41 40 commands::moderation::kick::kick(), 42 41 commands::moderation::timeout::timeout(), 42 + // commands for nix 43 + commands::nix::nixpkgs::nixpkgs(), 44 + commands::nix::nix::nix(), 45 + commands::nix::nixpkg::nixpkg(), 43 46 // fun commands 44 - commands::fun::nix::nix(), 45 47 commands::fun::chance::roll(), 46 48 commands::fun::chance::raffle(), 47 49 commands::fun::kittysay::kittysay(),