54 lines
1.2 KiB
Rust
54 lines
1.2 KiB
Rust
use crate::bot::{Command, Context};
|
|
use async_trait::async_trait;
|
|
//use std::collections::HashMap;
|
|
use reqwest::Client;
|
|
use serde_json::{Map,Value};
|
|
use serde::{Deserialize};
|
|
use tracing::Level;
|
|
|
|
|
|
#[derive(Default)]
|
|
pub struct Pkg {
|
|
client: Client,
|
|
}
|
|
|
|
impl Pkg {
|
|
pub fn new() -> Self {
|
|
Pkg {
|
|
client: Client::new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct pkgd{
|
|
version: u32,
|
|
results: Vec<result>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
struct result {
|
|
pkgname: String,
|
|
repo: String,
|
|
pkgver: String,
|
|
pkgdesc: String,
|
|
}
|
|
#[async_trait]
|
|
impl Command for Pkg {
|
|
async fn execute(&mut self, msg: Context<'_>) -> anyhow::Result<String> {
|
|
let start = Pkg::new();
|
|
println!("{:?}",msg.content);
|
|
let body = start.client
|
|
.get(format!(
|
|
"https://archlinux.org/packages/search/json/?name={}",
|
|
msg.content.unwrap()
|
|
))
|
|
.send()
|
|
.await?.text().await?;
|
|
let b: pkgd = serde_json::from_str(&body)?;
|
|
let c = &b.results[0];
|
|
tracing::debug!("{:?}",b);
|
|
Ok(format!("{} (v: {}): {}",c.pkgname,c.pkgver,c.pkgdesc))
|
|
}
|
|
}
|