Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Perl (http://www.programmingforums.org/forum21.html)
-   -   perl IRC bot help :D (http://www.programmingforums.org/showthread.php?t=10185)

skanker Jun 5th, 2006 6:06 AM

perl IRC bot help :D
 
So I got the perl IRC bot at vx13d.net and modified it a bit. What i need it is to store variables that i give it through privmsg.

I can do stuff like this.


:

}
if($input =~/!quit/) {
print $sock "QUIT : Bye!\r\n";
}



But what i need is something like; I say in irc !server irc.wtf.org. The bot then stores whatever comes after !server, ie irc.wtf.org in a variable called !server. What do i need to learn to be able to do this?

Pizentios Jun 5th, 2006 10:32 AM

if you were to use Net::IRC, you can add event handlers. All you'd need to do is create a handler to handle public events (the events that happen in the room window). Something like this:

:

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

my $irc = new Net::IRC;
my $conn = $irc->newconn(Server        => 'irc.freenode.org', Port => '6667', Nick => 'Chuck-Norris', Ircname => 'Yo-Momma!');

sub on_public {
        my ($conn, $event)= @_;
              my $text = $event->{args}[0]; #what the person said.
        my $nick = $event->{nick}; #the person's nick name.
        if ($text =~ m/\!server/)
        {
                #then you would grab the text you wanted from $text here and save it.
        }
}

$conn->add_handler('public', \&on_public);

$irc->start;


Ofcourse the code above will connect to irc.freenode.org, but it will not join a room, for that you need to setup a on_connect handler, then send a join command.

You could grab the text you wanted a few different ways. you could use the function substr if you know the total length of the string you are working with (which can be obtained from the function length()). Also i am sure there is a way to get the text you need form the string using a regular expression. It's all really up to you and what your comfortable with.


All times are GMT -5. The time now is 8:01 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC