![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jun 2006
Posts: 1
Rep Power: 0
![]() |
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? Last edited by skanker; Jun 5th, 2006 at 5:21 AM. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() |
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.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|