]> ruin.nu Git - NDIRC.git/blob - Commands/Members.pm
Converted Members
[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 use strict;
21 use warnings;
22 use feature ':5.10';
23
24 use MooseX::Declare;
25 use NDIRC::Dispatcher;
26
27 command def => {
28         help => q(Show current calls),
29         type => q(member),
30 }, class extends NDIRC::Command {
31         method execute($c,$msg) {
32                 my $f = $c->model->prepare(q{
33 SELECT (c.landing_tick - tick()) AS eta
34         ,array_to_string(array_agg(i.shiptype),'/') AS shiptype
35         ,dc.username
36 FROM calls c
37         JOIN incomings i USING (call)
38         LEFT OUTER JOIN users dc ON dc.uid = c.dc
39 WHERE status = 'Open' AND (c.landing_tick - tick()) >= 7
40 GROUP BY call,c.landing_tick,dc.username
41 ORDER BY c.landing_tick;
42                         });
43                 $f->execute();
44                 my $calls = "";
45                 while (my @row = $f->fetchrow()){
46                         my $dc = $row[2] // '';
47                         $calls .= " (Anti $row[1] ETA: $row[0] DC: $dc) |"
48                 }
49                 chop($calls);
50                 if ($msg ne 'q' || length $calls > 0){
51                         $c->reply("Current calls: $calls");
52                 }
53         }
54 };
55
56 command raids => {
57         help => q(List currently open raids),
58         type => q(member),
59 }, class extends NDIRC::Command {
60         method execute($c,$msg) {
61
62                 my $f = $c->model->prepare(q{
63 SELECT id FROM raids
64 WHERE open AND not removed AND tick + waves - 7 > tick()
65 AND id IN (SELECT raid FROM raid_access WHERE gid = 'M')
66                         });
67                 $f->execute();
68                 my $calls = "";
69                 while (my ($raid) = $f->fetchrow()){
70                         $calls .= " https://nd.ruin.nu/raids/view/$raid |"
71                 }
72                 $calls = "No open future raids" if ($f->rows == 0);
73                 chop($calls);
74                 $c->reply($calls);
75         }
76 };
77
78 command points => {
79         help => q(syntax: .points [nick] | not everyone have access to check for others.),
80 }, class extends NDIRC::Command {
81         method execute($c,$msg) {
82                 my $f;
83                 my $nick = $c->uid;
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 uid = ?
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
103 command sms => {
104         help => q(syntax: .sms nick | % can be used for wildcards %arro% will match barrow),
105         acl => q(irc_sms),
106 }, class extends NDIRC::Command {
107         method execute($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
123 command links => {
124         help => q(Shows link to webbie and maybe more links later),
125 }, class extends NDIRC::Command {
126         method execute($c,$msg) {
127                 $c->reply("https://nd.ruin.nu/");
128         }
129 };
130
131 command forum => {
132         help => q(syntax: .forum [nick] | not everyone have access to check for others.),
133 }, class extends NDIRC::Command {
134         method execute($c,$msg) {
135                 my $dbh = $c->model;
136
137                 my $user;
138                 if ($msg =~ /(\S+)/ && $c->check_user_roles('irc_forum_others')){
139                         $user = $dbh->selectrow_hashref(q{
140 SELECT uid,username FROM users WHERE username ILIKE ?
141                                 }, undef, $1);
142                 }else{
143                         $user = $dbh->selectrow_hashref(q{
144 SELECT uid,username FROM users WHERE uid = ?
145                                 }, undef, $c->uid);
146                 }
147                 if ($user){
148                         my $unread = $dbh->selectrow_hashref(q{SELECT * FROM unread_posts($1)},undef,$user->{uid});
149                         if ($unread){
150                                 $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");
151                         }
152                 }
153         }
154 };
155
156 1;