Help - Search - Member List - Calendar
Full Version: IRC Bot parsing
WorkTheWeb Forums > Webmaster Resources > Perl Beginner Help
Support our Sponsors!
Dave W Turner
Hi,

I started with perl not long ago. I am currently coding an IRC bot.
I have all the connect code working fine, and it sits on the channel.
At the moment, I am trying to make it respond to commands. I am
having trouble parsing the lines recieved from the IRC server - they
take the form:

:<senders host name> PRIVMSG <#channelname> :<message>

I would like to have an if statement which is true when the line
recieved is of the above form, and have variables containing the
channel and message.

At the moment I am using the if statement:
if($input =~ /m*PRIVMSG*:/i)
, but it is never true.

Thankyou very much for any help

--

Dave
All us base are belong to you.

Ing. Branislav Gerzo
[Email Removed] [dwt], on Sunday, July 3, 2005 at 15:04
(+0100) wrote about:


dwt> :<senders host name> PRIVMSG <#channelname> :<message>
dwt> At the moment I am using the if statement:
dwt> if($input =~ /m*PRIVMSG*:/i)
dwt> , but it is never true.

if message looks like this:
:somewhere.host.com PRIVMSG #channel : message

you should use for example:

if ($input =~ /^:[^s]+sPRIVMSGs+(.*?)s*:s*(.*)/) {
print "Channel:$1 Message: $2n";
}

....you should learn regexpes, they are very cool for parsing some
text.


--

...m8s, cu l8r, Brano.

[Gun Control? Ask Lorena Bobitt about knife Control!]

Stuart Adams
Just FYI, the POE::Component::IRC module on CPAN will do this all for you.

On 7/3/05, Ing. Branislav Gerzo <[Email Removed]> wrote:
QUOTE
[Email Removed] [dwt], on Sunday, July 3, 2005 at 15:04
(+0100) wrote about:


dwt> :<senders host name> PRIVMSG <#channelname> :<message
dwt> At the moment I am using the if statement:
dwt> if($input =~ /m*PRIVMSG*:/i)
dwt> , but it is never true.

if message looks like this:
:somewhere.host.com PRIVMSG #channel : message

you should use for example:

if ($input =~ /^:[^s]+sPRIVMSGs+(.*?)s*:s*(.*)/) {
print "Channel:$1 Message: $2n";
}

...you should learn regexpes, they are very cool for parsing some
text.


--

...m8s, cu l8r, Brano.

[Gun Control? Ask Lorena Bobitt about knife Control!]



--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
<http://learn.perl.org/> <http://learn.perl.org/first-response





--
-Stuart, The Digital Guerrilla
www.quickfry.com


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2005 Invision Power Services, Inc.