簡體   English   中英

Perl制作的IRC Bot的一些簡單錯誤

[英]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:
('
./bot.pl: line 8:
我的$ conn = $ irc-> newconn('

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM