| 1 | package Bot::IRC::Infobot; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Bot::IRC add classic "infobot" functionality to the bot | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use 5.016; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use exact; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use DateTime; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use DateTime::Format::Human::Duration; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | our $VERSION = '1.49'; # VERSION | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=5.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 1 | my ($bot) = @_; | |||||||||||||||||||||||||||
| 14 | 1 | $bot->load('Store'); | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | $bot->hook( | ||||||||||||||||||||||||||||
| 17 | { | ||||||||||||||||||||||||||||
| 18 | command => 'PRIVMSG', | ||||||||||||||||||||||||||||
| 19 | text => qr/^(?<term>\([^\)]+\)|\S+)\s+(?:is|=)\s+(?<fact>.+?)$/i, | ||||||||||||||||||||||||||||
| 20 | }, | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 22 | 0 | my ( $bot, $in, $m ) = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | ( my $term = lc( $m->{term} ) ) =~ s/[\(\)]+//g; | |||||||||||||||||||||||||||
| 25 | 0 | ▶ | my @facts = @{ $bot->store->get($term) || [] }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$bot->store->get($term) || []
MC/DC0%0/1
$bot->store->get($term) || []
$bot->store->get($term)
Truth table0%0/2
A
A= $bot->store->get($term)
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | push( @facts, $m->{fact} ); | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | $bot->store->set( $term => \@facts ); | |||||||||||||||||||||||||||
| 30 | 0 | return; | |||||||||||||||||||||||||||
| 31 | }, | ||||||||||||||||||||||||||||
| 32 | 1 | ); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | $bot->hook( | ||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | command => 'PRIVMSG', | ||||||||||||||||||||||||||||
| 37 | text => qr/^(?<term>\([^\)]+\)|\S+)\?/i, | ||||||||||||||||||||||||||||
| 38 | }, | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 40 | 0 | my ( $bot, $in, $m ) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ( my $display_term = $m->{term} ) =~ s/[\(\)]+//g; | |||||||||||||||||||||||||||
| 43 | 0 | my $term = lc($display_term); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | my @facts = map { | ||||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ( /\|/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | my @terms = split(/\|/); | |||||||||||||||||||||||||||
| 48 | 0 | $terms[ int( rand() * @terms ) ]; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | else { | ||||||||||||||||||||||||||||
| 51 | 0 | $_; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | } @{ $bot->store->get($term) || [] }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$bot->store->get($term) || []
MC/DC0%0/1
$bot->store->get($term) || []
$bot->store->get($term)
Truth table0%0/2
A
A= $bot->store->get($term)
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | return unless (@facts); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | my $text; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | if ( grep { /^<(?:action|reply)>/i } @facts ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | my $fact = $facts[ int( rand() * @facts ) ]; | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | $text = $fact if ( $fact =~ s|^<\s*action\s*>\s*|/me |i or $fact =~ s|^<\s*reply\s*>\s*||i ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$fact =~ s[^<\s*action\s*>\s*][/me ]iu or $fact =~ s/^<\s*reply\s*>\s*//iu
MC/DC0%0/2
$fact =~ s[^<\s*action\s*>\s*][/me ]iu or $fact =~ s/^<\s*reply\s*>\s*//iu
$fact =~ s[^<\s*action\s*>\s*][/me ]iu
$fact =~ s/^<\s*reply\s*>\s*//iu
Truth table0%0/3
A or B
A= $fact =~ s[^<\s*action\s*>\s*][/me ]iuB= $fact =~ s/^<\s*reply\s*>\s*//iu
| |||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | $bot->reply( | ||||||||||||||||||||||||||||
| 63 | $text // | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | "$display_term is " . $bot->list( ', ', 'and', map { s/[.,;:?!]+$//; $_ } @facts ) . '.' | ||||||||||||||||||||||||||
|
Condition0%0/2
$text // "$display_term is " . $bot->list(", ", "and", map({s/[.,;:?!]+$//u;
$_;} @facts)) . '.'
MC/DC0%0/1
$text // "$display_term is " . $bot->list(", ", "and", map({s/[.,;:?!]+$//u;
$_;} @facts)) . '.'
$text
Truth table0%0/2
A
A= $text
| |||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||
| 66 | }, | ||||||||||||||||||||||||||||
| 67 | 1 | ); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | $bot->hook( | ||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | to_me => 1, | ||||||||||||||||||||||||||||
| 72 | text => qr/^no\W+(?<term>\([^\)]+\)|\S+)\s+(?:is|=)\s+(?<fact>.+?)$/i, | ||||||||||||||||||||||||||||
| 73 | }, | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 75 | 0 | my ( $bot, $in, $m ) = @_; | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | ( my $term = lc( $m->{term} ) ) =~ s/[\(\)]+//g; | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | $bot->store->set( $term => [ $m->{fact} ] ); | |||||||||||||||||||||||||||
| 80 | 0 | $bot->reply_to('OK.'); | |||||||||||||||||||||||||||
| 81 | }, | ||||||||||||||||||||||||||||
| 82 | 1 | ); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | $bot->hook( | ||||||||||||||||||||||||||||
| 85 | { | ||||||||||||||||||||||||||||
| 86 | to_me => 1, | ||||||||||||||||||||||||||||
| 87 | text => qr/^forget\W+(?<term>\([^\)]+\)|[^.,:;?!\s]+)/i, | ||||||||||||||||||||||||||||
| 88 | }, | ||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 90 | 0 | my ( $bot, $in, $m ) = @_; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | ( my $term = lc( $m->{term} ) ) =~ s/[\(\)]+//g; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | $bot->store->set( $term => [] ); | |||||||||||||||||||||||||||
| 95 | 0 | $bot->reply_to('OK.'); | |||||||||||||||||||||||||||
| 96 | }, | ||||||||||||||||||||||||||||
| 97 | 1 | ); | |||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | $bot->hook( | ||||||||||||||||||||||||||||
| 100 | { | ||||||||||||||||||||||||||||
| 101 | to_me => 1, | ||||||||||||||||||||||||||||
| 102 | text => qr/^info\s+on\s+(?<term>\([^\)]+\)|[^.,:;?!\s]+)/i, | ||||||||||||||||||||||||||||
| 103 | }, | ||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 105 | 0 | my ( $bot, $in, $m ) = @_; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ( my $term = lc( $m->{term} ) ) =~ s/[\(\)]+//g; | |||||||||||||||||||||||||||
| 108 | 0 | ▶ | my @facts = @{ $bot->store->get($term) || [] }; | ||||||||||||||||||||||||||
|
Condition0%0/2
$bot->store->get($term) || []
MC/DC0%0/1
$bot->store->get($term) || []
$bot->store->get($term)
Truth table0%0/2
A
A= $bot->store->get($term)
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 0 | ▶ | $bot->reply_to( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | (@facts) | ||||||||||||||||||||||||||||
| 112 | ? "\"$m->{term}\" is " . $bot->list( ', ', 'and', @facts ) | ||||||||||||||||||||||||||||
| 113 | : "I have no information on \"$m->{term}\"." | ||||||||||||||||||||||||||||
| 114 | ); | ||||||||||||||||||||||||||||
| 115 | }, | ||||||||||||||||||||||||||||
| 116 | 1 | ); | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 1 | $bot->helps( infobot => | |||||||||||||||||||||||||||
| 119 | 'Mimics the factoid functionality of the classic infobot. ' . | ||||||||||||||||||||||||||||
| 120 | 'Usage: https://metacpan.org/pod/Bot::IRC::Infobot' | ||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 2 | 1; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | __END__ | ||||||||||||||||||||||||||||