Do you like writing bots for irc? Well, if you have ever had trouble parsing the lines sent from the server into data you can use, I have a solution. Just use this simple OO module, which exports two methods: new, and parse_line ... new creates an object, and parse_line splits up each line from the irc server into usable data that your bot can then react to.
Have fun!
package Mind;
use strict;
use diagnostics;
use warnings;
use Data::Dumper;
sub new {
my $class = shift;
my $self = {
NICK => undef,
HOST => undef,
TYPE => undef,
CHAN => undef,
TEXT => undef
};
bless $self, $class;
return $self;
}
sub parse_line {
my $self = shift;
chop (my $line = shift);
my ($i_nick, $i_host, $i_type, $i_chan, $i_text);
($i_chan, $i_text) = split(/ :/, $line);
($i_nick, $i_type, $i_chan) = split(/ /, $line);
($i_nick, $i_host) = split(/!/, $i_nick);
$i_nick =~ s/://;
$self->{NICK} = $i_nick;
$self->{HOST} = $i_host;
$self->{TYPE} = $i_type;
$self->{CHAN} = $i_chan;
$self->{TEXT} = $i_text;
#print Dumper($self); #test
return $self;
}
#add your own method here
#to allow for your bot to
#react to things that happen
#in your channel like so:
sub interact {
#test ...
my $self = shift;
if ($self->{TEXT} =~ /hi shrax/gi && $self->{NICK} =~ /kenny/g
+i) {
my $self = "$self->{TYPE} $self->{CHAN} :$self-
+>{NICK}, it works!";
return $self;
}
if ($self->{TEXT} =~ /how are you shrax/gi && $self->{NICK} =~
+ /kenny/gi) {
my $self = "$self->{TYPE} $self->{CHAN} :$self-
+>{NICK}, I'm fine thank you!";
return $self;
}
}
1;