working
This commit is contained in:
parent
6f100adf80
commit
2642f6111f
|
@ -9,3 +9,4 @@ pub mod sed;
|
||||||
pub mod spotify;
|
pub mod spotify;
|
||||||
pub mod title;
|
pub mod title;
|
||||||
pub mod waifu;
|
pub mod waifu;
|
||||||
|
pub mod pkg;
|
|
@ -1,14 +1,32 @@
|
||||||
use crate::bot::{Command, Context};
|
use crate::bot::{Command, Context};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
//use std::collections::HashMap;
|
||||||
|
use reqwest::Client;
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Pkg {
|
pub struct Pkg {
|
||||||
pkg_name: String,
|
client: Client,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Pkg {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Pkg {
|
||||||
|
client: Client::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl Command for Pkg {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ use crate::commands::sed::Sed;
|
||||||
use crate::commands::spotify::Spotify;
|
use crate::commands::spotify::Spotify;
|
||||||
use crate::commands::title::Title;
|
use crate::commands::title::Title;
|
||||||
use crate::commands::waifu::Waifu;
|
use crate::commands::waifu::Waifu;
|
||||||
|
use crate::commands::pkg::Pkg;
|
||||||
use crate::web::HttpContext;
|
use crate::web::HttpContext;
|
||||||
use futures_util::stream::StreamExt;
|
use futures_util::stream::StreamExt;
|
||||||
use irc::client::prelude::Config;
|
use irc::client::prelude::Config;
|
||||||
|
@ -136,6 +137,7 @@ async fn main() -> anyhow::Result<()> {
|
||||||
let search_limit = cfg.bot.search_limit.unwrap_or(3);
|
let search_limit = cfg.bot.search_limit.unwrap_or(3);
|
||||||
bot.add_command("qsearch".into(), Search::new(search_limit));
|
bot.add_command("qsearch".into(), Search::new(search_limit));
|
||||||
bot.add_command("qnext".into(), SearchNext::new(search_limit));
|
bot.add_command("qnext".into(), SearchNext::new(search_limit));
|
||||||
|
bot.add_command("pkg".into(), Pkg::default());
|
||||||
bot.add_trigger(
|
bot.add_trigger(
|
||||||
Regex::new(r"^(?:(?<u>\S+):\s+)?s/(?<r>[^/]*)/(?<w>[^/]*)(?:/(?<f>[a-z]*))?\s*")?,
|
Regex::new(r"^(?:(?<u>\S+):\s+)?s/(?<r>[^/]*)/(?<w>[^/]*)(?:/(?<f>[a-z]*))?\s*")?,
|
||||||
Sed,
|
Sed,
|
||||||
|
|
Loading…
Reference in a new issue