#!/usr/bin/perl
#
# Let Me Google That For You
#

use strict;
use warnings;
use vars qw($VERSION %IRSSI);

my $url_base = "http://letmegooglethatforyou.com/?q=";

use Irssi qw(command_bind);
$VERSION = '1.0';
%IRSSI = (
    authors => 'cxreg',
    contact => 'cxreg@pobox.com',
    name    => 'lmgtfy',
    description => 'Let Me Google That For You',
    license => 'Public domain',
);

die "You must load tinyurl.pl first\n" unless defined &Irssi::Script::tinyurl::tinyurl;

command_bind(
    lmgtfy => sub {
      my ($msg, $server, $witem) = @_;
      my $url = $url_base . $msg;
      my $answer = Irssi::Script::tinyurl::tinyurl($url);
      if ($answer) {
        print CLIENTCRAP "$answer";
        if ($witem && ($witem->{type} eq 'CHANNEL' || $witem->{type} eq 'QUERY')) {
          $witem->command("MSG " . $witem->{name} ." ". $answer);
        }
      }
    }
);


