#!/usr/bin/perl -w
my
$pid
= $$;
substr
(
$pid
, 0, 1) =
''
while
length
(
$pid
) > 3;
my
$nick
=
'eliza'
.
$pid
;
my
$name
=
'eliza'
.
$pid
;
my
$eliza
= Chatbot::Eliza->new();
sub
_start {
my
(
$kernel
,
$session
) =
@_
[KERNEL, SESSION];
$_
[HEAP] =
$_
[ARG0];
$_
[HEAP]->yield(
'register'
,
'all'
);
$_
[HEAP]->yield(
'connect'
, { }
);
}
sub
irc_001 {
my
(
$kernel
) =
$_
[KERNEL];
$_
[HEAP]->yield(
'mode'
,
$nick
,
'+i'
);
$_
[HEAP]->yield(
'join'
,
$ARGV
[2] ||
'#IRC.pm'
);
$_
[HEAP]->yield(
'away'
,
'JOSHUA SCHACTER IST MEIN GELEESCHAUMGUMMIRING DER LIEBE!'
);
}
sub
_stop {
my
(
$kernel
) =
$_
[KERNEL];
print
"Control session stopped.\n"
;
$_
[HEAP]->call(
'quit'
,
'Neenios on ice!'
);
}
sub
irc_disconnected {
my
(
$server
) =
$_
[ARG0];
print
"Lost connection to server $server.\n"
;
}
sub
irc_error {
my
$err
=
$_
[ARG0];
print
"Server error occurred! $err\n"
;
}
sub
irc_socketerr {
my
$err
=
$_
[ARG0];
print
"Couldn't connect to server: $err\n"
;
}
sub
irc_kick {
my
(
$kernel
,
$who
,
$where
,
$isitme
,
$reason
) =
@_
[KERNEL, ARG0 .. ARG4];
if
(
$isitme
eq
$nick
) {
print
"Kicked from $where by $who: $reason\n"
;
}
}
sub
irc_public {
my
(
$kernel
,
$who
,
$where
,
$msg
) =
@_
[KERNEL, ARG0 .. ARG2];
my
$nick
= (
split
/!/,
$who
)[0];
print
"<$nick:@{$where}[0]> $msg\n"
;
$_
[HEAP]->yield(
privmsg
=>
$where
,
$eliza
->transform(
$msg
)
);
}
my
(
$object
) = POE::Component::IRC->spawn(
Debug
=> 1,
Nick
=>
$nick
,
Server
=>
$ARGV
[0] ||
'irc.rhizomatic.net'
,
Port
=>
$ARGV
[1] || 6667,
Username
=>
$name
,
Ircname
=>
'Ask me about my colon!'
) or
die
"Can't instantiate new IRC component!\n"
;
POE::Session->new(
'main'
=>
[
qw( _start _stop irc_001 irc_kick irc_disconnected
irc_error irc_socketerr irc_public
)
],
[
$object
],
);
$poe_kernel
->run();
exit
0;