2022-08-05 19:30:56 -05:00
|
|
|
use crate::bot::{Command, Context};
|
|
|
|
use async_trait::async_trait;
|
2022-08-06 17:49:06 -05:00
|
|
|
use reqwest::Client;
|
2022-08-08 10:09:05 -05:00
|
|
|
use serde::{Deserialize};
|
2022-08-11 15:55:20 -05:00
|
|
|
|
2022-08-08 10:09:05 -05:00
|
|
|
|
2022-08-05 19:30:56 -05:00
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct Pkg {
|
2022-08-06 17:49:06 -05:00
|
|
|
client: Client,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Pkg {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Pkg {
|
|
|
|
client: Client::new(),
|
|
|
|
}
|
|
|
|
}
|
2022-08-05 19:30:56 -05:00
|
|
|
}
|
|
|
|
|
2022-08-11 15:55:20 -05:00
|
|
|
#[derive(Debug,Deserialize)]
|
|
|
|
struct Depkgd{
|
|
|
|
results: Vec<TheGStuff>,
|
2022-08-08 10:09:05 -05:00
|
|
|
}
|
|
|
|
|
2022-08-11 15:55:20 -05:00
|
|
|
#[derive(Debug,Deserialize)]
|
|
|
|
struct TheGStuff {
|
2022-08-08 10:09:05 -05:00
|
|
|
pkgname: String,
|
|
|
|
repo: String,
|
2022-08-11 06:24:31 -05:00
|
|
|
pkgver: String,
|
2022-08-08 10:09:05 -05:00
|
|
|
pkgdesc: String,
|
|
|
|
}
|
2022-08-05 19:30:56 -05:00
|
|
|
#[async_trait]
|
|
|
|
impl Command for Pkg {
|
2022-08-06 17:49:06 -05:00
|
|
|
async fn execute(&mut self, msg: Context<'_>) -> anyhow::Result<String> {
|
|
|
|
let start = Pkg::new();
|
2022-08-06 18:26:44 -05:00
|
|
|
println!("{:?}",msg.content);
|
|
|
|
let body = start.client
|
2022-08-06 17:49:06 -05:00
|
|
|
.get(format!(
|
2022-08-08 10:09:05 -05:00
|
|
|
"https://archlinux.org/packages/search/json/?name={}",
|
|
|
|
msg.content.unwrap()
|
2022-08-06 17:49:06 -05:00
|
|
|
))
|
|
|
|
.send()
|
|
|
|
.await?.text().await?;
|
2022-08-11 15:55:20 -05:00
|
|
|
let b: Depkgd = serde_json::from_str(&body)?;
|
2022-08-11 06:24:31 -05:00
|
|
|
let c = &b.results[0];
|
|
|
|
tracing::debug!("{:?}",b);
|
|
|
|
Ok(format!("{} (v: {}): {}",c.pkgname,c.pkgver,c.pkgdesc))
|
2022-08-05 19:30:56 -05:00
|
|
|
}
|
2022-08-06 17:49:06 -05:00
|
|
|
}
|