Add fedora dnf search

This commit is contained in:
kageru 2019-10-31 12:21:24 +01:00
parent af1891f3b9
commit 258c6dbc9a
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
2 changed files with 43 additions and 4 deletions

37
src/commands/dnf.rs Normal file
View File

@ -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
)
}
}

View File

@ -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
};
}