X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=Commands%2FUsermgm.pm;fp=Commands%2FUsermgm.pm;h=3563b84fc12b7754b6dfb41330adff97ea6ed8cb;hb=51ff7a3cc079e17dd0c11eb90a6b28a0ef51d409;hp=8a87f8e1fae85147459336c9e4bcf654420c6f29;hpb=5f7e87f30570220f44035831a51c881ee3ca34b7;p=NDIRC.git
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;