mirror of
https://github.com/pragma-/pbot.git
synced 2024-11-05 11:39:34 +01:00
73b793295b
todo! multi-channel support pathetic (note 12/08/09, fixed multi-channel for anti-flood and for ignore) todo! most of this crap needs to be refactored (note 11/23/09, refactored execute_module) 0.4.1 (12/08/09): improved anti-flood system to be significantly more accurate and per-channel added per-nick-per-channel message history using %flood_watch add per-channel support to ignore system automatically remove message history for nicks that haven't spoken in one day (run once per hour) do not ignore !login command 0.3.16(11/23/09): refactored module execution to execute_module() subroutine added trigger to execute get_title.pl module when URL is detected in regular untriggered chat 0.3.15(11/20/09): replace 'me' with '$nick' in arguments
86 lines
1.4 KiB
Perl
Executable File
86 lines
1.4 KiB
Perl
Executable File
#!/usr/bin/perl -w -I /home/msmud/lib/lib/perl5/site_perl/5.10.0/
|
|
|
|
# quick and dirty by :pragma
|
|
|
|
use strict;
|
|
use LWP::UserAgent;
|
|
|
|
my ($defint, $phrase, $text, $entry, $entries, $i);
|
|
my @defs;
|
|
|
|
if ($#ARGV < 0)
|
|
{
|
|
print "What phrase would you like to define?\n";
|
|
die;
|
|
}
|
|
|
|
$phrase = join("+", @ARGV);
|
|
|
|
$entry = 1;
|
|
|
|
if($phrase =~ m/([0-9]+)\+(.*)/)
|
|
{
|
|
$entry = $1;
|
|
$phrase = $2;
|
|
}
|
|
|
|
my $ua = LWP::UserAgent->new;
|
|
$ua->agent("howdy");
|
|
my $response = $ua->get("http://www.google.com/search?q=define:$phrase");
|
|
$phrase =~ s/\+/ /g;
|
|
|
|
if (not $response->is_success) {
|
|
exit(1);
|
|
}
|
|
|
|
$text = $response->content;
|
|
if($text =~ m/No definitions were found/i)
|
|
{
|
|
print "No entry found for '$phrase'. ";
|
|
print "\n";
|
|
exit 1;
|
|
}
|
|
|
|
print "$phrase: ";
|
|
|
|
$i = $entry;
|
|
|
|
while($i <= $entry + 5)
|
|
{
|
|
if($text =~ m/<li>(.*?)<br>/gs)
|
|
{
|
|
push @defs, $1;
|
|
}
|
|
$i++;
|
|
}
|
|
|
|
my %uniq = map { $_ => 1 } @defs;
|
|
@defs = keys %uniq;
|
|
|
|
my $comma = "";
|
|
|
|
for($i = 1; $i <= $#defs + 1; $i++) {
|
|
|
|
# and now for some fugly beautifying regexps...
|
|
|
|
my $quote = chr(226) . chr(128) . chr(156);
|
|
my $quote2 = chr(226) . chr(128) . chr(157);
|
|
my $dash = chr(226) . chr(128) . chr(147);
|
|
|
|
$_ = $defs[$i-1];
|
|
|
|
s/$quote/"/g;
|
|
s/$quote2/"/g;
|
|
s/$dash/-/g;
|
|
s/<b>Pronun.*?<BR>//gsi;
|
|
s/<.*?>//gsi;
|
|
s/\ \;/ /gi;
|
|
s/\&.*?\;//g;
|
|
s/\r\n//gs;
|
|
s/\( P \)//gs;
|
|
s/\s+/ /gs;
|
|
|
|
print "$i) $_$comma";
|
|
$comma = ", ";
|
|
}
|