]> ruin.nu Git - NDIRC.git/blob - Members.pm
mved package from ND::IRC to NDIRC
[NDIRC.git] / Members.pm
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
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.                                   *
8 #                                                                         *
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.                          *
13 #                                                                         *
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::Members;
20 use strict;
21 use warnings;
22 use NDIRC::Access;
23 use ND::DB;
24 require Exporter;
25
26 our @ISA = qw/Exporter/;
27
28 our @EXPORT = qw/currentCalls showraids checkPoints findSMS/;
29
30 sub currentCalls {
31         my ($verbose) = @_;
32         DB();
33         if (1){ #TODO: add check for member
34                 my $f = $ND::DBH->prepare(<<SQL
35         SELECT (c.landing_tick - tick()) AS eta, concat(i.shiptype||'/') AS shiptype, dc.username,p.x
36         FROM calls c 
37                 JOIN incomings i ON i.call = c.id
38                 LEFT OUTER JOIN users dc ON dc.uid = c.dc
39                 JOIN users u ON u.uid = c.member
40                 JOIN current_planet_stats p ON u.planet = p.id
41         WHERE open AND (c.landing_tick - tick()) >= 7
42         GROUP BY c.id,c.landing_tick,dc.username,p.x
43         ORDER BY c.landing_tick;
44 SQL
45 );
46                 $f->execute();
47                 my $calls = "";
48                 while (my @row = $f->fetchrow()){
49                         chop($row[1]);
50                         my $dc = defined $row[2] ? $row[2] : '';
51                         $calls .= " (Anti $row[1] ETA: $row[0] Cluster: $row[3] DC: $dc) |"
52                 }
53                 chop($calls);
54                 if (defined $verbose || length $calls > 0){
55                         $ND::server->command("msg $ND::target Current calls: $calls");
56                 }
57         }
58 }
59
60 sub showraids {
61         DB();
62         if (1){ #TODO: add check for member
63                 my $f = $ND::DBH->prepare(<<SQL
64         SELECT id FROM raids 
65         WHERE open AND not removed AND tick + waves - 7 > tick()
66         AND id IN (SELECT raid FROM raid_access WHERE gid = 2)
67 SQL
68 );
69                 $f->execute();
70                 my $calls = "";
71                 while (my ($raid) = $f->fetchrow()){
72                         $calls .= " https://nd.ruin.nu/raids?raid=$raid |"
73                 }
74                 $calls = "No open future raids" if ($f->rows == 0);
75                 chop($calls);
76                 $ND::server->command("msg $ND::target $calls");
77         }
78 }
79
80 sub checkPoints {
81         my ($nick) = @_;
82         DB();
83         my $f;
84         if ($nick){
85                 if (officer() || dc() || bc()){
86                         $f = $ND::DBH->prepare("SELECT username, attack_points, defense_points, scan_points, humor_points FROM users WHERE username ILIKE ?");
87                 }else{
88                         $ND::server->command("msg $ND::target Only officers are allowed to check for others");
89                 }
90         } else{
91                 $f = $ND::DBH->prepare("SELECT username, attack_points, defense_points, scan_points, humor_points FROM users WHERE hostmask ILIKE ?");
92                 $nick = $ND::address;
93         }
94         if ($f){
95                 $f->execute($nick);
96                 while (my @row = $f->fetchrow()){
97                         $ND::server->command("msg $ND::target $row[0] has $row[1] Attack, $row[2] Defense, $row[3] Scan, $row[4] Humor points");
98                 }
99         }
100 }
101
102 sub findSMS {
103         my ($nick) = @_;
104         DB();
105         my $f;
106         if (officer() || dc()){
107                 $f = $ND::DBH->prepare("SELECT username,COALESCE(sms,'nothing added') FROM users WHERE username ILIKE ?");
108                 if (my ($username,$sms) = $ND::DBH->selectrow_array($f,undef,$nick)){
109                         $ND::server->command("notice $ND::target $ND::B$username$ND::B has sms $ND::B$sms$ND::B");
110                 }else{
111                         $ND::server->command("notice $ND::target No hit, maybe spelling mistake, or add % as wildcard");
112                 }
113         }else{
114                 $ND::server->command("notice $ND::target Only dcs and above are allowed to check for others");
115         }
116 }
117
118 1;