51 lines
1.1 KiB
Rust
51 lines
1.1 KiB
Rust
use crate::bot::{Command, Context};
|
|
use async_trait::async_trait;
|
|
use reqwest::Client;
|
|
use serde::{Deserialize};
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
pub struct Pkg {
|
|
client: Client,
|
|
}
|
|
|
|
impl Pkg {
|
|
pub fn new() -> Self {
|
|
Pkg {
|
|
client: Client::new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug,Deserialize)]
|
|
struct Depkgd{
|
|
results: Vec<TheGStuff>,
|
|
}
|
|
|
|
#[derive(Debug,Deserialize)]
|
|
struct TheGStuff {
|
|
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: Depkgd = serde_json::from_str(&body)?;
|
|
let c = &b.results[0];
|
|
tracing::debug!("{:?}",b);
|
|
Ok(format!("{} (v: {}): {}",c.pkgname,c.pkgver,c.pkgdesc))
|
|
}
|
|
}
|