Add manpage queries
This commit is contained in:
parent
8111f1f877
commit
fa799fdd38
|
@ -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);
|
||||||
|
}
|
|
@ -10,6 +10,7 @@ mod nix;
|
||||||
mod pacman;
|
mod pacman;
|
||||||
mod aur;
|
mod aur;
|
||||||
mod xbps;
|
mod xbps;
|
||||||
|
mod man;
|
||||||
extern crate reqwest;
|
extern crate reqwest;
|
||||||
|
|
||||||
pub struct Handler;
|
pub struct Handler;
|
||||||
|
@ -75,6 +76,7 @@ lazy_static! {
|
||||||
command_list.push(Command::new("dnf", dnf::query_dnf));
|
command_list.push(Command::new("dnf", dnf::query_dnf));
|
||||||
command_list.push(Command::new("aur", aur::query_aur));
|
command_list.push(Command::new("aur", aur::query_aur));
|
||||||
command_list.push(Command::new("xbps", xbps::query_xbps));
|
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("pacbot help", help));
|
||||||
command_list.push(Command::new("pb help", help));
|
command_list.push(Command::new("pb help", help));
|
||||||
command_list
|
command_list
|
||||||
|
|
Loading…
Reference in New Issue
Block a user