mech_scripts.pl


This is currently used by mockerbot, an irc bot

no comments for now

#!/usr/bin/perl

#subroutines for doing www::mechanize routines, to be used by irc bot

use WWW::Mechanize;
use Net::IRC;
$mech = WWW::Mechanize->new();


#global for moving data
$sca1 = "";
$sca2 = "";
@arr1 = {"", ""};
@arr2 = {"", ""};



sub dictionary_com {
my ($conn, $data1) = @_;
$conn->privmsg('mocker', "loaded dictionary.com");
#rip definition off of dictionary.com
$sca1 = "";
if(!defined($data1) || length($data1) < 2){
$data1 = "idiot"; }
$mech->get( "http://dictionary.com/browse/".$data1);
$html1 = $mech->content;
open(TESTDUMP, ">/scripts/custom/dumpmech") || die "couldnt open dump";
@htmlarr = split(/
    /, $html1); @liarr = split(/
  1. /i, $htmlarr[1]); $numhtmlarr = @liarr; if($numhtmlarr > 4){ $numhtmlarr = 4; } $count1 = 0; while($count1 < $numhtmlarr -1){ $tmpli = $liarr[$count1]; $tmpli =~ s/<.*>/ /g ; $tmpli =~ s/\n/ /g ; if(length($tmpli) > 3){ $conn->privmsg($conn->{channel}, $tmpli); } $count1 +=1 ; } print TESTDUMP $htmlarr[1]; #print TESTDUMP "count = $count1 . licount = $numli . maxcount = $numhtmlarr \n $tmpli[0] \n $tmpli[1] \n $tmpli[2] "; close(TESTDUMP); }



sub google_trans {
#rip translation from google
my ($conn, $lang, $input) = @_;
if(!$conn || !$lang || !$input){
die "no input"; }
$mech->get("http://www.google.com/language_tools?hl=en");
$mech->form_number(2);
$mech->field("text", $input);
$mech->select("langpair", $lang);
$mech->submit();
$mech->form_number(1);
$dump = $mech->content;
$trans = $mech->value("q");
$conn->privmsg($conn->{channel}, "$input : $trans");

}



sub freedict_trans {
#rip translation from freedict.com
my ($conn, $lang, $input) = @_;
if(!$conn || !$lang || !$input){
die "no input"; }
$formnum = 1;
if(substr($lang,0,1) eq '2'){
$lang = substr($lang,1); $formnum = 2; }
$mech->get($lang);
$mech->form_number($formnum);
$mech->field("search", $input);
$mech->select("max", "1");
$mech->submit();
$dump = $mech->content;
@dump = split(/strong/, $dump) ;
$trans = $dump[1];
$conn->privmsg($conn->{channel}, "$input : $trans");

}



sub google_search {
#get search from google
my ($conn, $input) = @_;
if(length($input) < 2){ $input = 'idiot'; }
$mech->get("http://www.google.com");
$mech->form_number(1);
$mech->field("q", $input);
$mech->submit();
$dump = $mech->content();
$dump =~ /(.+?)<\/a>/i;
$url = $1; $title = $2;
$title =~ s/[][<\/b>]/ /g;
$conn->privmsg($conn->{channel}, "$title ($url)");

}


sub forums_latest {
#get forums latest posts

}