Add aur queries
This commit is contained in:
parent
ef4c01dfb3
commit
54b1855db5
|
@ -0,0 +1,55 @@
|
|||
use crate::commands::*;
|
||||
use serde::Deserialize;
|
||||
use serenity::model::channel::Message;
|
||||
use std::fmt;
|
||||
|
||||
pub fn query_aur(ctx: Context, msg: Message, args: Vec<&str>) {
|
||||
let query = args.join(" ");
|
||||
let response: Response = search(
|
||||
&format!(
|
||||
"https://aur.archlinux.org/rpc/?v=5&type=search&by=name&arg={}",
|
||||
&query
|
||||
),
|
||||
|_e| EMPTY_RESULT,
|
||||
);
|
||||
if response.results.is_empty() {
|
||||
send(msg.channel_id, "No results", &ctx);
|
||||
return;
|
||||
}
|
||||
respond_with_results(msg.channel_id, &response.results, &ctx);
|
||||
}
|
||||
|
||||
const EMPTY_RESULT: Response = Response {
|
||||
results: Vec::new(),
|
||||
};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Response {
|
||||
results: Vec<Package>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Package {
|
||||
#[serde(rename = "Name")]
|
||||
name: String,
|
||||
#[serde(rename = "Version")]
|
||||
version: String,
|
||||
#[serde(rename = "Description")]
|
||||
description: String,
|
||||
#[serde(rename = "URL")]
|
||||
url: String,
|
||||
#[serde(rename = "NumVotes")]
|
||||
votes: u16,
|
||||
//Popularity 3.159745
|
||||
//OutOfDate null
|
||||
}
|
||||
|
||||
impl fmt::Display for Package {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"aur/{} {} (+{})\n {}\n url: {}",
|
||||
self.name, self.version, self.votes, self.description, self.url
|
||||
)
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ mod apt;
|
|||
mod dnf;
|
||||
mod nix;
|
||||
mod pacman;
|
||||
mod aur;
|
||||
extern crate reqwest;
|
||||
|
||||
pub struct Handler;
|
||||
|
@ -64,6 +65,7 @@ lazy_static! {
|
|||
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.push(Command::new("aur", aur::query_aur));
|
||||
command_list.push(Command::new("pacbot help", help));
|
||||
command_list.push(Command::new("pb help", help));
|
||||
command_list
|
||||
|
|
Loading…
Reference in New Issue
Block a user