4 use POE
qw(Component::IRC);
7 use vars
qw($botnick $server $botchan);
10 use Cwd qw( abs_path getcwd );
12 my %consts = ( CWD
=> getcwd
(), PREFIX
=> dirname
(abs_path
($0)), );
14 import constant
(\
%consts);
20 use Kith
::Conf
qw($botnick $nickpass $server $port $serverpass $botchan); # Grab the variables we need from the conf module
21 use Kith::Stats::Registration;
22 use Kith::Stats::Cards;
23 use Kith::Stats::Battle;
26 GetOptions ('debug' => \$debug);
28 if (!-e "config/bot.conf") {
29 die("Error: Please make sure you have both \'sql.conf\' and \'bot.conf\' in this directory\n");
32 my $version = "0.0.1";
34 our %stats; # Hash for keeping stats locally. This will probably get moved in a few days.
36 our $irc = POE::Component::IRC->spawn(
38 ircname => "Kithairon RPG Bot",
41 password => $serverpass,
42 ) or die "Oh noooo! $!";
46 main => [ qw(_start irc_001 irc_public irc_msg irc_notice) ],
48 heap
=> { irc
=> $irc },
53 my $irc = $heap->{irc
};
54 $irc->yield( register
=> 'all' );
55 $irc->yield( connect => { Flood
=> '1' } ); # disables the flood-throttle in POE - should come in handy
63 open(STDIN
, '>', '/dev/null');
64 open(STDOUT
, '>', '/dev/null');
65 open(STDERR
, '>', '/dev/null');
66 if(fork()) { exit(0) }
69 daemonize
() if !defined($debug);
74 my $sender = $_[SENDER
];
75 my $irc = $sender->get_heap();
76 print "Connected to ", $irc->server_name(), "\n" if defined($debug);
77 $irc->yield( join => $botchan );
78 print "Joining $botchan\n" if defined($debug);
83 my ($sender, $who, $where, $what) = @_[SENDER
, ARG0
.. ARG2
];
84 my $nick = ( split /!/, $who )[0];
85 my $channel = $where->[0];
86 print "$nick:$channel> $what\n" if defined($debug);
89 my ($who, $target, $msg) = @_[ARG0
.. ARG2
];
90 my $nick = (split /!/,$who)[0];
91 print "NOTICE:$nick> $msg\n" if defined($debug);
92 if ($nick eq "NickServ" && $msg =~ /msg nickserv identify/i) {
93 $irc->yield(privmsg
=> NickServ
=> "identify $nickpass") if $nickpass ne "";
97 my ($who, $msg) = @_[ARG0
, ARG2
];
98 my $nick = (split /!/,$who)[0];
99 print "$nick> $msg\n" if defined($debug);
100 if ($msg =~ /^\.register$/i) {
101 if (!chk_registered
($nick)) {
102 $irc->yield(privmsg
=> $nick => "[Register] Welcome to Kithairon, $nick. To begin, you must choose a card pack.");
103 $irc->yield(privmsg
=> $nick => "[Register] Each pack comes with a boost in whichever stat the name of the pack falls under. Choose one of the following card packs by typing \037.pack packname\037");
104 $irc->yield(privmsg
=> $nick => "[Register] \002Attack\002, \002spirit\002, or \002speed\002");
107 $irc->yield(privmsg
=> $nick => "[Error] You are already registered.");
110 if ($msg =~ /^\.pack (attack|spirit|speed)$/i) {
111 if (!chk_registered
($nick)) {
112 $irc->yield(privmsg
=> $nick => "[Register] You have chosen the $1 pack. Please wait while your information is recorded.");
116 $irc->yield(privmsg
=> $nick => "[Error] You have already chosen your pack, and are already registered.");
119 if ($msg =~ /^\.hand$/i) {
120 if (chk_registered
($nick)) {
124 $irc->yield(privmsg
=> $nick => "[Error] You need to be registered first.");
127 if ($msg =~ /^\.battle (.+)$/i) {
129 if ($nick ne $nick2) {
130 if (chk_registered
($nick) && chk_registered
($nick2)) {
131 if (!chk_battle
($nick) && !chk_battle
($nick2)) {
132 initiate_challenge
($nick,$nick2);
133 $irc->yield(privmsg
=> $nick => "[Battle] You have requested a battle with \002$nick2\002. This request will expire in \002one minute\002.");
134 $irc->yield(privmsg
=> $nick2 => "[Battle] \002$nick\002 has requested a battle! Type \002.accept\002 or \002.decline\002");
136 elsif (chk_battle
($nick)) {
137 $irc->yield(privmsg
=> $nick => "[Error] You are currently in a battle.");
139 elsif (chk_battle
($nick2)) {
140 $irc->yield(privmsg
=> $nick => "[Error] Your opponent is in a battle.");
144 $irc->yield(privmsg
=> $nick => "[Error] You or your opponent may not be registered.");
148 if ($msg =~ /^\.accept$/i) {
149 if (chk_battle
($nick)) {
150 if (chk_opponent
($nick) ne "" && chk_turn
($nick) eq "deciding") {
151 my $nick2 = chk_opponent
($nick);
152 start_battle
($nick,$nick2);
153 $irc->yield(privmsg
=> $nick2 => "[Battle] Your opponent has accepted the challenge. The battle will now begin. Showing extended hand information.");
154 $irc->yield(privmsg
=> $nick => "[Battle] The battle will now begin. Showing extended hand information.");
155 show_hand_ext
($nick);
156 show_hand_ext
($nick2);
159 elsif (!chk_battle
($nick)) {
160 $irc->yield(privmsg
=> $nick => "[Error] You are not currently in a battle.");
163 if ($msg =~ /^\.decline$/i) {
164 if (chk_battle
($nick)) {
165 if (chk_opponent
($nick) ne "") {
166 my $nick2 = chk_opponent
($nick);
167 stop_challenge
($nick,$nick2);
168 $irc->yield(privmsg
=> $nick => "[Battle] You have declined the challenge.");
169 $irc->yield(privmsg
=> $nick2 => "[Battle] Your opponent has declined the challenge.");
172 $irc->yield(privmsg
=> $nick => "[Error] This is not your opponent.");