mirror of
https://github.com/pragma-/pbot.git
synced 2024-12-27 13:12:42 +01:00
Improve factlog command
Now, by default, uses concise timestamp relative durations; e.g. "2d5h ago" instead of "2 days and 5 hours ago". Now, by default, shows only nick instead of full hostmask for each entry. Now accepts optional arguments -t and -h to control the above behavior. If -t is specified, then it shows a full timedate instead of a relative duration; e.g., "Sun Dec 13 14:26:56 PST 2015" instead of "2d5h ago". If -h is specified, then it shows the full hostmask for each entry instead of just the nick.
This commit is contained in:
parent
d199b3c26c
commit
8b66bd82ec
@ -11,6 +11,8 @@ use strict;
|
||||
use Carp ();
|
||||
use Time::Duration;
|
||||
use Time::HiRes qw(gettimeofday);
|
||||
use Getopt::Long qw(GetOptionsFromString);
|
||||
use POSIX qw(strftime);
|
||||
|
||||
sub new {
|
||||
if(ref($_[1]) eq 'HASH') {
|
||||
@ -702,10 +704,29 @@ sub factlog {
|
||||
my $self = shift;
|
||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
||||
|
||||
my ($chan, $trig) = split / /, $arguments;
|
||||
my $usage = "Usage: factlog [-h] [-t] [channel] <keyword>; -h show full hostmask; -t show actual timestamp instead of relative";
|
||||
|
||||
return $usage if not $arguments;
|
||||
|
||||
my $getopt_error;
|
||||
local $SIG{__WARN__} = sub {
|
||||
$getopt_error = shift;
|
||||
chomp $getopt_error;
|
||||
};
|
||||
|
||||
my ($show_hostmask, $actual_timestamp);
|
||||
my ($ret, $args) = GetOptionsFromString($arguments,
|
||||
'h' => \$show_hostmask,
|
||||
't' => \$actual_timestamp);
|
||||
|
||||
return "$getopt_error -- $usage" if defined $getopt_error;
|
||||
return "Too many arguments -- $usage" if @$args > 2;
|
||||
return "Missing argument -- $usage" if not @$args;
|
||||
|
||||
my ($chan, $trig) = (@$args[0], @$args[1]);
|
||||
|
||||
if(not defined $chan and not defined $trig) {
|
||||
return "Usage: factlog [channel] <trigger>";
|
||||
return $usage;
|
||||
}
|
||||
|
||||
my $needs_disambig;
|
||||
@ -753,7 +774,18 @@ sub factlog {
|
||||
|
||||
while (my $line = <$fh>) {
|
||||
my ($timestamp, $hostmask, $msg) = split / /, $line, 3;
|
||||
$result .= "[" . ago(gettimeofday - $timestamp) . "] $hostmask $msg\n";
|
||||
|
||||
if (not $show_hostmask) {
|
||||
$hostmask =~ s/!.*$//;
|
||||
}
|
||||
|
||||
if ($actual_timestamp) {
|
||||
$timestamp = strftime "%a %b %e %H:%M:%S %Z %Y", localtime $timestamp;
|
||||
} else {
|
||||
$timestamp = concise ago gettimeofday - $timestamp;
|
||||
}
|
||||
|
||||
$result .= "[$timestamp] $hostmask $msg\n";
|
||||
}
|
||||
|
||||
close $fh;
|
||||
|
Loading…
Reference in New Issue
Block a user