From: Michael Andreen Date: Sat, 16 May 2009 16:42:52 +0000 (+0200) Subject: Converted laston, split half the command into lastseen X-Git-Url: https://ruin.nu/git/?p=NDIRC.git;a=commitdiff_plain;h=51ff7a3cc079e17dd0c11eb90a6b28a0ef51d409 Converted laston, split half the command into lastseen --- diff --git a/Commands/Usermgm.pm b/Commands/Usermgm.pm index 8a87f8e..3563b84 100644 --- a/Commands/Usermgm.pm +++ b/Commands/Usermgm.pm @@ -180,4 +180,71 @@ WHERE flag = $1 $c->reply("$count Users with flag $flag: $users"); } +sub laston + : Help(syntax: .laston flag [days] | lists users and the number of days since they were last seen (irc|forum|claim). If days is specified it will only list users with at least that amount of idle time. Days can also specify forum and claim with irc|forum|claim syntax) + : ACL(irc_laston) +{ + my ($self,$c,$msg) = @_; + my ($flag,$min,$forum,$claim) = $msg =~ /^(\w)(?: (\d+)(?:\|(\d+)\|(\d+))?)?$/ + or die 'ARGS'; + $min //= 0; + + my $f = $c->model->prepare(q{ +SELECT username, COALESCE(last::text,'?') AS last + ,COALESCE(lastforum::text,'?') AS lastforum + ,COALESCE(lastclaim::text,'?') AS lastclaim +FROM (SELECT username + ,date_part('day',now() - laston)::int AS last + ,date_part('day',now() - + (SELECT max(time) FROM forum_thread_visits WHERE uid = u.uid)) AS lastforum + ,date_part('day',now() - + (SELECT max(timestamp) FROM raid_claims WHERE uid = u.uid)) AS lastclaim + FROM users u + NATURAL JOIN groupmembers + NATURAL JOIN groups + WHERE flag = $1 + ) a +WHERE COALESCE(last >= $2,TRUE) AND COALESCE(lastforum >= $3,TRUE) + AND COALESCE(lastclaim >= $4,TRUE) +ORDER BY last DESC, lastforum DESC, lastclaim DESC + }); + $f->execute($flag,$min,$forum,$claim); + + my $text; + my $i = 0; + while (my $user = $f->fetchrow_hashref){ + $text .= "$user->{username}($user->{last}|$user->{lastforum}|$user->{lastclaim}) "; + $i++; + } + $c->reply("$i Users(days) with flag $flag: $text"); +} + + +sub lastseen + : Help(syntax: .lastseen username | Shows the number of days since the user(s) last visited irc, forum and raids) + : ACL(irc_lastseen) +{ + my ($self,$c,$msg) = @_; + my ($username) = $msg =~ /^(\S+)$/ or die 'ARGS'; + + my $f = $c->model->prepare(q{ +SELECT username, COALESCE(date_part('day',now() - laston)::text,'?') AS last + ,COALESCE(date_part('day',now() - (SELECT max(time) + FROM forum_thread_visits WHERE uid = u.uid))::text,'?') AS lastforum + ,COALESCE(date_part('day',now() - (SELECT max(timestamp) + FROM raid_claims WHERE uid = u.uid))::text,'?') AS lastclaim +FROM users u +WHERE username ILIKE $1 ORDER BY lower(username) + }); + $f->execute($username); + + my $text; + my $i = 0; + while (my $user = $f->fetchrow_hashref){ + $text .= "$user->{username}($user->{last}|$user->{lastforum}|$user->{lastclaim}) "; + $i++; + } + $c->reply("$i Users(days): $text"); +} + 1; diff --git a/Usermgm.pm b/Usermgm.pm index e751c56..b24e3e1 100644 --- a/Usermgm.pm +++ b/Usermgm.pm @@ -25,64 +25,7 @@ require Exporter; our @ISA = qw/Exporter/; -our @EXPORT = qw/laston addPoints setHost setPNick getShips getFleet/; - -sub laston { - my ($msg, $command) = @_; - - if (officer() || ia()){ - my ($flag,$min); - my $f; - if(defined $msg && $msg =~ /^(\w)(?: (\d+)(?:\|(\d+)\|(\d+))?)?$/){ - $flag = $1; - $min = $2; - my $forum = $3; - my $claim = $4; - $min = 0 unless defined $min; - $f = $ND::DBH->prepare(q{SELECT username, last - ,COALESCE(lastforum::text,'?') AS lastforum - ,COALESCE(lastclaim::text,'?') AS lastclaim - FROM (SELECT username - ,date_part('day',now() - laston)::int AS last - ,date_part('day',now() - (SELECT max(time) FROM forum_thread_visits WHERE uid = u.uid)) AS lastforum - ,date_part('day',now() - (SELECT max(timestamp) FROM raid_claims WHERE uid = u.uid)) AS lastclaim - FROM users u - NATURAL JOIN groupmembers - NATURAL JOIN groups - WHERE flag = $1 - ) a - WHERE COALESCE(last >= $2,TRUE) AND COALESCE(lastforum >= $3,TRUE) AND COALESCE(lastclaim >= $4,TRUE) - ORDER BY last DESC, lastforum DESC, lastclaim DESC - }); - $f->execute($flag,$min,$forum,$claim); - }elsif(defined $msg && $msg =~ /^(\S+)$/){ - $f = $ND::DBH->prepare(q{SELECT username - ,date_part('day',now() - laston)::int AS last - ,COALESCE(date_part('day',now() - (SELECT max(time) FROM forum_thread_visits WHERE uid = u.uid))::text,'?') - AS lastforum - ,COALESCE(date_part('day',now() - (SELECT max(timestamp) FROM raid_claims WHERE uid = u.uid))::text,'?') AS lastclaim - FROM users u - WHERE username ILIKE $1 ORDER BY lower(username) - }); - $f->execute($1); - }else{ - $ND::server->command("notice $ND::nick syntax: .$command | lists users and the number of days since they were last seen (irc|forum|claim). 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}|$user->{lastclaim}) "; - $i++; - } - $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"); - } -} - +our @EXPORT = qw/addPoints setHost setPNick getShips getFleet/; sub getShips { my ($ship,$command) = @_; diff --git a/database/roles.sql b/database/roles.sql index 18386cb..5051286 100644 --- a/database/roles.sql +++ b/database/roles.sql @@ -14,6 +14,8 @@ INSERT INTO roles VALUES('irc_deactivateuser'); INSERT INTO roles VALUES('irc_chattr'); INSERT INTO roles VALUES('irc_whois'); INSERT INTO roles VALUES('irc_flag'); +INSERT INTO roles VALUES('irc_laston'); +INSERT INTO roles VALUES('irc_lastseen'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_nick'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_p_intel'); @@ -29,6 +31,8 @@ INSERT INTO group_roles (gid,role) VALUES(1,'irc_deactivateuser'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_chattr'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_whois'); INSERT INTO group_roles (gid,role) VALUES(1,'irc_flag'); +INSERT INTO group_roles (gid,role) VALUES(1,'irc_laston'); +INSERT INTO group_roles (gid,role) VALUES(1,'irc_lastseen'); INSERT INTO group_roles (gid,role) VALUES(2,'irc_gs'); INSERT INTO group_roles (gid,role) VALUES(2,'irc_scan'); @@ -46,6 +50,8 @@ INSERT INTO group_roles (gid,role) VALUES(3,'irc_deactivateuser'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_chattr'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_whois'); INSERT INTO group_roles (gid,role) VALUES(3,'irc_flag'); +INSERT INTO group_roles (gid,role) VALUES(3,'irc_laston'); +INSERT INTO group_roles (gid,role) VALUES(3,'irc_lastseen'); INSERT INTO group_roles (gid,role) VALUES(4,'irc_points_others'); @@ -64,5 +70,7 @@ INSERT INTO group_roles (gid,role) VALUES(18,'irc_p_intel'); INSERT INTO group_roles (gid,role) VALUES(18,'irc_points_others'); INSERT INTO group_roles (gid,role) VALUES(18,'irc_whois'); INSERT INTO group_roles (gid,role) VALUES(18,'irc_flag'); +INSERT INTO group_roles (gid,role) VALUES(18,'irc_laston'); +INSERT INTO group_roles (gid,role) VALUES(18,'irc_lastseen'); INSERT INTO group_roles (gid,role) VALUES(19,'irc_p_intel');