Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Perl IRC bot  (Read 3185 times)

0 Members and 1 Guest are viewing this topic.

camerongray

    Topic Starter


    Expert
  • Thanked: 306
    • Yes
    • Cameron Gray - The Random Rambings of a Computer Geek
  • Certifications: List
  • Computer: Specs
  • Experience: Expert
  • OS: Mac OS
Perl IRC bot
« on: August 15, 2009, 06:16:27 AM »
I recently wrote an IRC bot in perl and it works except for the fact that it will not respond to pings. I have posted the code below so can you please tell me the code and where to insert it.

Thanks

Cameron Gray

Code: [Select]
#!/usr/bin/perl -w

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          => 'irc.mibbit.com',
        Port            => '6667',
        Nick            => 'WelcomeBot',
        Ircname         => 'WelcomeBot v1.0',
        Username        => 'WelcomeBotv1.0'
);

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

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};
        my $channel = $conn->{channel};
        # say hello to the nick in public
        $conn->privmsg($conn->{channel}, "Hello $nick - Welcome to $channel -  $
        # Remember to make line above only on one line after editing
}

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

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

# start IRC
$irc->start();

Thanks in advance
Cameron Gray

P.S. DO NOT tell me to stop using Net::IRC like everyone else is  :P

You should see my bot in #bots on irc.mibbit.com - It is called WelcomeBot and will say
Quote
<WelcomeBot> Hello [NICK] - Welcome to #Bots -  Have fun! :)