CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Net::IRC problems

 



blondIE
New User

Mar 15, 2002, 2:59 PM

Post #1 of 1 (421 views)
Net::IRC problems Can't Post

Hello all. I'm having trouble with a script I'm running on my linux box. It's an IRC bot that was working when I first wrote it, but now that I've rebooted my computer and tried to run it again, it doesn't seem to work, and it issues my these two errors:

Can't connect to irc.2600.net:6667! at /usr/lib/perl5/site_perl/Net/IRC.pm line 192

Can't call method "add_handler" on unblessed reference at ./bot line 75.


Here is what my code looks like:

#!/usr/bin/perl
use Net::IRC;
use strict;

# 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 || 'irc.whatever.net',
Port => shift || '6667',
Nick => 'Bot',
Ircname => 'Bot',
Username => 'Bot');

# We're going to add this to the conn hash so we know what channel we
# want to operate in.
$conn->{channel} = shift || '#mychannel';


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;

}

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!");

}

sub on_part {

# pretty much the same as above

my ($conn, $event) = @_;

my $nick = $event->{nick};
$conn->privmsg($conn->{channel}, "Goodbye, $nick!");
}

sub on_public {
my($conn, $event) = @_;
my $text = $event->{args}[0];

if ($text eq "\U$text") {
if (length $text > 6) {
my $name_text = $event->{nick};
$conn->privmsg($event->{to}[0], "$name_text: No need to yell. Switch to lowercase and be happy. =)");
}
}

sub on_msg {
my($conn, $event) = @_;

$conn->privmsg($event->{nick}, "I, don't appreciate being /msg'd.");
}

# add event handlers for join and part events
$conn->add_handler('join', \&on_join);
$conn->add_handler('part', \&on_part);
$conn->add_handler('public', \&on_public);
$conn->add_handler('msg', \&on_msg);

# The end of MOTD (message of the day), numbered 376 signifies we've connect
$conn->add_handler('376', \&on_connect);

# start IRC
$irc->start();

_______________________

I entered irc.whatever.net for the server, because I've tried to connect it to multiple servers and it won't connect to any of them. I would think that this is simply a problem with my code, because it usually is =), but this same script was working before i rebooted my computer. Any help on this subject would be greatly appreciated, as I'm pulling my hair out over it. =)

Thanks a lot

blondIE

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives