From 411fb28ae07562cfa599a3d834d485dd7fee7dc3 Mon Sep 17 00:00:00 2001 From: gallant Date: Mon, 8 Aug 2022 10:09:05 -0500 Subject: [PATCH] yo delta check this out --- src/commands/pkg.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/commands/pkg.rs b/src/commands/pkg.rs index df21b7c..f6c09aa 100644 --- a/src/commands/pkg.rs +++ b/src/commands/pkg.rs @@ -2,6 +2,9 @@ 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 { @@ -16,6 +19,17 @@ impl Pkg { } } +#[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 { @@ -23,11 +37,13 @@ impl Command for Pkg { println!("{:?}",msg.content); let body = start.client .get(format!( - "https://archlinux.org/packages/search/json/?name={:?}", - msg.content + "https://archlinux.org/packages/search/json/?name={}", + msg.content.unwrap() )) .send() .await?.text().await?; - Ok(body) + let b: pkgd = serde_json::from_str(&body)?; + + Ok(format!("{}: {}", b.results.pkgname,b.results.pkgdesc)) } }