Add utility to view/analyze message_history off-line

This commit is contained in:
Pragmatic Software 2014-03-11 00:05:58 +00:00
parent fe020443bb
commit f2c556e5c7
3 changed files with 51 additions and 1 deletions

View File

@ -13,7 +13,7 @@ use warnings;
# These are set automatically by the build/commit script
use constant {
BUILD_NAME => "PBot",
BUILD_REVISION => 520,
BUILD_REVISION => 521,
BUILD_DATE => "2014-03-10",
};

1
data/mh Executable file
View File

@ -0,0 +1 @@
./view_message_history.pl > mh.txt && less mh.txt

49
data/view_message_history.pl Executable file
View File

@ -0,0 +1,49 @@
#!/usr/bin/perl
use warnings;
use strict;
use Storable;
use Time::HiRes qw/gettimeofday/;
use Data::Dumper;
use Time::Duration;
my $mh = retrieve('message_history');
sub view_message_history {
foreach my $mask (sort { lc $a cmp lc $b } keys %{ $mh }) {
print '-' x 80, "\n";
print "Checking [$mask]\n";
print Dumper($mh->{$mask}), "\n";
if(exists $mh->{$mask}->{nickserv_accounts}) {
print " Multiple nickserv accounts for $mask (", scalar keys $mh->{$mask}->{nickserv_accounts}, "): ", (join ', ', keys $mh->{$mask}->{nickserv_accounts}), "\n" if scalar keys $mh->{$mask}->{nickserv_accounts} > 1;
foreach my $account (keys $mh->{$mask}->{nickserv_accounts}) {
print " Nickserv account [$account] last identified ", ago_exact(gettimeofday - $mh->{$mask}->{nickserv_accounts}->{$account}), "\n";
}
}
foreach my $channel (keys %{ $mh->{$mask}->{channels} }) {
my $length = $#{ $mh->{$mask}->{channels}->{$channel}{messages} } + 1;
if($length <= 0) {
print "length <= 0 for $mask in $channel\n";
next;
}
my %last = %{ @{ $mh->{$mask}->{channels}->{$channel}{messages} }[$length - 1] };
print " [$channel] Last seen ", ago_exact(gettimeofday - $last{timestamp}), "\n";
if(gettimeofday - $last{timestamp} >= 60 * 60 * 24 * 90) {
print(" $mask in $channel no activity in ninety days.\n");
}
}
if(scalar keys %{ $mh->{$mask} } == 0) {
print(" [$mask] has no channels\n");
}
}
print "Done.\n";
}
view_message_history;