]> ruin.nu Git - NDIRC.git/blob - Commands/Members.pm
b1f4da9a998bf8aa083a829063810a8c1ff1d18a
[NDIRC.git] / Commands / Members.pm
1 #**************************************************************************
2 #   Copyright (C) 2009 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
20 package NDIRC::Commands::Members;
21
22 use strict;
23 use warnings;
24 use feature ':5.10';
25
26 use Moose;
27 use MooseX::MethodAttributes;
28
29 sub def
30         : Help(Show current calls)
31         : Type(member)
32 {
33         my ($self,$c,$msg) = @_;
34         my $f = $c->model->prepare(q{
35 SELECT (c.landing_tick - tick()) AS eta
36         ,array_to_string(array_agg(i.shiptype),'/') AS shiptype
37         ,dc.username
38 FROM calls c
39         JOIN incomings i USING (call)
40         LEFT OUTER JOIN users dc ON dc.uid = c.dc
41 WHERE status = 'Open' AND (c.landing_tick - tick()) >= 7
42 GROUP BY call,c.landing_tick,dc.username
43 ORDER BY c.landing_tick;
44                 });
45         $f->execute();
46         my $calls = "";
47         while (my @row = $f->fetchrow()){
48                 my $dc = $row[2] // '';
49                 $calls .= " (Anti $row[1] ETA: $row[0] DC: $dc) |"
50         }
51         chop($calls);
52         if ($msg ne 'q' || length $calls > 0){
53                 $c->reply("Current calls: $calls");
54         }
55 }
56
57 sub raids
58         : Help(List currently open raids)
59         : Type(member)
60 {
61         my ($self,$c,$msg) = @_;
62
63         my $f = $c->model->prepare(q{
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 = 'M')
67                 });
68         $f->execute();
69         my $calls = "";
70         while (my ($raid) = $f->fetchrow()){
71                 $calls .= " https://nd.ruin.nu/raids/view/$raid |"
72         }
73         $calls = "No open future raids" if ($f->rows == 0);
74         chop($calls);
75         $c->reply($calls);
76 }
77
78 sub points
79         : Help(syntax: .points [nick] | not everyone have access to check for others.)
80 {
81         my ($self,$c,$msg) = @_;
82         my $f;
83         my $nick = $c->host;
84         if ($msg =~ /(\S+)/ && $c->check_user_roles(qw/irc_points_others/)){
85                 $nick = $1;
86                 $f = $c->model->prepare(q{
87 SELECT username, attack_points, defense_points, scan_points, humor_points
88 FROM users WHERE username ILIKE ? LIMIT 5
89                 });
90         }else{
91                 $f = $c->model->prepare(q{
92 SELECT username, attack_points, defense_points, scan_points, humor_points
93 FROM users WHERE hostmask ILIKE ?
94                 });
95         }
96         $f->execute($nick);
97         while (my @row = $f->fetchrow()){
98                 $c->reply("$row[0] has $row[1] Attack, $row[2] Defense, $row[3] Scan, $row[4] Humor points");
99         }
100 }
101
102 sub sms
103         : Help(syntax: .sms nick | % can be used for wildcards %arro% will match barrow)
104         : ACL(irc_sms)
105 {
106         my ($self,$c,$msg) = @_;
107         my ($nick) = $msg =~ /(\S+)/ or die 'ARGS';
108         my $f = $c->model->prepare(q{
109 SELECT username,COALESCE(sms,'nothing added'), call_if_needed, timezone, sms_note
110         ,to_char(NOW() AT TIME ZONE timezone,'HH24:MI') AS time
111 FROM users WHERE username ILIKE ?
112                 });
113         if (my ($username,$sms, $call, $timezone, $note, $time) = $c->model->selectrow_array($f,undef,$nick)){
114                 $call = $call ?  'Wake up if needed' : 'Do not wake up';
115                 $c->reply("<b>$username</b> has sms <b>$sms</b>, $call, <b>$time</b> ($timezone), $note ");
116         }else{
117                 $c->reply("No hit, maybe spelling mistake, or add % as wildcard");
118         }
119 }
120
121 sub links
122         : Help(Shows link to webbie and maybe more links later)
123 {
124         my ($self,$c,$msg) = @_;
125         $c->reply("https://nd.ruin.nu/");
126 }
127
128 sub forum
129         : Help(syntax: .forum [nick] | not everyone have access to check for others.)
130 {
131         my ($self,$c,$msg) = @_;
132         my $dbh = $c->model;
133
134         my $user;
135         if ($msg =~ /(\S+)/ && $c->check_user_roles('irc_forum_others')){
136                 $user = $dbh->selectrow_hashref(q{
137 SELECT uid,username FROM users WHERE username ILIKE ?
138                 }, undef, $1);
139         }else{
140                 $user = $dbh->selectrow_hashref(q{
141 SELECT uid,username FROM users WHERE hostmask ILIKE ?
142                 }, undef, $c->host);
143         }
144         if ($user){
145                 my $unread = $dbh->selectrow_hashref(q{SELECT * FROM unread_posts($1)},undef,$user->{uid});
146                 if ($unread){
147                         $c->reply("$user->{username} has $unread->{new} posts since your last forum visit ($unread->{unread} unread posts in total) https://nd.ruin.nu/forum/allUnread");
148                 }
149         }
150 }
151
152 1;