aboutsummaryrefslogtreecommitdiff
path: root/plugins/zyklonb/seen-import-degesch.pl
blob: ddef6be87f36dc041402690d12b449397084eac6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env perl
# Creates a database for the "seen" plugin from logs for degesch.
# The results may not be completely accurate but are good for jumpstarting.
# Usage: ./seen-import-degesch.pl LOG-FILE... > seen.db

use strict;
use warnings;
use File::Basename;
use Time::Piece;

my $db = {};
for (@ARGV) {
	my $where = (basename($_) =~ /\.(.*).log/)[0];
	unless ($where) {
		print STDERR "Invalid filename: $_\n";
		next;
	}

	open my $fh, '<', $_ or die "Failed to open log file: $!";
	while (<$fh>) {
		my ($when, $who, $who_action, $what) =
			/^(.{19}) (?:<[~&@%+]*(.*?)>| \*  (\S+)) (.*)/;
		next unless $when;

		if ($who_action) {
			$who = $who_action;
			$what = "* $what";
		}
		$db->{$who}->{$where} =
			[Time::Piece->strptime($when, "%Y-%m-%d %T")->epoch, $what];
	}
}

while (my ($who, $places) = each %$db) {
	while (my ($where, $data) = each %$places) {
		my ($when, $what) = @$data;
		print ":$who PRIVMSG $where $when :$what\n";
	}
}