1 #**************************************************************************
2 # Copyright (C) 2009 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
19 package NDIRC::Delling;
39 after irc_public => sub {
40 my ($self,$sender, $who, $where, $msg) = @_[OBJECT,SENDER, ARG0 .. ARG2];
41 my ($nick,$username,$address) = ( split /[!@]/, $who );
42 my $channel = $where->[0];
44 my $irc = $sender->get_heap();
46 #$irc->yield(privmsg => $channel, "Authed? " . $irc->is_nick_authed($nick));
48 my $seen = $dbh->prepare_cached(q{UPDATE users SET laston = NOW() WHERE hostmask = ?});
49 $seen->execute($address);
51 my $nickname = $irc->nick_name;
52 if ($msg =~ /^$nickname: (.*)/i){
53 my $text = $self->hal->do_reply($1);
54 $irc->yield(privmsg => $channel, "$nick: $text");
55 }elsif ($msg =~ /^(\S+): (.+)$/ && $self->disp->has_command('anon',$channel)){
58 unless ($irc->is_channel_member($channel,$1) || /(Constructing|Researching)/){
59 $msg = ".anon $_ $text";
63 if ($self->parseCommand($msg,$irc,$nick,$address,$channel,$dbh)){
64 #Command parsed and run successfully
68 after irc_msg => sub {
69 my ($self,$sender, $who, $where, $msg) = @_[OBJECT,SENDER, ARG0 .. ARG2];
70 my ($nick,$username,$address) = ( split /[!@]/, $who );
71 my $irc = $sender->get_heap();
74 my $seen = $dbh->prepare_cached(q{UPDATE users SET laston = NOW() WHERE hostmask = ?});
75 $seen->execute($address);
77 if ($self->parseCommand($msg,$irc,$nick,$address,'pm',$dbh)){
78 #Command parsed and run successfully
80 $irc->yield(notice => $nick, "unknown command");
85 my ($self,$sender, $who, $channel) = @_[OBJECT,SENDER, ARG0 .. ARG1];
86 my ($nick,$username,$address) = ( split /[!@]/, $who );
87 my $irc = $sender->get_heap();
90 my $seen = $dbh->prepare_cached(q{UPDATE users SET laston = NOW() WHERE hostmask = ?});
91 $seen->execute($address);
93 if($self->disp->has_command('voice',$channel)){
94 my $flags = $dbh->prepare_cached(q{
97 JOIN groupmembers g USING (uid)
98 JOIN channel_group_flags gf USING (gid)
99 WHERE u.hostmask = $1 AND channel = $2 AND flag IN ('o','v');
101 $flags->execute($address, $channel);
104 while (my ($flag) = $flags->fetchrow()){
109 $irc->yield(mode => $channel, $mode, @who) if $mode;
114 my ($kernel,$heap) = @_[KERNEL,HEAP];
115 $kernel->delay( refresh => 60 );
116 print 'Time: ' . time() . ' Lag: ' . $heap->{connector}->lag() . "\n";
119 my $scans = $dbh->prepare(q{SELECT s.scan_id
120 ,array_agg(sr.nick) AS nick
121 ,array_agg(sr.id) AS id
122 FROM scan_requests sr
123 JOIN scans s USING (pid,type)
124 WHERE sr.time > NOW() - '30 min'::INTERVAL
125 AND s.tick >= sr.tick AND NOT sr.sent
128 my $sentscan = $dbh->prepare(q{UPDATE scan_requests
129 SET sent = TRUE WHERE id = ANY($1)
132 while (my $scan = $scans->fetchrow_hashref){
133 $heap->{irc}->yield(notice => $scan->{nick}, "http://game.planetarion.com/showscan.pl?scan_id=$scan->{scan_id}");
134 $sentscan->execute($scan->{id});
140 my $hal = AI::MegaHAL->new('Path' => '.', 'Banner' => 0, 'Prompt' => 0, 'Wrap' => 0, 'AutoSave' => 1);
144 after sig_usr2 => sub {
147 $self->hal->_cleanup;