ok more questions. I used your code and wrote another simular to output on "-event"
Code:
sub on_event {
# on an event, we get connection object and event hash
my ($conn, $event) = @_;
# this is what was said in the event
my $text = $event->{args}[0];
# regex the text to see if it begins with -event
# then print the values
if ($text =~ /^\-event (\d+)/) {
open (TXT, "<C:\\Perl\\clone\\files\\$1.txt");
$text = <TXT>;
close (TXT);
$conn->privmsg($event->{to}[0], "The count for $1 is $text");
}
}
$conn->add_handler('public', \&on_event);
It works good but the problem is now i cant get them to work together at the same time. Im sure im missing something(prolly an if/else statement) but i was wondering why or how to write an if/else statement when the sub's already do what i need.
Code:
#!/usr/bin/perl -w
use Net::IRC;
use Net::IRC::Event;
#use strict;
my $irc = new Net::IRC;
my $conn = $irc->newconn(
Nick => 'CloneBot2',
Server => 'irc.gameaddix.net',
Port => '6667',
Ircname => 'CloneBot2',
Username =>'CloneBot2',
Logfile => 'C:\Perl\clone\clone.log');
# We're going to add this to the conn hash so we know what channel we
# want to operate in.
$conn->{channel} = shift || '##';
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}, 'CloneBot is Online!');
$conn->{connected} = 1;
}
;
# The end of MOTD (message of the day), numbered 376 signifies we've connect
$conn->add_handler('376', \&on_connect);
#setting of public commands
sub on_count {
# on an event, we get connection object and event hash
my ($conn, $event) = @_;
# this is what was said in the event
my $text = $event->{args}[0];
# regex the text to see if it begins with -count
# then print the values
if ($text =~ /^\-count (\d+)\s(\d+)/) {
$conn->privmsg($event->{to}[0], "I received a count of $2 for server $1");
open (TXT, ">C:\\Perl\\clone\\files\\$1.txt");
print TXT "$2";
close (TXT);
}
}
$conn->add_handler('public', \&on_count);
sub on_event {
# on an event, we get connection object and event hash
my ($conn, $event) = @_;
# this is what was said in the event
my $text = $event->{args}[0];
# regex the text to see if it begins with -event
# then print the values
if ($text =~ /^\-event (\d+)/) {
open (TXT, "<C:\\Perl\\clone\\files\\$1.txt");
$text = <TXT>;
close (TXT);
$conn->privmsg($event->{to}[0], "The count for $1 is $text");
}
}
$conn->add_handler('public', \&on_event);
use Data::Dumper;
sub default {
# This is helpful to see what an event returns. Data::Dumper will
# recursively reveal the structure of any value
my ($conn, $event) = @_;
print Dumper($event);
}
# experiment with the cping event, printing out to standard output
$conn->add_handler('cping', \&default);
# start IRC
$irc->start();