开发者

Some Simple Errors With a IRC Bot Made With Perl

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 obj开发者_C百科ect
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?


#!/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;


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜