使用 Perl 制作的 IRC 机器人的一些简单错误

发布于 2024-10-14 17:12:44 字数 1886 浏览 10 评论 0原文

我正在遵循一个名为 Programming IRC Bots In Perl 的教程,为 Abjects 服务器上的频道制作一个简单的 IRC 机器人,问题是我遇到了一些奇怪的错误。看一下:

Nathan-Camposs-MacBook-Pro:桌面 Nathan$ ./bot.pl
./bot.pl:第 1 行:使用:找不到命令
./bot.pl:第 4 行:我的:找不到命令
./bot.pl:第 8 行:意外标记附近出现语法错误 ('
./bot.pl: 第 8 行:
my $conn = $irc->newconn('
Nathan-Camposs-MacBook-Pro:台式机 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();

我应该做什么来纠正这个问题?

I'm following a tutorial called Programming IRC Bots In Perl to make a simple IRC bot for my channel at Abjects server, the problem is that I'm getting some weird errors. Take a look:

Nathan-Camposs-MacBook-Pro:Desktop Nathan$ ./bot.pl
./bot.pl: line 1: use: command not found
./bot.pl: line 4: my: command not found
./bot.pl: line 8: syntax error near unexpected token ('
./bot.pl: line 8:
my $conn = $irc->newconn('
Nathan-Camposs-MacBook-Pro:Desktop Nathan$

With this code:

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();

What should I do to correct this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冰雪之触 2024-10-21 17:12:44
#!/usr/bin/perl

在顶部。 /bin/sh 通常不理解 Perl,这就是您所看到的。

另外,我会推荐:

use strict;
use warnings;
#!/usr/bin/perl

at the top. /bin/sh doesn't generally understand Perl, which is what you're seeing.

Also, I would recommend:

use strict;
use warnings;
还在原地等你 2024-10-21 17:12:44

另外,我确信您以前在某处见过和听说过这一点,但帮自己一个忙,不要使用 Net::IRC...它已经死在水中一段时间​​了自我宣传7年。

新的建议是使用 POE::Component::IRC 或某些变体。虽然 POE::Component::IRC 为您提供了对机器人功能的最大控制、灵活性和可见性,但更简单的方法是 Bot::BasicBot

希望有帮助。

In addition, and I'm sure you've seen and heard this before somewhere, but do yourself a favor and don't use Net::IRC... It's been dead in the water for a self advertised 7 years.

The new recommendation is to use POE::Component::IRC or some variant. While POE::Component::IRC offers you the most control, flexibility, and visibility into the functions of the bot, a much easier approach is Bot::BasicBot.

Hope that helps.

念三年u 2024-10-21 17:12:44

参考 http://freetexthost.com/wdmcihuvxx,您缺少 Net 库。根据您使用的操作系统,您可以通过多种方式获取它 - 或者仅使用 CPAN。

In reference to http://freetexthost.com/wdmcihuvxx, you're missing the Net library. Depending on which OS you're on you have multiple ways of getting it - or just use CPAN.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文