diff --git a/src/commands/man.rs b/src/commands/man.rs new file mode 100644 index 0000000..46d1211 --- /dev/null +++ b/src/commands/man.rs @@ -0,0 +1,21 @@ +use crate::commands::*; +use reqwest::StatusCode; +use serenity::model::channel::Message; +use serenity::model::id::ChannelId; + +pub fn query_man(ctx: Context, msg: Message, args: Vec<&str>) { + let url = format!("https://linux.die.net/man/1/{}/", args[0]); + let response = reqwest::get(&url); + if response.is_err() { + send_not_found(msg.channel_id, &ctx); + return; + } + match response.unwrap().status() { + StatusCode::OK => send(msg.channel_id, &url, &ctx), + _ => send_not_found(msg.channel_id, &ctx), + } +} + +fn send_not_found(target: ChannelId, ctx: &Context) { + send(target, "No such manpage", ctx); +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 90350dd..6e0bd6a 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -10,6 +10,7 @@ mod nix; mod pacman; mod aur; mod xbps; +mod man; extern crate reqwest; pub struct Handler; @@ -75,6 +76,7 @@ lazy_static! { command_list.push(Command::new("dnf", dnf::query_dnf)); command_list.push(Command::new("aur", aur::query_aur)); command_list.push(Command::new("xbps", xbps::query_xbps)); + command_list.push(Command::new("man", man::query_man)); command_list.push(Command::new("pacbot help", help)); command_list.push(Command::new("pb help", help)); command_list