3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-10-01 17:16:39 +02:00

Minor whitespace syntax clean-up throughout

This commit is contained in:
Pragmatic Software 2019-05-28 09:19:42 -07:00
parent 00618c5502
commit 925a5e57bd
130 changed files with 1045 additions and 1204 deletions

View File

@ -419,7 +419,7 @@ sub expand_factoid_vars {
my $debug = 0;
my $depth = 0;
while (1) {
last if ++$depth >= 100;
last if ++$depth >= 1000;
my $offset = 0;
my $matches = 0;

View File

@ -314,7 +314,11 @@ sub remindme {
}
}
print "alarm: $alarm\n";
my ($length, $error) = parsedate($alarm);
print "length: $length, error: $error!\n";
return $error if $error;
# I don't know how I feel about enforcing arbitrary time restrictions

View File

@ -29,6 +29,8 @@ sub parsedate {
my $parse = Time::ParseDate::parsedate($input, NOW => $now);
print "parsedate: now => $now, input => $input, parse => $parse\n";
if (not defined $parse) {
$input =~ s/\s+$//;
return (0, "I don't know what '$input' means. I expected a time duration like '5 minutes' or '24 hours' or 'next tuesday'.\n");

View File

@ -224,7 +224,7 @@ if($comma eq "") {
print "p" . $found_paragraph if $paragraph_specified;
=cut
# print "\nhttp://blackshell.com/~msmud/n1570.html\#$found_section";
print "\nhttp://www.iso-9899.info/n1570.html\#$found_section";
print "http://www.iso-9899.info/n1570.html\#$found_section";
print "p" . $found_paragraph if $paragraph_specified;
print "\n\n";
print "[", $found_section_title, "]\n\n" if length $found_section_title;

View File

@ -218,7 +218,7 @@ if($matches > 1 and not $list_only) {
}
if ($comma eq "") {
print "\nhttp://www.iso-9899.info/n1256.html\#$found_section";
print "http://www.iso-9899.info/n1256.html\#$found_section";
print "p" . $found_paragraph if $paragraph_specified;
print "\n\n";
print "[", $found_section_title, "]\n\n" if length $found_section_title;

View File

@ -12,7 +12,8 @@
use warnings;
use strict;
use IO::Socket;
use IO::Socket::INET;
use JSON;
my $sock = IO::Socket::INET->new(
PeerAddr => '192.168.0.42',
@ -24,22 +25,20 @@ if(not defined $sock) {
die $!;
}
my $nick = shift @ARGV;
my $channel = shift @ARGV;
my $code = join ' ', @ARGV;
my $json = join ' ', @ARGV;
my $h = decode_json $json;
#$code = "{ $code";
$code =~ s/\s*}\s*$//;
my $lang = "c11";
$h->{code} =~ s/\s*}\s*$//;
my $lang = $h->{lang} // "c11";
if ($code =~ s/-lang=([^ ]+)//) {
$lang = lc $1;
}
print $sock "compile:$nick:$channel:$lang\n";
print $sock "$code\n";
print $sock "compile:end\n";
$h->{lang} = $lang;
$json = encode_json $h;
print $sock "$json\n";
while (my $line = <$sock>) {
print "$line";

View File

@ -26,6 +26,10 @@ if(not defined $sock) {
}
my $json = join ' ', @ARGV;
my $length = length $json;
print STDERR "got $length bytes of argv json: [$json]\n";
my $h = decode_json $json;
my $lang = $h->{lang} // "c11";
@ -36,7 +40,11 @@ if ($h->{code} =~ s/-lang=([^ ]+)//) {
$h->{lang} = $lang;
$json = encode_json $h;
print $sock "$json\n";
$length = length $json;
print STDERR "got $length bytes of json: [$json]\n";
syswrite($sock, "$json\n");
while (my $line = <$sock>) {
print "$line";

View File

@ -74,15 +74,19 @@ sub execute {
local $SIG{ALRM} = sub { print "Time out\n"; kill 9, $pid; print "sent KILL to $pid\n"; die "Timed-out: $result\n"; };
alarm($COMPILE_TIMEOUT);
print "Reading...\n";
while(my $line = <$fh>) {
print "read [$line]\n";
$result .= $line;
}
close $fh;
print "Done reading.\n";
my $ret = $? >> 8;
alarm 0;
#print "[$ret, $result]\n";
print "[$ret, $result]\n";
return ($ret, $result);
};
@ -94,6 +98,7 @@ sub execute {
return ($ret, $result);
} else {
waitpid($child, 0);
print "?: $?\n";
my $result = $? >> 8;
print "child exited, parent continuing [result = $result]\n";
return (undef, $result);
@ -247,6 +252,7 @@ sub compiler_server {
close $client;
print "timed out: $timed_out; killed: $killed\n";
next unless ($timed_out or $killed);
vm_reset;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;
use feature "switch";
@ -423,8 +419,7 @@ sub execute {
my $got_result = 0;
while(my $line = <$compiler_output>) {
#print STDERR "Read [$line]\n";
print STDERR "Read [$line]\n";
$line =~ s/[\r\n]+$//;
last if $line =~ /^result:end$/;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;
@ -20,8 +16,6 @@ sub initialize {
$self->{options_nopaste} = '-fno-diagnostics-show-caret';
$self->{cmdline} = 'gcc -ggdb -g3 $sourcefile $options -o $execfile';
$self->{default_options} .= ' -Werror' if defined $self->{nick} && $self->{nick} =~ m/marchelz/i;
$self->{prelude} = <<'END';
#define _XOPEN_SOURCE 9001
#define __USE_XOPEN

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;
@ -20,7 +16,7 @@ sub initialize {
$self->{options_nopaste} = '-fno-diagnostics-show-caret';
$self->{cmdline} = 'gcc -ggdb -g3 $sourcefile $options -o $execfile';
$self->{default_options} .= ' -Werror' if defined $self->{nick} && $self->{nick} =~ m/marchelz/i;
# $self->{default_options} .= ' -Werror' if defined $self->{nick} && $self->{nick} =~ m/marchelz/i;
$self->{prelude} = <<'END';
#define _XOPEN_SOURCE 9001

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;
@ -20,7 +16,7 @@ sub initialize {
$self->{options_nopaste} = '-fno-diagnostics-show-caret';
$self->{cmdline} = 'gcc -ggdb -g3 $sourcefile $options -o $execfile';
$self->{default_options} .= ' -Werror' if defined $self->{nick} && $self->{nick} =~ m/marchelz/i;
# $self->{default_options} .= ' -Werror' if defined $self->{nick} && $self->{nick} =~ m/marchelz/i;
$self->{prelude} = <<'END';
#define _XOPEN_SOURCE 9001

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;
@ -15,10 +11,10 @@ sub initialize {
$self->{sourcefile} = 'prog.c';
$self->{execfile} = 'prog';
$self->{default_options} = '-Wextra -Wall -Wno-unused -Wno-unused-parameter -pedantic -Wfloat-equal -Wshadow -std=c11 -lm -Wfatal-errors -fsanitize=integer,undefined,address,alignment';
$self->{default_options} = '-Wextra -Wall -Wno-unused -Wno-unused-parameter -pedantic -Wfloat-equal -Wshadow -std=c11 -lm -Wfatal-errors -fsanitize=integer,undefined,alignment';
$self->{options_paste} = '-fcaret-diagnostics';
$self->{options_nopaste} = '-fno-caret-diagnostics';
$self->{cmdline} = 'clang-3.7 -ggdb -g3 $sourcefile $options -o $execfile';
$self->{cmdline} = 'clang -ggdb -g3 $sourcefile $options -o $execfile';
$self->{prelude} = <<'END';
#define _XOPEN_SOURCE 9001

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;
@ -15,10 +11,10 @@ sub initialize {
$self->{sourcefile} = 'prog.c';
$self->{execfile} = 'prog';
$self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c89 -lm -Wfatal-errors -fsanitize=integer,undefined,alignment,address';
$self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c89 -lm -Wfatal-errors -fsanitize=integer,undefined,alignment';
$self->{options_paste} = '-fcaret-diagnostics';
$self->{options_nopaste} = '-fno-caret-diagnostics';
$self->{cmdline} = 'clang-3.7 -ggdb -g3 $sourcefile $options -o $execfile';
$self->{cmdline} = 'clang -ggdb -g3 $sourcefile $options -o $execfile';
$self->{prelude} = <<'END';
#define _XOPEN_SOURCE 9001

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;
@ -15,10 +11,10 @@ sub initialize {
$self->{sourcefile} = 'prog.c';
$self->{execfile} = 'prog';
$self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c99 -lm -Wfatal-errors -fsanitize=integer,undefined,alignment,address';
$self->{default_options} = '-Wextra -Wall -Wno-unused -pedantic -Wfloat-equal -Wshadow -std=c99 -lm -Wfatal-errors -fsanitize=integer,undefined,alignment';
$self->{options_paste} = '-fcaret-diagnostics';
$self->{options_nopaste} = '-fno-caret-diagnostics';
$self->{cmdline} = 'clang-3.7 -ggdb -g3 $sourcefile $options -o $execfile';
$self->{cmdline} = 'clang -ggdb -g3 $sourcefile $options -o $execfile';
$self->{prelude} = <<'END';
#define _XOPEN_SOURCE 9001

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;
use feature "switch";

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/env perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -1,9 +1,5 @@
#!/usr/bin/perl
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
use warnings;
use strict;

View File

@ -3,4 +3,4 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
~/pbot/modules/lookupbot.pl compliment $*
~/pbot/modules/lookupbot.pl compliment "$*"

View File

@ -10,12 +10,12 @@ use strict;
use WWW::Google::CustomSearch;
use HTML::Entities;
my $api_key = '';
my $cx = '';
my $api_key = 'AIzaSyCps6lKe6-WGvPawx7BphCYb-xM0rdevKQ';
my $cx = '003394693865260357751:kmvdeoslok4';
my ($nick, $arguments, $matches);
$matches = 3;
$matches = 1;
$nick = shift @ARGV;
if ($#ARGV < 0) {

View File

@ -22,6 +22,9 @@ my $arguments = join("%20", @ARGV);
$arguments =~ s/\W$//;
exit if $arguments =~ m{https?://git}i;
exit if $arguments =~ m{https://.*swissborg.com}i;
exit if $arguments =~ m{https://matrix.org}i;
exit if $arguments =~ m{https://freenode.net/news/spam-shake}i;
exit if $arguments =~ m{https://twitter.com/ISCdotORG}i;
exit if $arguments =~ m{https://evestigatorsucks.com}i;
@ -153,6 +156,9 @@ if($distance / $length < 0.75) {
}
exit if $t !~ m/\s/; # exit if title is only one word -- this isn't usually interesting
exit if $t =~ m{christel}i;
exit if $t =~ m{freenode}i;
exit if $t =~ m{ico scam}i;
exit if $t =~ m{Freenode head of infrastructure}i;
exit if $t =~ m{ISC on Twitter}i;
exit if $t =~ m{spambot.*freenode}i;

View File

@ -3,4 +3,4 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
~/pbot/modules/lookupbot.pl horoscope $*
~/pbot/modules/lookupbot.pl horoscope "$*"

View File

@ -3,4 +3,4 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
~/pbot/modules/lookupbot.pl horrorscope $*
~/pbot/modules/lookupbot.pl horrorscope "$*"

View File

@ -5,6 +5,7 @@ use LWP::Simple;
use LWP::UserAgent;
use Encode qw/ decode is_utf8 /;
use CGI qw/escape unescapeHTML/;
use HTML::Entities;
use utf8;
my $VERSION = '1.0.2';
@ -158,7 +159,7 @@ sub urban_search {
}
}
return $definition;
return decode_entities($definition);
}
##
@ -427,6 +428,8 @@ sub horoscope_search {
return "No results found; signs of the Zodiac are Aquarius, Pisces, Aries, Taurus, Gemini, Cancer, Leo, Virgo, Libra, Scorpio, Sagittarius, Capricorn";
}
$line =~ s/<ins class.*$//;
return $line;
}

View File

@ -28,8 +28,8 @@ my $orig_arguments = $arguments;
$arguments =~ s/(the )*answer.*question of life(,? the universe,? and everything)?\s?/42/gi;
$arguments =~ s/(the )*meaning of (life|existence|everything)?/42/gi;
if ($arguments =~ s/([^ ]+)\s+to\s+([^ ]+)\s*$//) {
@conversion = ($1, $2);
if ($arguments =~ s/(\d+\s?)([^ ]+)\s+to\s+([^ ]+)\s*$/$1/) {
@conversion = ($2, $3);
}
if ($arguments =~ m/([\$`\|{}"'#@=?\[\]])/ or $arguments =~ m/(~~)/) {

View File

@ -51,6 +51,11 @@ if (@$args == 0) {
close $fh;
}
if ($args =~ m/afroman/) {
print "Oh fuck off.\n";
exit;
}
my $ud = WebService::UrbanDictionary->new;
my $results = $ud->request($args);
@ -66,7 +71,12 @@ sub sort_entries {
}
}
my @entries = sort sort_entries @{ $results->definitions };
my @entries;
if (defined $sort) {
@entries = sort sort_entries @{ $results->definitions };
} else {
@entries = @{ $results->definitions };
}
my $num_entries = @entries;
if ($num_entries == 0) {
@ -100,7 +110,7 @@ sub show_definition {
$entry->{'example'} =~ s/\[(.*?)\]/$1/g if $entry->{'example'};
print "(+$entry->{'thumbs_up'}/-$entry->{'thumbs_down'}) $entry->{'definition'}\n";
print "$entry->{'example'}\n" if $entry->{'example'};
print "«$entry->{'example'}»\n" if $entry->{'example'};
}
if (defined $show_all or defined $match) {
@ -110,7 +120,8 @@ if (defined $show_all or defined $match) {
for my $each (@entries) {
$n++;
if (defined $match) {
my $def = $each->{'definition'} . "\n" . $each->{'example'};
my $def = $each->{'definition'} . "\n";
$def .= "«$each->{'example'}»" if $each->{'example'};
next if $def !~ m/$match/im;
}
show_definition($each, $n);

View File

@ -6,11 +6,8 @@
use strict;
use WWW::Wikipedia;
use Text::Autoformat;
use Getopt::Std;
my %options;
getopts( 'l:', \%options );
use HTML::Parse;
use HTML::FormatText;
my $term = join(' ', @ARGV);
@ -19,47 +16,27 @@ if(not $term) {
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 $wiki = WWW::Wikipedia->new(language => '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/&ndash;/-/;
$text =~ s/{{.*?}}//msg;
$text =~ s/\[\[//g;
$text =~ s/\]\]//g;
$text =~ s/<ref>.*?<\/ref>//g;
$text =~ s/__[A-Z]+__//g;
$text =~ s/\s+\(\)//msg;
$text = HTML::FormatText->new->format(parse_html($text));
print $text;
}
else {
} else {
print "Specific entry not found, see also: ";
my $semi = "";
foreach ( $entry->related() ) { print "$_$semi"; $semi = "; "; }
foreach ($entry->related()) { print "$semi$_"; $semi = "; "; }
}
} else {
print qq("$term" not found in Wikipedia\n)
}
else { print qq("$term" not found in wikipedia\n) }