]> ruin.nu Git - NDIRC.git/commitdiff
allow laston to take username as argument, also show last forum visit
authorMichael Andreen <harv@ruin.nu>
Sat, 6 Oct 2007 13:16:23 +0000 (15:16 +0200)
committerMichael Andreen <harv@ruin.nu>
Sat, 6 Oct 2007 13:16:23 +0000 (15:16 +0200)
Usermgm.pm

index 83c27ca0681bd19111f68c305a887b0921ce313f..ee0187e0f73779515c20a0f6a114f15747f759ac 100644 (file)
@@ -134,28 +134,35 @@ sub laston {
        my ($msg, $command) = @_;
 
        my ($flag,$min);
-       if(defined $msg && $msg =~ /^(\w)(?: (\d+))?$/){
-               $flag = $1;
-               $min = $2;
-       }else{
-               $ND::server->command("notice $ND::nick syntax: .$command flag [days] | lists users and the number of days since they were last seen. If days is specified it will only list users with at least that amount of idle time.");
-               return;
-       }
-
+       my $f;
        if (officer()){
-               my $f = $ND::DBH->prepare(qq{SELECT username,last
-                       FROM (SELECT uid,username, date_part('day',now() - laston)::int AS last,laston FROM users) u NATURAL JOIN groupmembers NATURAL JOIN groups WHERE flag = ? AND (last >= ? OR last IS NULL) ORDER BY laston
-                       });
-               $min = 0 unless defined $min;
-               $f->execute($flag,$min);
+               if(defined $msg && $msg =~ /^(\w)(?: (\d+))?$/){
+                       $flag = $1;
+                       $min = $2;
+                       $min = 0 unless defined $min;
+                       $f = $ND::DBH->prepare(qq{SELECT username,last,lastforum
+                               FROM (SELECT uid,username, date_part('day',now() - laston)::int AS last,date_part('day',now() - last_forum_visit)::int AS lastforum, laston FROM users) u NATURAL JOIN groupmembers NATURAL JOIN groups WHERE flag = ? AND (last >= ? OR last IS NULL) ORDER BY laston
+                               });
+                       $f->execute($flag,$min);
+               }elsif(defined $msg && $msg =~ /^(\S+)$/){
+                       $f = $ND::DBH->prepare(qq{SELECT username,last,lastforum
+                               FROM (SELECT uid,username, date_part('day',now() - laston)::int AS last,date_part('day',now() - last_forum_visit)::int AS lastforum, laston FROM users) u WHERE username ILIKE ? ORDER BY lower(username)
+                               });
+                       $f->execute($1);
+               }else{
+                       $ND::server->command("notice $ND::nick syntax: .$command <flag [days]|nick> | lists users and the number of days since they were last seen (irc|forum). If days is specified it will only list users with at least that amount of idle time.");
+                       return;
+               }
+
                my $text;
                my $i = 0;
                while (my $user = $f->fetchrow_hashref){
                        $user->{last} = '?' unless defined $user->{last};
-                       $text .= "$user->{username}($user->{last}) ";
+                       $user->{lastforum} = '?' unless defined $user->{lastforum};
+                       $text .= "$user->{username}($user->{last}|$user->{lastforum}) ";
                        $i++;
                }
-               $ND::server->command("msg $ND::target $ND::B$i$ND::B Users(days) with flag $ND::B$flag$ND::B: $text");
+               $ND::server->command("msg $ND::target $ND::B$i$ND::B Users(days)".(defined $flag ?  " with flag $ND::B$flag$ND::B" : "").": $text");
        }else{
                $ND::server->command("msg $ND::target Only officers are allowed to check that");
        }