]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/wtf.pl
ws
[infobot.git] / src / Modules / wtf.pl
1 #
2 #     wtf.pl: interface to bsd wtf
3 #     Author: Tim Riker <Tim@Rikers.org>
4 #     Source: modified from jethro's patch
5 #  Licensing: Artistic License (as perl itself)
6 #    Version: v0.1
7 #
8 #  Copyright (c) 2005 Tim Riker
9 #
10
11 package wtf;
12
13 use strict;
14
15 sub wtf::wtf {
16     my $query = shift;
17     my $binary;
18     my @binaries = ( '/usr/games/wtf', '/usr/local/bin/wtf' );
19     foreach (@binaries) {
20         if ( -x $_ ) {
21             $binary = $_;
22             last;
23         }
24     }
25     if ( !$binary ) {
26         return ("no binary found.");
27     }
28     if ( $query =~ /^$|[^\w]/ ) {
29         return ("usage: wtf <foo>.");
30     }
31     if ( !&::validExec($query) ) {
32         return ("argument appears to be fuzzy.");
33     }
34
35     my $reply = '';
36     foreach (`$binary '$query' 2>&1`) {
37         $reply .= $_;
38     }
39     $reply =~ s/\n/ /;
40     chomp($reply);
41     return ($reply);
42 }
43
44 sub wtf::query {
45     &::performStrictReply( &wtf(@_) );
46     return;
47 }
48
49 1;
50
51 # vim:ts=4:sw=4:expandtab:tw=80