4 use POE
qw(Component::IRC);
5 use Config
::INI
::Simple
;
10 GetOptions
('debug' => \
$debug);
12 if (!-e
"sql.conf" || !-e
"bot.conf") {
13 die("Error: Please make sure you have both \'sql.conf\' and \'bot.conf\' in this directory\n");
16 my $sqlConfig = new Config
::INI
::Simple
;
17 $sqlConfig->read( 'sql.conf' );
19 my $botConfig = new Config
::INI
::Simple
;
20 $botConfig->read( 'bot.conf' );
22 my $version = "0.0.1";
23 my $nickname = $botConfig->{default}->{nickname
};
24 my $server = $botConfig->{default}->{server
};
25 my $port = $botConfig->{default}->{port
};
26 my $botchan = $botConfig->{default}->{channel
}; # had to change this line from $channel because we use the variable $channel later in the public event
28 my $dsn = "dbi:mysql:". $sqlConfig->{default}->{db
} .":localhost:3306";
29 my $sql = DBI
->connect($dsn, $sqlConfig->{default}->{user
}, $sqlConfig->{default}->{passwd
}) or die "Unable to connect: $DBI::errstr\n";
31 my %stats; # hash for keeping stats locally
33 my $irc = POE
::Component
::IRC
->spawn(
35 ircname
=> "Kithairon RPG Bot",
36 username
=> $nickname,
38 ) or die "Oh noooo! $!";
42 main
=> [ qw(_start irc_001 irc_public irc_msg) ],
44 heap
=> { irc
=> $irc },
49 my $irc = $heap->{irc
};
50 $irc->yield( register
=> 'all' );
51 $irc->yield( connect => { Flood
=> '1' } ); # disables the flood-throttle in POE - should come in handy
59 open(STDIN
, '>', '/dev/null');
60 open(STDOUT
, '>', '/dev/null');
61 open(STDERR
, '>', '/dev/null');
62 if(fork()) { exit(0) }
65 daemonize
() if !defined($debug);
70 my $sender = $_[SENDER
];
71 my $irc = $sender->get_heap();
72 print "Connected to ", $irc->server_name(), "\n" if defined($debug);
73 $irc->yield( join => $botchan );
74 print "Joining $botchan\n" if defined($debug);
79 my ($sender, $who, $where, $what) = @_[SENDER
, ARG0
.. ARG2
];
80 my $nick = ( split /!/, $who )[0];
81 my $channel = $where->[0];
82 print "$nick:$channel> $what\n" if defined($debug);
86 my ($who, $msg) = @_[ARG0
, ARG2
];
87 my $nick = (split /!/,$who)[0];
88 print "$nick> $msg\n" if defined($debug);
89 if ($msg =~ /^\.register$/) {
90 if (!registered
($nick)) {
91 $irc->yield(privmsg
=> $nick => "[Register] Welcome to Kithairon, $nick. To begin, you must choose a card pack.");
98 return defined($stats{$nick}{registered
});