3 #**************************************************************************
4 # Copyright (C) 2009 by Michael Andreen <harvATruinDOTnu> *
6 # This program is free software; you can redistribute it and/or modify *
7 # it under the terms of the GNU General Public License as published by *
8 # the Free Software Foundation; either version 2 of the License, or *
9 # (at your option) any later version. *
11 # This program is distributed in the hope that it will be useful, *
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 # GNU General Public License for more details. *
16 # You should have received a copy of the GNU General Public License *
17 # along with this program; if not, write to the *
18 # Free Software Foundation, Inc., *
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 #**************************************************************************
25 use POE qw(Component::IRC::Qnet::State);
27 use POE::Component::IRC::Plugin::Logger;
28 use POE::Component::IRC::Plugin::BotTraffic;
29 use POE::Component::IRC::Plugin::Connector;
30 use POE::Component::IRC::Plugin::DCC;
34 use NDIRC::Dispatcher;
38 use NDIRC::CommonStates;
40 my $nickname = 'ndbot';
41 my $ircname = 'ND test bot';
42 my $server = 'irc.netgamers.org';
44 # We create a new PoCo-IRC object
45 my $irc = POE::Component::IRC::Qnet::State->spawn(
49 servers => [$server, 'underworld.no.eu.netgamers.org', ]
50 ) or die "Oh noooo! $!";
52 $irc->service_bots(QBOT => 'P@cservice.netgamers.org');
54 $irc->plugin_add( 'BotTraffic', POE::Component::IRC::Plugin::BotTraffic->new() );
55 $irc->plugin_add( 'DCC', POE::Component::IRC::Plugin::DCC->new() );
56 $irc->plugin_add('Logger', POE::Component::IRC::Plugin::Logger->new(
63 Strip_formatting => 1,
67 my $TICK = $DBH->selectrow_array('SELECT tick()');
69 $ND::scanchan = '#testarmer';
70 $ND::defchan = '#testarlite';
71 $ND::memchan = '#testarmer';
75 'NDIRC::CommonStates' => [ qw(_default _start irc_001 sig_DIE signal_handler irc_disconnected irc_invite) ],
76 main => [ qw(irc_public irc_msg refresh sig_usr2 irc_join) ],
78 heap => { irc => $irc},
87 my $disp = new NDIRC::Dispatcher;
89 $disp->load(qw/Basic SMS Channel Def Intel Members PA Quotes Usermgm/);
91 open CHANNELS, 'channels';
94 my ($chan, @types) = split /\s+/;
96 $disp->add_channel($chan,\@types);
100 $heap->{disp} = $disp;
105 my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
106 my ($nick,$username,$address) = ( split /[!@]/, $who );
107 my $channel = $where->[0];
109 my $irc = $sender->get_heap();
111 #$irc->yield(privmsg => $channel, "Authed? " . $irc->is_nick_authed($nick));
113 if ($msg =~ /^(\S+): (.+)$/ && $heap->{disp}->has_command('anon',$channel)){
116 unless ($irc->is_channel_member($channel,$1) || /(Constructing|Researching)/){
117 $msg = ".anon $_ $text";
121 if (parseCommand($msg,$irc,$nick,$address,$channel,$heap->{disp},DB())){
122 #Command parsed and run successfully
128 my ($sender, $heap, $who, $where, $msg) = @_[SENDER, HEAP, ARG0 .. ARG2];
129 my ($nick,$username,$address) = ( split /[!@]/, $who );
130 my $irc = $sender->get_heap();
132 if (parseCommand($msg,$irc,$nick,$address,'pm',$heap->{disp},DB())){
133 #Command parsed and run successfully
138 my ($sender, $heap, $who, $channel) = @_[SENDER, HEAP, ARG0 .. ARG1];
139 my ($nick,$username,$address) = ( split /[!@]/, $who );
140 my $irc = $sender->get_heap();
142 if($heap->{disp}->has_command('voice',$channel)){
144 my $flags = $dbh->prepare_cached(q{
147 JOIN groupmembers g USING (uid)
148 JOIN channel_group_flags gf USING (gid)
149 WHERE u.hostmask = $1 AND channel = $2 AND flag IN ('o','v');
151 $flags->execute($address, $channel);
154 while (my ($flag) = $flags->fetchrow()){
159 $irc->yield(mode => $channel, $mode, @who) if $mode;
164 my ($kernel,$heap) = @_[KERNEL,HEAP];
165 print 'Time: ' . time() . ' Lag: ' . $heap->{connector}->lag() . "\n";
166 $kernel->delay( refresh => 60 );