From 5398773e1b199e43c9b8f8676ea5df586d25dc94 Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Wed, 22 Jun 2011 17:53:01 +0200 Subject: [PATCH] add wolfram alpha (!alpha) command --- brmd/brmd.pl | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/brmd/brmd.pl b/brmd/brmd.pl index bd03595..096bf84 100755 --- a/brmd/brmd.pl +++ b/brmd/brmd.pl @@ -1,10 +1,12 @@ #!/usr/bin/perl # 2011 (c) Petr Baudis , brmlab +# 2011 (c) Pavol Rusnak , brmlab # You can distribute this under the same terms as Perl itself. use strict; use warnings; use POE; +use WWW::WolframAlpha; our $channel = "#brmlab"; our $streamurl = "http://video.hrach.eu:8090/brmstream.asf"; @@ -538,10 +540,30 @@ sub irc_public { my $nick = ( split /!/, $who )[0]; my $channel = $where->[0]; - if ( my ($rot13) = $what =~ /^rot13 (.+)/ ) { + if ( my ($rot13) = $what =~ /^!rot13 (.+)/ ) { $rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M]; $irc->yield( privmsg => $channel => "$nick: $rot13" ); } + + if ( my ($alpha) = $what =~ /^!alpha (.+)/ ) { + my $answer = ''; + my $wa = WWW::WolframAlpha->new ( appid => 'P6XPHG-URK5HXVWXL', ); + my $query = $wa->query( input => $alpha, ); + if ($query->success) { + foreach my $pod (@{$query->pods}) { + if (!$pod->error) { + foreach my $subpod (@{$pod->subpods}) { + if ($subpod->plaintext) { + $answer += ($pod->title . ': ') if $pod->title; + $answer += ($subpod->title . ': ') if $subpod->title; + $answer += ($subpod->plaintext . "\n"); + } + } + } + } + } + $irc->yield( privmsg => $channel => $answer ) if $answer; + } } sub irc_332 {