Jabber 봇을 만들려고하는데 메시지를 기다리는 동안 계속 실행하는 데 문제가 있습니다. 스크립트를 계속 실행하려면 어떻게해야합니까? while 루프를 가지고있는 서브 루틴을 호출 해 보았습니다. 이론적으로는 메시지를 확인하고 그에 따라 반응하도록 설정했지만 스크립트는 그런 식으로 행동하지 않습니다. http://pastebin.com/03HabbvhPerl Jabber 봇을 이벤트 기반 프로그램으로 만들려면 어떻게해야합니까?
# set jabber bot callbacks $jabberBot->SetMessageCallBacks(chat=>\&chat); $jabberBot->SetPresenceCallBacks(available=>\&welcome,unavailable=>\&killBot); $jabberBot->SetCallBacks(receive=>\&prnt,iq=>\&gotIQ); $jabberBot->PresenceSend(type=>"available"); $jabberBot->Process(1); sub welcome { print "Welcome!\n"; $jabberBot->MessageSend(to=>$jbrBoss->GetJID(),subject=>"",body=>"Hello There!",type=>"chat",priority=>10); &keepItGoing; } sub prnt { print $_[1]."\n"; } #$jabberBot->MessageSend(to=>$jbrBoss->GetJID(),subject=>"",body=>"Hello There! Global...",type=>"chat",priority=>10); #$jabberBot->Process(5); #&keepItGoing; sub chat { my ($sessionID,$msg) = @_; $dump->pl2xml($msg); if($msg->GetType() ne 'get' && $msg->GetType() ne 'set' && $msg->GetType() ne '') { my $jbrCmd = &trimSpaces($msg->GetBody()); my $dbQry = $dbh->prepare("SELECT command,acknowledgement FROM commands WHERE message = '".lc($jbrCmd)."'"); $dbQry->execute(); if($dbQry->rows() > 0 && $jbrCmd !~ /^insert/si) { my $ref = $dbQry->fetchrow_hashref(); $dbQry->finish(); $jabberBot->MessageSend(to=>$msg->GetFrom(),subject=>"",body=>$ref->{'acknowledgement'},type=>"chat",priority=>10); eval $ref->{'command'}; &keepItGoing; } else { $jabberBot->MessageSend(to=>$msg->GetFrom(),subject=>"",body=>"I didn't understand you!",type=>"chat",priority=>10); $dbQry->finish(); &keepItGoing; } } } sub gotIQ { print "iq\n"; } sub trimSpaces { my $string = $_[0]; $string =~ s/^\s+//; #remove leading spaces $string =~ s/\s+$//; #remove trailing spaces return $string; } sub keepItGoing { print "keepItGoing!\n"; my $proc = $jabberBot->Process(1); while(defined($proc) && $proc != 1) { $proc = $jabberBot->Process(1); } } sub killBot { print "killing\n"; $jabberBot->MessageSend(to=>$_[0]->GetFrom(),subject=>"",body=>"Logging Out!",type=>"chat",priority=>10); $jabberBot->Process(1); $jabberBot->Disconnect(); exit; }
내 루프가 지금 사용하고있는 것이지만 iq 패킷과 메시지 패킷을 받으면 엉망이됩니다. – cskwrd