From 2642f6111fac0c74c568129e605fdc8fc6ba3567 Mon Sep 17 00:00:00 2001 From: gallant Date: Sat, 6 Aug 2022 17:49:06 -0500 Subject: [PATCH] working --- src/commands/mod.rs | 1 + src/commands/pkg.rs | 26 ++++++++++++++++++++++---- src/main.rs | 2 ++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index dbef554..332a976 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -9,3 +9,4 @@ pub mod sed; pub mod spotify; pub mod title; pub mod waifu; +pub mod pkg; \ No newline at end of file diff --git a/src/commands/pkg.rs b/src/commands/pkg.rs index f5f459d..6b314c6 100644 --- a/src/commands/pkg.rs +++ b/src/commands/pkg.rs @@ -1,14 +1,32 @@ use crate::bot::{Command, Context}; use async_trait::async_trait; +//use std::collections::HashMap; +use reqwest::Client; #[derive(Default)] pub struct Pkg { - pkg_name: String, + client: Client, +} + +impl Pkg { + pub fn new() -> Self { + Pkg { + client: Client::new(), + } + } } #[async_trait] impl Command for Pkg { - async fn execute(&mut self, msg: Context<'_>) -> anyhow::Result { - + async fn execute(&mut self, msg: Context<'_>) -> anyhow::Result { + let start = Pkg::new(); + let body = self.client + .get(format!( + "https://archlinux.org/packages/search/json/?name={:?}", + msg.content + )) + .send() + .await?.text().await?; + Ok(body) } -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index ed53ebd..d9ca789 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,6 +16,7 @@ use crate::commands::sed::Sed; use crate::commands::spotify::Spotify; use crate::commands::title::Title; use crate::commands::waifu::Waifu; +use crate::commands::pkg::Pkg; use crate::web::HttpContext; use futures_util::stream::StreamExt; use irc::client::prelude::Config; @@ -136,6 +137,7 @@ async fn main() -> anyhow::Result<()> { let search_limit = cfg.bot.search_limit.unwrap_or(3); bot.add_command("qsearch".into(), Search::new(search_limit)); bot.add_command("qnext".into(), SearchNext::new(search_limit)); + bot.add_command("pkg".into(), Pkg::default()); bot.add_trigger( Regex::new(r"^(?:(?\S+):\s+)?s/(?[^/]*)/(?[^/]*)(?:/(?[a-z]*))?\s*")?, Sed,