50 lines
1 KiB
Rust
50 lines
1 KiB
Rust
use crate::bot::{Command, Context};
|
|
use async_trait::async_trait;
|
|
//use std::collections::HashMap;
|
|
use reqwest::Client;
|
|
use serde_json;
|
|
use serde::{Deserialize};
|
|
|
|
|
|
#[derive(Default)]
|
|
pub struct Pkg {
|
|
client: Client,
|
|
}
|
|
|
|
impl Pkg {
|
|
pub fn new() -> Self {
|
|
Pkg {
|
|
client: Client::new(),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
struct pkgd{
|
|
results: result,
|
|
}
|
|
|
|
#[derive(Deserialize)]
|
|
struct result {
|
|
pkgname: String,
|
|
repo: 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)?;
|
|
|
|
Ok(format!("{}: {}", b.results.pkgname,b.results.pkgdesc))
|
|
}
|
|
}
|