]> git.donarmstrong.com Git - infobot.git/blob - src/Modules/wtf.pl
* Add vim formatting comments ( # vim:ts=4:sw=4:expandtab:tw=80 )
[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 = (
19                 '/usr/games/wtf',
20                 '/usr/local/bin/wtf'
21         );
22         foreach (@binaries) {
23                 if (-x $_) {
24                         $binary=$_;
25                         last;
26                 }
27         }
28         if (!$binary) {
29                 return("no binary found.");
30         }
31         if ($query =~ /^$|[^\w]/){
32                 return("usage: wtf <foo>.");
33         }
34         if (!&::validExec($query)) {
35                 return("argument appears to be fuzzy.");
36         }
37
38         my $reply ='';
39         foreach (`$binary '$query' 2>&1`){
40                 $reply .= $_;
41         }
42         $reply =~ s/\n/ /;
43         chomp($reply);
44         return($reply);
45 }
46
47 sub wtf::query {
48         &::performStrictReply(&wtf(@_));
49         return;
50 }
51
52 1;
53
54 # vim:ts=4:sw=4:expandtab:tw=80