diff --git a/src/commands/dnf.rs b/src/commands/dnf.rs new file mode 100644 index 0000000..c33e377 --- /dev/null +++ b/src/commands/dnf.rs @@ -0,0 +1,37 @@ +use crate::commands::*; +use serde::Deserialize; +use serenity::model::channel::Message; +use std::fmt; + +pub fn query_dnf(ctx: Context, msg: Message, args: Vec<&str>) { + let query = args.join(" "); + let response: Response = search( + &format!("https://mdapi.fedoraproject.org/f31/pkg/{}", &query), + |_e| Default::default(), + ); + if response.basename == "" { + send(msg.channel_id, "No results", &ctx); + return; + } + respond_with_results(msg.channel_id, &[response], &ctx); +} + +#[derive(Deserialize, Default)] +struct Response { + basename: String, + arch: String, + description: String, + repo: String, + url: String, + version: String, +} + +impl fmt::Display for Response { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + f, + "{}.{} : {}\n {} in {}\n Homepage: {}", + self.basename, self.arch, self.description, self.version, self.repo, self.url + ) + } +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 78ac2ba..d238e9b 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,11 +1,12 @@ -use serenity::model::channel::Message; -use std::fmt; -use serenity::model::id::ChannelId; use serde::de::DeserializeOwned; +use serenity::model::channel::Message; +use serenity::model::id::ChannelId; use serenity::prelude::*; +use std::fmt; mod apt; -mod pacman; +mod dnf; mod nix; +mod pacman; extern crate reqwest; pub struct Handler; @@ -50,6 +51,7 @@ lazy_static! { command_list.push(Command::new("pacman", pacman::query_pacman)); command_list.push(Command::new("apt", apt::query_apt)); command_list.push(Command::new("nix", nix::query_nix)); + command_list.push(Command::new("dnf", dnf::query_dnf)); command_list }; }