home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.urbanrage.com
/
2015-02-07.ftp.urbanrage.com.tar
/
ftp.urbanrage.com
/
pub
/
perl
/
test_plug.pl
< prev
next >
Wrap
Text File
|
2006-10-18
|
5KB
|
198 lines
# xchat script perl
use IO::All;
%colors = (
'2' => "3",
'3' => "2",
'4' => "6",
'5' => "7",
'6' => "4"
);
%color_names = (
'2' => "Green",
'3' => "Blue",
'4' => "Purple",
'5' => "Orange",
'6' => "Red"
);
IRC::register("test script", "1.0", "", "");
IRC::add_message_handler("PRIVMSG", "tryit");
IRC::add_command_handler("", "from_me");
IRC::add_command_handler("word_click", "clicked");
sub printme {
$len = @_;
IRC::print_with_channel("printme $len [$_[0]]\n","#dump");
return IRC::EAT_NONE;
}
sub clicked {
my $channel = IRC::get_info(2);
my $me = IRC::get_info(1);
my $word = shift;
$word =~ tr/[]//d;
IRC::print_with_channel("clicked: <$word>\n","#dump");
&do_query($me, $channel, 0, $word);
return 1;
}
sub from_me {
my $channel = IRC::get_info(2);
my $me = IRC::get_info(1);
my @items = ($_[0] =~ /q\[(.+?)\]/g);
#IRC::print_with_channel("from_me called $_[1], 0 = $_[0]\n","#dump");
if (@items > 0) {
&do_query($me, $channel, 2, @items);
return 1;
}
@items = ($_[0] =~ /p\[(.+?)\]/g);
#IRC::print_with_channel("from_me @items\n","#dump");
if (@items > 0) {
&do_query($me, $channel, 1, @items);
return 1;
}
return 0;
}
sub tryit {
my $me = IRC::get_info(1);
($source, $dest, $msg) = ($_[0] =~ /:(.*?)\!.* PRIVMSG (.*?) :(.*)/);
($who) = ($msg =~ /^($me).*/);
my @items = ($msg =~ /q\[(.+?)\]/g);
if (@items > 0) {
do_query($source, $dest, 2, @items);
} else {
my @items = ($msg =~ /s\[(.+?)\]/g);
if (@items > 0) {
do_query($source, $dest, 3, @items);
}
}
return IRC::EAT_NONE;
}
sub do_query {
my $source = shift;
my $dest = shift;
my $both = shift;
my $content;
my @lines;
my $line;
my $key;
my $skey;
my $ukey;
my $query;
my $thing;
my $sthing;
my @data;
my $check_source;
my $value = "";
my $color;
my $name;
my $count;
my %choices;
my $me = IRC::get_info(1);
foreach $thing (@_) {
$key = lc($thing);
if ((exists($items{$key})) && ($both < 3)) {
if ($both < 2) {
IRC::command("/gui MSGBOX \"$box_items{$key}\"");
}
if ($both > 0) {
IRC::command_with_channel("$items{$key}", $dest);
}
next;
}
($sthing = $key) =~ tr/\ //d;
$thing =~ s/(.*?)[ _]/$1\%20/g;
$query = "http://www.thottbot.com/?s=$thing";
$content < io($query);
# IRC::print_with_channel("$content\n", "#dump");
@lines = split(/\n/, $content);
$count = 0;
foreach $line (@lines) {
next if ($line !~ /class=ttb/);
($color = $line) =~ s/.*quality(.?).+/$1/;
# $line =~ s/.*?\<table.*?\>(.*?)\<\/table\>.*/$1/;
$line =~ s/.*?"<table(.*?)<\/table>".*/$1/;
@data = ($line =~ /\>([^\<]+?)(?=\<)/g);
$key = lc($data[0]);
$name = shift (@data);
$check_source = 0;
$value = $colors{$color}.$name." - ";
$box = $name."\n".$color_names{$color}."\n";
foreach $item (@data) {
$item =~ s/(.*?)\ /$1/g;
$item =~ s/(.*?)\</$1</g;
$item =~ s/(.*?)\>/$1>/g;
last if ($check_source && ($item !~ /Source/));
next if ($item =~ /^Live/);
if (($item eq "Use") || ($item eq "Equip") || ($item eq "Chance on hit")) {
$value .= $item." ";
$box .= $item." ";
} else {
$value .= $item." | ";
$box .= $item."\n";
}
last if ($item =~ /Source/);
if ($item =~ /^Item/) {
$check_source = 1;
}
}
$choices{$key} = $key;
if (!exists($items{$key})) {
$items{$key} = $value;
}
if (!exists($box_items{$key})) {
$box_items{$key} = $box;
}
$count++;
}
if ($count == 1) {
if ($both < 2) {
IRC::command("/gui MSGBOX \"$box\"");
}
if ($both > 0) {
IRC::command_with_channel("$value", $dest);
}
} elsif (($count > 1) && ($count < 25)) {
# make sure we didn't get an exact match but with white space differences
foreach $key (keys(%choices)) {
($skey = $key) =~ tr/\ //d;
if ($skey eq $sthing) {
$ukey = $key;
last;
}
}
if ($skey eq $sthing) {
IRC::command_with_channel("$items{$ukey}", $dest);
} elsif ($count < 5) {
foreach $key (keys(%choices)) {
IRC::command_with_channel("$items{$key}", $dest);
}
}
if ($me ne $source) {
IRC::command("/msg $source Any of these?");
foreach $key (keys(%choices)) {
IRC::command("/msg $source [$choices{$key}]");
}
} else {
IRC::command("/msg $source Any of those?");
IRC::print_with_channel("\n", $source);
foreach $key (keys(%choices)) {
IRC::print_with_channel("[$choices{$key}]", $source);
}
}
} elsif ($count == 0) {
IRC::command("/msg $source no matching items found");
} else {
IRC::command("/msg $source too many items to print, found $count items");
}
}
}