]> ruin.nu Git - NDIRC.git/blob - Commands/Members.pm
More info with .sms
[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'), call_if_needed, timezone, sms_note
111         ,to_char(NOW() AT TIME ZONE timezone,'HH24:MI') AS time
112 FROM users WHERE username ILIKE ?
113                 });
114         if (my ($username,$sms, $call, $timezone, $note, $time) = $c->model->selectrow_array($f,undef,$nick)){
115                 $call = $call ?  'Wake up if needed' : 'Do not wake up';
116                 $c->reply("<b>$username</b> has sms <b>$sms</b>, $call, <b>$time</b> ($timezone), $note ");
117         }else{
118                 $c->reply("No hit, maybe spelling mistake, or add % as wildcard");
119         }
120 }
121
122 sub links
123         : Help(Shows link to webbie and maybe more links later)
124 {
125         my ($self,$c,$msg) = @_;
126         $c->reply("https://nd.ruin.nu/");
127 }
128
129 sub forum
130         : Help(syntax: .forum [nick] | not everyone have access to check for others.)
131 {
132         my ($self,$c,$msg) = @_;
133         my $dbh = $c->model;
134
135         my $user;
136         if ($msg =~ /(\S+)/ && $c->check_user_roles('irc_forum_others')){
137                 $user = $dbh->selectrow_hashref(q{
138 SELECT uid,username FROM users WHERE username ILIKE ?
139                 }, undef, $1);
140         }else{
141                 $user = $dbh->selectrow_hashref(q{
142 SELECT uid,username FROM users WHERE hostmask ILIKE ?
143                 }, undef, $c->host);
144         }
145         if ($user){
146                 my $unread = $dbh->selectrow_hashref(q{SELECT * FROM unread_posts($1)},undef,$user->{uid});
147                 if ($unread){
148                         $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");
149                 }
150         }
151 }
152
153 1;