Enhanced WolframAlpha output display, limit number of lines

This commit is contained in:
Petr Baudis 2011-08-29 21:59:53 +02:00
parent 3812b24d11
commit ec3cabebf0

View file

@ -473,6 +473,7 @@ sub web_alphasign_set {
package brmd::IRC; package brmd::IRC;
use POE qw(Component::IRC Component::IRC::Plugin::Connector); use POE qw(Component::IRC Component::IRC::Plugin::Connector);
use URI;
sub new { sub new {
my $class = shift; my $class = shift;
@ -549,20 +550,35 @@ sub irc_public {
my $wa = WWW::WolframAlpha->new ( appid => 'P6XPHG-URK5HXVWXL', ); my $wa = WWW::WolframAlpha->new ( appid => 'P6XPHG-URK5HXVWXL', );
my $query = $wa->query( input => $alpha, ); my $query = $wa->query( input => $alpha, );
if ($query->success) { if ($query->success) {
foreach my $pod (@{$query->pods}) { my $first = 1;
my $npods = 3;
foreach my $pod (@{$query->pods}[0..$npods-1]) {
$pod or next;
if (!$pod->error) { if (!$pod->error) {
my @answers;
push @answers, $pod->title if $pod->title;
foreach my $subpod (@{$pod->subpods}) { foreach my $subpod (@{$pod->subpods}) {
if ($subpod->plaintext) { if ($subpod->plaintext) {
my $answer = ''; my $sanswer = '';
$answer .= ($pod->title . ': ') if $pod->title; $sanswer .= ($subpod->title . ': ') if $subpod->title;
$answer .= ($subpod->title . ': ') if $subpod->title; $sanswer .= $subpod->plaintext;
$answer .= $subpod->plaintext; push @answers, split (/\n+/, $sanswer);
$answer =~ s/\n/, /g; }
}
if ($first) {
my $sanswer = URI->new("http://www.wolframalpha.com/input/?i=$alpha")->as_string;
$sanswer .= " (trimmed)" if (@{$query->pods} > $npods);
push @answers, $sanswer;
$first = 0;
}
my $answer = join(" \3"."14::\3 ", @answers);
$irc->yield( privmsg => $channel => "$nick: $answer" ); $irc->yield( privmsg => $channel => "$nick: $answer" );
} else {
$irc->yield( privmsg => $channel => "$nick: Error " . $pod->error->code . ": " . $pod->error->msg );
} }
} }
} } else {
} $irc->yield( privmsg => $channel => "$nick: No results." );
} }
} }
} }