pacbot/src/commands/man.rs
2019-11-11 13:45:33 +01:00

22 lines
647 B
Rust

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