]> ruin.nu Git - NDIRC.git/blob - Commands/Members.pm
34ef7d605028efa790c8935fdf336a976019b3dc
[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, concat(i.shiptype||'/') AS shiptype
36         , dc.username
37 FROM calls c
38         JOIN incomings i ON i.call = c.id
39         LEFT OUTER JOIN users dc ON dc.uid = c.dc
40         JOIN users u ON u.uid = c.member
41 WHERE open AND (c.landing_tick - tick()) >= 7
42 GROUP BY c.id,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                 chop($row[1]);
49                 my $dc = $row[2] // '';
50                 $calls .= " (Anti $row[1] ETA: $row[0] DC: $dc) |"
51         }
52         chop($calls);
53         if ($msg ne 'q' || length $calls > 0){
54                 $c->reply("Current calls: $calls");
55         }
56 }
57
58 sub raids
59         : Help(List currently open raids)
60         : Type(member)
61 {
62         my ($self,$c,$msg) = @_;
63
64         my $f = $c->model->prepare(q{
65 SELECT id FROM raids
66 WHERE open AND not removed AND tick + waves - 7 > tick()
67 AND id IN (SELECT raid FROM raid_access WHERE gid = 2)
68                 });
69         $f->execute();
70         my $calls = "";
71         while (my ($raid) = $f->fetchrow()){
72                 $calls .= " https://nd.ruin.nu/raids/view/$raid |"
73         }
74         $calls = "No open future raids" if ($f->rows == 0);
75         chop($calls);
76         $c->reply($calls);
77 }
78
79 sub points
80         : Help(syntax: .points [nick] | not everyone have access to check for others.)
81 {
82         my ($self,$c,$msg) = @_;
83         my $f;
84         my $nick = $c->host;
85         if ($msg =~ /(\S+)/ && $c->check_user_roles(qw/irc_points_others/)){
86                 $nick = $1;
87                 $f = $c->model->prepare(q{
88 SELECT username, attack_points, defense_points, scan_points, humor_points
89 FROM users WHERE username ILIKE ? LIMIT 5
90                 });
91         }else{
92                 $f = $c->model->prepare(q{
93 SELECT username, attack_points, defense_points, scan_points, humor_points
94 FROM users WHERE hostmask ILIKE ?
95                 });
96         }
97         $f->execute($nick);
98         while (my @row = $f->fetchrow()){
99                 $c->reply("$row[0] has $row[1] Attack, $row[2] Defense, $row[3] Scan, $row[4] Humor points");
100         }
101 }
102
103 sub sms
104         : Help(syntax: .sms nick | % can be used for wildcards %arro% will match barrow)
105         : ACL(irc_sms)
106 {
107         my ($self,$c,$msg) = @_;
108         my ($nick) = $msg =~ /(\S+)/ or die 'ARGS';
109         my $f = $c->model->prepare(q{
110 SELECT username,COALESCE(sms,'nothing added') FROM users WHERE username ILIKE ?
111                 });
112         if (my ($username,$sms) = $c->model->selectrow_array($f,undef,$nick)){
113                 $c->reply("<b>$username</b> has sms <b>$sms</b>");
114         }else{
115                 $c->reply("No hit, maybe spelling mistake, or add % as wildcard");
116         }
117 }
118
119 sub links
120         : Help(Shows link to webbie and maybe more links later)
121 {
122         my ($self,$c,$msg) = @_;
123         $c->reply("https://nd.ruin.nu/");
124 }
125
126 sub forum
127         : Help(syntax: .forum [nick] | not everyone have access to check for others.)
128 {
129         my ($self,$c,$msg) = @_;
130         my $dbh = $c->model;
131
132         my $user;
133         if ($msg =~ /(\S+)/ && $c->check_user_roles('irc_forum_others')){
134                 $user = $dbh->selectrow_hashref(q{
135 SELECT uid,username FROM users WHERE username ILIKE ?
136                 }, undef, $1);
137         }else{
138                 $user = $dbh->selectrow_hashref(q{
139 SELECT uid,username FROM users WHERE hostmask ILIKE ?
140                 }, undef, $c->host);
141         }
142         if ($user){
143                 my $unread = $dbh->selectrow_hashref(q{SELECT * FROM unread_posts($1)},undef,$user->{uid});
144                 if ($unread){
145                         $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");
146                 }
147         }
148 }
149
150 1;