use
5.014;
our
$VERSION
=
'1.28'
;
sub
init {
my
(
$bot
) =
@_
;
$bot
->load(
'Store'
);
$bot
->hook(
{
command
=>
'PRIVMSG'
,
text
=>
qr/^(?<term>\([^\)]+\)|\S+)\s+(?:is|=)\s+(?<fact>.+?)$/
i,
},
sub
{
my
(
$bot
,
$in
,
$m
) =
@_
;
(
my
$term
=
lc
(
$m
->{term} ) ) =~ s/[\(\)]+//g;
my
@facts
= @{
$bot
->store->get(
$term
) || [] };
push
(
@facts
,
$m
->{fact} );
$bot
->store->set(
$term
=> \
@facts
);
return
;
},
);
$bot
->hook(
{
command
=>
'PRIVMSG'
,
text
=>
qr/^(?<term>\([^\)]+\)|\S+)\?/
i,
},
sub
{
my
(
$bot
,
$in
,
$m
) =
@_
;
(
my
$display_term
=
$m
->{term} ) =~ s/[\(\)]+//g;
my
$term
=
lc
(
$display_term
);
my
@facts
=
map
{
if
( /\|/ ) {
my
@terms
=
split
(/\|/);
$terms
[
int
(
rand
() *
@terms
) ];
}
else
{
$_
;
}
} @{
$bot
->store->get(
$term
) || [] };
return
unless
(
@facts
);
my
$text
;
if
(
grep
{ /^<(?:action|reply)>/i }
@facts
) {
my
$fact
=
$facts
[
int
(
rand
() *
@facts
) ];
$text
=
$fact
if
(
$fact
=~ s|^<\s
*action
\s*>\s*|/me |i or
$fact
=~ s|^<\s
*reply
\s*>\s*||i );
}
$bot
->reply(
$text
//
"$display_term is "
.
$bot
->list(
', '
,
'and'
,
map
{ s/[.,;:?!]+$//;
$_
}
@facts
) .
'.'
);
},
);
$bot
->hook(
{
to_me
=> 1,
text
=>
qr/^no\W+(?<term>\([^\)]+\)|\S+)\s+(?:is|=)\s+(?<fact>.+?)$/
i,
},
sub
{
my
(
$bot
,
$in
,
$m
) =
@_
;
(
my
$term
=
lc
(
$m
->{term} ) ) =~ s/[\(\)]+//g;
$bot
->store->set(
$term
=> [
$m
->{fact} ] );
$bot
->reply_to(
'OK.'
);
},
);
$bot
->hook(
{
to_me
=> 1,
text
=>
qr/^forget\W+(?<term>\([^\)]+\)|[^.,:;?!\s]+)/
i,
},
sub
{
my
(
$bot
,
$in
,
$m
) =
@_
;
(
my
$term
=
lc
(
$m
->{term} ) ) =~ s/[\(\)]+//g;
$bot
->store->set(
$term
=> [] );
$bot
->reply_to(
'OK.'
);
},
);
$bot
->hook(
{
to_me
=> 1,
text
=>
qr/^info\s+on\s+(?<term>\([^\)]+\)|[^.,:;?!\s]+)/
i,
},
sub
{
my
(
$bot
,
$in
,
$m
) =
@_
;
(
my
$term
=
lc
(
$m
->{term} ) ) =~ s/[\(\)]+//g;
my
@facts
= @{
$bot
->store->get(
$term
) || [] };
$bot
->reply_to(
(
@facts
)
?
"\"$m->{term}\" is "
.
$bot
->list(
', '
,
'and'
,
@facts
)
:
"I have no information on \"$m->{term}\"."
);
},
);
$bot
->helps(
infobot
=>
'Mimics the factoid functionality of the classic infobot. '
.
);
}
1;