CPAN::Forum
POE-Component-IRC - threading
| Posted on Sat Jan 7 20:51:55 2006 by dmitrykit |
| threading |
|
hello all,
i'm truing to make irc BOT with perl, but, how can i make it multithreading?
its not work, any one can help?
use strict;
use POE;
use POE::Component::IRC;
use Term::ANSIColor qw(:constants);
use Win32::Console::ANSI; $Term::ANSIColor::AUTORESET = 1;
use Config::Tiny;
use Socket;
use IO::Socket;
use Data::Dumper;
#use Win32::MMF;
use threads;
use threads::shared;
POE::Component::IRC->new("irc_client");
POE::Session->new ( _start => \&irc_start,
irc_join => \&irc_join,
irc_part => \&irc_part,
irc_nick => \&irc_nick,
irc_quit => \&irc_quit,
irc_376 => \&irc_connect, #end of motd
irc_372 => \&irc_motd,
irc_353 => \&irc_names,
irc_public => \&irc_pub_msg,
irc_msg => \&irc_privmsg, );
sub irc_start {
# KERNEL, HEAP, and SESSION are constants exported by POE
my $kernel = $_[KERNEL];
my $heap = $_[HEAP];
my $session = $_[SESSION];
$kernel->refcount_increment( $session->ID(), "my bot");
$kernel->post(irc_client=> register=> "all");
$kernel->post(irc_client=>connect=> { Nick => 'ircbot024',
Username => 'username',
Ircname => 'noname',
Server => 'irc.sexnarod.ru',
Port => '6667',
}
);
}
sub irc_connect {
my $kernel = $_[KERNEL];
$kernel->post(irc_client=>join=>'#main');
}
sub irc_motd {
my $msg = $_[ARG1];
print "MOTD: $msg\n";
}
sub irc_names {
my $names = (split /:/, $_[ARG1])[1];
my $channel = (split /:/, $_[ARG1])[0];
$channel =~ s/[@|=] (.*?) /$1/;
print "#-> Users on $channel [ $names ]\n";
}
#nick change
sub irc_nick {
my $oldnick = (split /!/, $_[ARG0])[0];
my $newnick = $_[ARG1];
print "#-> $oldnick is now known as $newnick\n";
}
#user parted
sub irc_part {
my $nick = (split /!/, $_[ARG0])[0];
my $channel = $_[ARG1];
print "#-> $nick has parted $channel\n";
}
#user joined
sub irc_join {
my $nick = (split /!/, $_[ARG0])[0];
my $channel = $_[ARG1];
print "#-> $nick has joined $channel\n";
}
#user quit
sub irc_quit {
my $nick = $_[ARG0];
my $reason = $_[ARG1];
print "#-> $nick has quit ($reason)\n";
}
sub irc_pub_msg{
return 1;
my $kernel = $_[KERNEL];
my $nick = (split /!/, $_[ARG0])[0];
my $channel = $_[ARG1]->[0];
my $msg = $_[ARG2];
#print "$channel: <$nick> $msg\n";
}
sub irc_privmsg{
#irc_msg
#Sent whenever you receive a PRIVMSG command that was addressed to
#you privately. ARG0 is the nick!hostmask of the sender. ARG1 is an
#array reference containing the nick(s) of the recipients. ARG2 is
#the text of the message.
my $kernel = $_[KERNEL];
my $nick = (split /!/, $_[ARG0])[0];
#my $channel = $_[ARG1]->[0];
my $msg = $_[ARG2];
print "PRIVMSG: <$nick> $msg\n";
#my $thread = threads->create("parse_answer",$nick,$msg,$kernel);
#$thread->detach;
&parse_answer($nick,$msg,$kernel);
}
#start everything
$poe_kernel->run();
sub parse_answer{
my($nick,$msg,$kernel)=@_;
# $kernel->post(irc_client=>connect=> { Nick => 'ircbot024',
# Username => 'username',
# Ircname => 'noname',
# Server => 'irc.sexnarod.ru',
# Port => '6667',
# }
# $kernel->post( 'irc_client', 'msg', 'KIT_','blia' );
# $kernel->yield( privmsg => 'KIT_', $msg );
my $CHANNELa = '#main';
#$kernel->post(irc_client=>join=>'#huj');
sleep(10);
$_[KERNEL]->post( irc_client => privmsg => $nick =>
"[discarded $msg messages]" );
}
any one can help? i need add big processing engine, and nedd to use multithread.. with possibility answer back to user...
|
| Write a response |
(3)
]