| 1 | package Bot::BasicBot::Pluggable::Module::NatTrivia; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Bot::BasicBot::Pluggable::Module; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use LWP::Simple; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use vars qw( @ISA $VERSION ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | @ISA = qw(Bot::BasicBot::Pluggable::Module); | |||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | $VERSION = '0.01_2'; | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | my $cmds = qr/nattrivia/; | |||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | my $ua = LWP::UserAgent->new; | |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | $ua->timeout(10); | |||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | my ($topic, $question, $answer); | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my $tries = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | my $channel; | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | my $running = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | my $counter = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | my %players; | |||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | sub told { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
told: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | my ( $self, $mess ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | my $bot = $self->bot(); | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # we must be directly addressed | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | if !( ( defined $mess->{address} && $mess->{address} eq $bot->nick() ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | || $mess->{channel} eq 'msg' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $mess->{"address"} and $mess->{"address"} eq $bot->nick or $mess->{"channel"} eq "msg"
defined $mess->{"address"} and $mess->{"address"} eq $bot->nick
MC/DC0%0/3
defined $mess->{"address"} and $mess->{"address"} eq $bot->nick or $mess->{"channel"} eq "msg"
defined $mess->{"address"}
$mess->{"address"} eq $bot->nick
$mess->{"channel"} eq "msg"
Truth table0%0/5
A and B or C
A= defined $mess->{"address"}B= $mess->{"address"} eq $bot->nickC= $mess->{"channel"} eq "msg"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # ignore people we ignore | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | return if $bot->ignore_nick( $mess->{who} ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $reply; | |||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | my $msg = $mess->{body}; | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ($msg =~ m/\s*nattrivia\s+(\w+)/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my $opt = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($opt =~ m/start/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ($question or $running) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$question or $running
MC/DC0%0/2
$question or $running
$question
$running
Truth table0%0/3
A or B
A= $questionB= $running
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $reply = 'Pergunta ou jogo já a decorrer...'; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | return $reply; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $running = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | %players = (); | |||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $channel = $mess->{channel}; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $bot->say({channel=>$mess->{channel},body=>"[NatTrivia] Jogo a começar em ".$mess->{channel}.", uma pergunta por minuto"}); | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ($opt =~ m/stop/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($running) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $res; | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | foreach (keys %players) { | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | $res .= "$_:".$players{$_}." "; | |||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $bot->say({channel=>$mess->{channel},body=>"[NatTrivia] Jogo terminado em ".$mess->{channel}.", resultados: $res"}); | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $running = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $question = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $running = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | $reply = 'Jogo não está a decorrer!'; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | return $reply; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($running and $question) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$running and $question
MC/DC0%0/2
$running and $question
$running
$question
Truth table0%0/3
A and B
A= $runningB= $question
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $request = HTTP::Request->new(POST => 'http://eremita.di.uminho.pt:3000/verify'); | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | $request->content_type("text/xml; charset=utf-8"); | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $request->content("<question>$question</question><answer>$msg</answer>"); | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | print STDERR "###\n<question>$question</question><answer>$msg</answer>\n###\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $response = $ua->request($request); | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if ($response =~ /correcto/i) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $question = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $reply = 'certo!'; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $players{$mess->{who}}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | return $reply; | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 87 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $reply = "resposta errada ($msg)"; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | return $reply; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub tick { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tick: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $bot = $self->bot(); | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | return unless $running; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $counter++; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($question and $counter >= 12) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$question and $counter >= 12
MC/DC0%0/2
$question and $counter >= 12
$question
$counter >= 12
Truth table0%0/3
A and B
A= $questionB= $counter >= 12
| |||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | $bot->say({channel=>$channel,body=>"[NatTrivia] Acabou o tempo, resposta correcta era: $answer"}); | |||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $question = ''; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | $counter = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if ($counter > 12) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $counter = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | ▶ | return if $question; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | return unless $running; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $xml = get 'http://eremita.di.uminho.pt:3000/random'; | |||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | ▶ | utf8::decode($xml) unless utf8::is_utf8($xml); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $xml =~ m/<topic>(.*?)<\/topic>/i; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $topic = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $xml =~ m/<question>(.*?)<\/question>/i; | |||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | $question = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | print STDERR "Q $question\n"; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $xml =~ m/<answer>(.*?)<\/answer>/i; | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $answer = $1; | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | my $x = $answer; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $x =~ s/\S/_/g; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $bot->say({channel=>$channel,body=>"[NatTrivia] ($topic) $question$x"}); | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | ▶ | sub help {'trivia [start|stop] to control the game'} | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
help: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | Bot::BasicBot::Pluggable::Module::NatTrivia - IRC frontend to NatTrivia | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||
| 144 | < you> bot: nattrivia on | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | < you> bot: nattrivia off | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | XXX | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||
| 151 | =head1 IRC USAGE | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | XXX | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||
| 155 | =head2 Commands | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | The robot understand the following subcommands: | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||
| 161 | =item * nattrivia [on|off] | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | XXXX | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | =back | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||
| 169 | Nuno Carvalho, C<< <smash@cpan.org> >> | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | José Joao Almeida, C<<jj@di.uminho.pt>> | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||||||||||||||||||||
| 176 | C<bug-bot-basicbot-pluggable-module-corelist@rt.cpan.org>, or through | ||||||||||||||||||||||||||||||||||||||||||||||
| 177 | the web interface at L<http://rt.cpan.org/>. I will be notified, and | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | then you'll automatically be notified of progress on your bug as I | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | make changes. | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | Copyright 2011 Nuno Carvalho. | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||