This commit is contained in:
gallant 2022-08-06 17:49:06 -05:00
parent 6f100adf80
commit 2642f6111f
3 changed files with 25 additions and 4 deletions

View file

@ -9,3 +9,4 @@ pub mod sed;
pub mod spotify;
pub mod title;
pub mod waifu;
pub mod pkg;

View file

@ -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<String> {
async fn execute(&mut self, msg: Context<'_>) -> anyhow::Result<String> {
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)
}
}
}

View file

@ -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"^(?:(?<u>\S+):\s+)?s/(?<r>[^/]*)/(?<w>[^/]*)(?:/(?<f>[a-z]*))?\s*")?,
Sed,