]> ruin.nu Git - NDIRC.git/blobdiff - Commands/Members.pm
Introduce a uid member for the context and use it intead of the host in commands
[NDIRC.git] / Commands / Members.pm
index a2f54eeb061e3990fdce93eb577609e608ff83b0..960728904c05feea288bba004d1757a5c0a231ec 100644 (file)
@@ -32,20 +32,19 @@ sub def
 {
        my ($self,$c,$msg) = @_;
        my $f = $c->model->prepare(q{
-SELECT (c.landing_tick - tick()) AS eta, concat(i.shiptype||'/') AS shiptype
-       , dc.username
+SELECT (c.landing_tick - tick()) AS eta
+       ,array_to_string(array_agg(i.shiptype),'/') AS shiptype
+       ,dc.username
 FROM calls c
-       JOIN incomings i ON i.call = c.id
+       JOIN incomings i USING (call)
        LEFT OUTER JOIN users dc ON dc.uid = c.dc
-       JOIN users u ON u.uid = c.member
-WHERE open AND (c.landing_tick - tick()) >= 7
-GROUP BY c.id,c.landing_tick,dc.username
+WHERE status = 'Open' AND (c.landing_tick - tick()) >= 7
+GROUP BY call,c.landing_tick,dc.username
 ORDER BY c.landing_tick;
                });
        $f->execute();
        my $calls = "";
        while (my @row = $f->fetchrow()){
-               chop($row[1]);
                my $dc = $row[2] // '';
                $calls .= " (Anti $row[1] ETA: $row[0] DC: $dc) |"
        }
@@ -64,7 +63,7 @@ sub raids
        my $f = $c->model->prepare(q{
 SELECT id FROM raids
 WHERE open AND not removed AND tick + waves - 7 > tick()
-AND id IN (SELECT raid FROM raid_access WHERE gid = 2)
+AND id IN (SELECT raid FROM raid_access WHERE gid = 'M')
                });
        $f->execute();
        my $calls = "";
@@ -81,7 +80,7 @@ sub points
 {
        my ($self,$c,$msg) = @_;
        my $f;
-       my $nick = $c->host;
+       my $nick = $c->uid;
        if ($msg =~ /(\S+)/ && $c->check_user_roles(qw/irc_points_others/)){
                $nick = $1;
                $f = $c->model->prepare(q{
@@ -91,7 +90,7 @@ FROM users WHERE username ILIKE ? LIMIT 5
        }else{
                $f = $c->model->prepare(q{
 SELECT username, attack_points, defense_points, scan_points, humor_points
-FROM users WHERE hostmask ILIKE ?
+FROM users WHERE uid = ?
                });
        }
        $f->execute($nick);
@@ -107,13 +106,47 @@ sub sms
        my ($self,$c,$msg) = @_;
        my ($nick) = $msg =~ /(\S+)/ or die 'ARGS';
        my $f = $c->model->prepare(q{
-SELECT username,COALESCE(sms,'nothing added') FROM users WHERE username ILIKE ?
+SELECT username,COALESCE(sms,'nothing added'), call_if_needed, timezone, sms_note
+       ,to_char(NOW() AT TIME ZONE timezone,'HH24:MI') AS time
+FROM users WHERE username ILIKE ?
                });
-       if (my ($username,$sms) = $c->model->selectrow_array($f,undef,$nick)){
-               $c->reply("<b>$username</b> has sms <b>$sms</b>");
+       if (my ($username,$sms, $call, $timezone, $note, $time) = $c->model->selectrow_array($f,undef,$nick)){
+               $call = $call ?  'Wake up if needed' : 'Do not wake up';
+               $c->reply("<b>$username</b> has sms <b>$sms</b>, $call, <b>$time</b> ($timezone), $note ");
        }else{
                $c->reply("No hit, maybe spelling mistake, or add % as wildcard");
        }
 }
 
+sub links
+       : Help(Shows link to webbie and maybe more links later)
+{
+       my ($self,$c,$msg) = @_;
+       $c->reply("https://nd.ruin.nu/");
+}
+
+sub forum
+       : Help(syntax: .forum [nick] | not everyone have access to check for others.)
+{
+       my ($self,$c,$msg) = @_;
+       my $dbh = $c->model;
+
+       my $user;
+       if ($msg =~ /(\S+)/ && $c->check_user_roles('irc_forum_others')){
+               $user = $dbh->selectrow_hashref(q{
+SELECT uid,username FROM users WHERE username ILIKE ?
+               }, undef, $1);
+       }else{
+               $user = $dbh->selectrow_hashref(q{
+SELECT uid,username FROM users WHERE uid = ?
+               }, undef, $c->uid);
+       }
+       if ($user){
+               my $unread = $dbh->selectrow_hashref(q{SELECT * FROM unread_posts($1)},undef,$user->{uid});
+               if ($unread){
+                       $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");
+               }
+       }
+}
+
 1;