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");
}