mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-28 05:32:48 +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
62 lines
1.5 KiB
Perl
Executable File
62 lines
1.5 KiB
Perl
Executable File
#!/usr/bin/perl -I /home/msmud/lib/perl5
|
|
|
|
use strict;
|
|
use WWW::Wikipedia;
|
|
use Text::Autoformat;
|
|
use Getopt::Std;
|
|
|
|
my %options;
|
|
getopts( 'l:', \%options );
|
|
|
|
my $term = join(' ', @ARGV);
|
|
|
|
if(not $term) {
|
|
print "Usage: !wikipedia <term>\n";
|
|
exit;
|
|
}
|
|
|
|
# upper-case first letter and lowercase remainder of each word
|
|
# $term =~ s/(.)(\w*)(\s?)/\u$1\l$2$3/g;
|
|
|
|
my $wiki = WWW::Wikipedia->new( language => $options{ l } || 'en' );
|
|
my $entry = $wiki->search( $term );
|
|
|
|
if ( $entry ) {
|
|
my $text = $entry->text();
|
|
|
|
if ( $text ) {
|
|
$text =~ s/[\n\r]/ /msg;
|
|
$text =~ s/\[otheruses.*?\]//gsi;
|
|
$text =~ s/\[fixbunching.*?\]//gsi;
|
|
$text =~ s/\[wiktionary.*?\]//gsi;
|
|
$text =~ s/\[TOC.*?\]//gsi;
|
|
$text =~ s/\[.*?sidebar\]//gsi;
|
|
$text =~ s/\[pp.*?\]//gsi;
|
|
$text =~ s/'''//gs;
|
|
|
|
1 while $text =~ s/{{[^{}]*}}//gs;
|
|
1 while $text =~ s/\[quote[^\]]*\]//gsi;
|
|
1 while $text =~ s/\[\[Image:[^\[\]]*\]\]//gsi;
|
|
1 while $text =~ s/\[\[(File:)?([^\[\]]*)\]\]//gsi;
|
|
|
|
$text =~ s/\[\[.*?\|(.*?)\]\]/$1/gs;
|
|
$text =~ s/\[\[(.*?)\]\]/$1/gs;
|
|
$text =~ s/<!--.*?--\s?>//gs;
|
|
$text =~ s/\s+/ /gs;
|
|
$text =~ s/^\s+//;
|
|
$text =~ s/\<.*?\>.*?\<\/.*?\>//gs;
|
|
$text =~ s/\<.*?\/\>//gs;
|
|
|
|
$text =~ s/–/-/;
|
|
|
|
print $text;
|
|
}
|
|
else {
|
|
print "Specific entry not found, see also: ";
|
|
my $semi = "";
|
|
foreach ( $entry->related() ) { print "$_$semi"; $semi = "; "; }
|
|
}
|
|
}
|
|
else { print qq("$term" not found in wikipedia\n) }
|
|
|