Add manpage queries

This commit is contained in:
kageru 2019-11-11 13:45:33 +01:00
parent 8111f1f877
commit fa799fdd38
2 changed files with 23 additions and 0 deletions

21
src/commands/man.rs Normal file
View File

@ -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);
}

View File

@ -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