Add fedora dnf search
This commit is contained in:
parent
af1891f3b9
commit
258c6dbc9a
|
@ -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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,12 @@
|
||||||
use serenity::model::channel::Message;
|
|
||||||
use std::fmt;
|
|
||||||
use serenity::model::id::ChannelId;
|
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
use serenity::model::channel::Message;
|
||||||
|
use serenity::model::id::ChannelId;
|
||||||
use serenity::prelude::*;
|
use serenity::prelude::*;
|
||||||
|
use std::fmt;
|
||||||
mod apt;
|
mod apt;
|
||||||
mod pacman;
|
mod dnf;
|
||||||
mod nix;
|
mod nix;
|
||||||
|
mod pacman;
|
||||||
extern crate reqwest;
|
extern crate reqwest;
|
||||||
|
|
||||||
pub struct Handler;
|
pub struct Handler;
|
||||||
|
@ -50,6 +51,7 @@ lazy_static! {
|
||||||
command_list.push(Command::new("pacman", pacman::query_pacman));
|
command_list.push(Command::new("pacman", pacman::query_pacman));
|
||||||
command_list.push(Command::new("apt", apt::query_apt));
|
command_list.push(Command::new("apt", apt::query_apt));
|
||||||
command_list.push(Command::new("nix", nix::query_nix));
|
command_list.push(Command::new("nix", nix::query_nix));
|
||||||
|
command_list.push(Command::new("dnf", dnf::query_dnf));
|
||||||
command_list
|
command_list
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user