我正在尝试制作 Jabber 机器人,但在等待消息时无法保持其运行。如何让我的脚本连续运行?我尝试调用一个子程序,该子程序有一个 while 循环,理论上我已经设置它来检查任何消息并做出相应的反应,但我的脚本并没有那样做。
这是我的来源: http: //pastebin.com/03Habbvh
# 设置 jabber bot 回调
$jabberBot->SetMessageCallBacks(chat=>\&chat);
$jabberBot->SetPresenceCallBacks(available=>\&welcome,unavailable=>\&killBot);
$jabberBot->SetCallBacks(receive=>\&prnt,iq=>\&gotIQ);
$jabberBot->PresenceSend(type=>"available");
$jabberBot->进程(1);
子欢迎
{
打印“欢迎!\n”;
$jabberBot->MessageSend(to=>$jbrBoss->GetJID(),subject=>"",body=>"你好!",type=>"chat",priority=>10);
&保持下去;
}
子打印
{
打印 $_[1]."\n";
}
#$jabberBot->MessageSend(to=>$jbrBoss->GetJID(),subject=>"",body=>"Hello There! Global...",type=>"chat",priority=>10);
#$jabberBot->进程(5);
#&保持下去;
子聊天
{
我的 ($sessionID,$msg) = @_;
$dump->pl2xml($msg);
if($msg->GetType() ne 'get' && $msg->GetType() ne 'set' && $msg->GetType() ne '')
{
我的 $jbrCmd = &trimSpaces($msg->GetBody());
我的 $dbQry = $dbh->prepare("SELECT command,acknowledgement FROM commands WHERE message = '".lc($jbrCmd)."'");
$dbQry->执行();
if($dbQry->rows() > 0 && $jbrCmd !~ /^insert/si)
{
我的 $ref = $dbQry->fetchrow_hashref();
$dbQry->完成();
$jabberBot->MessageSend(to=>$msg->GetFrom(),subject=>"",body=>$ref->{'acknowledgement'},type=>"chat",priority=>10);
评估 $ref->{'command'};
&保持下去;
}
别的
{
$jabberBot->MessageSend(to=>$msg->GetFrom(),subject=>"",body=>"我没听懂你!",type=>"chat",priority=>10);
$dbQry->完成();
&保持下去;
}
}
}
子得到IQ
{
打印“iq\n”;
}
子修剪空间
{
我的 $string = $_[0];
$string =~ s/^\s++//; #删除前导空格
$string =~ s/\s+$//; #删除尾随空格
返回$字符串;
}
子 keepItGoing
{
打印 "keepItGoing!\n";
我的 $proc = $jabberBot->Process(1);
而(定义($proc)&& $proc!= 1)
{
$proc = $jabberBot->进程(1);
}
}
子杀戮机器人
{
打印“杀戮\n”;
$jabberBot->MessageSend(to=>$_[0]->GetFrom(),subject=>"",body=>"注销!",type=>"chat",priority=>10);
$jabberBot->进程(1);
$jabberBot->断开连接();
出口;
}