[英]Some Simple Errors With a IRC Bot Made With Perl
我正在跟踪一个名为Perl中的IRC Bots编程的教程,以便为我在Abjects服务器上的频道制作一个简单的IRC机器人,问题是我遇到了一些奇怪的错误。 看一看:
Nathan-Camposs-MacBook-Pro:台式Nathan $ ./bot.pl
./bot.pl:第1行:使用:找不到命令
./bot.pl:第4行:my:命令未找到
./bot.pl:第8行:语法错误,出现在意外令牌('
./bot.pl: line 8:('
./bot.pl: line 8:('
我的$ conn = $ irc-> newconn('
./bot.pl: line 8:
Nathan-Camposs-MacBook-Pro:Desktop Nathan $
使用此代码:
use Net::IRC;
# create the IRC object
my $irc = new Net::IRC;
# Create a connection object. You can have more than one "connection" per
# IRC object, but we'll just be working with one.
my $conn = $irc->newconn(
Server => shift || 'summer.abjects.net',
# Note: IRC port is normally 6667, but my firewall won't allow it
Port => shift || '6667',
Nick => 'iBot',
Ircname => 'I\'ve bee built by iNathan!',
Username => 'iBot'
);
# We're going to add this to the conn hash so we know what channel we
# want to operate in.
$conn->{channel} = shift || '#MobilePassion';
sub on_connect {
# shift in our connection object that is passed automatically
my $conn = shift;
# when we connect, join our channel and greet it
$conn->join($conn->{channel});
$conn->privmsg($conn->{channel}, 'Hello everyone!');
$conn->{connected} = 1;
}
# The end of MOTD (message of the day), numbered 376 signifies we've connect
$conn->add_handler('376', \&on_connect);
sub on_join {
# get our connection object and the event object, which is passed
# with this event automatically
my ($conn, $event) = @_;
# this is the nick that just joined
my $nick = $event->{nick};
# say hello to the nick in public
$conn->privmsg($conn->{channel}, "Hello, $nick!");
}
$conn->add_handler('join', \&on_join);
$irc->start();
我该怎么做才能纠正这个问题?
#!/usr/bin/perl
在顶部。 / bin / sh通常不了解Perl,这就是您所看到的。
另外,我建议:
use strict;
use warnings;
另外,我敢肯定,您之前在某个地方已经看到并听到过此消息,但是请您自己帮个忙,不要使用Net::IRC
...自我宣传7年以来,它已经死在水里了。
新建议是使用POE::Component::IRC
或某些变体。 虽然POE::Component::IRC
为您提供了对机器人功能的最大控制,灵活性和可视性,但Bot::BasicBot
是一种更简单的方法。
希望能有所帮助。
关于http://freetexthost.com/wdmcihuvxx ,您缺少Net库。 根据您所使用的操作系统,您有多种获取方式-或仅使用CPAN。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.