#!/usr/bin/perl -w

use FindBin; use lib "$FindBin::Bin";
use Arctic;
use Utils qw(bail print_r trace);

use strict;
use warnings;

my $ARC = Arctic->init("rooms");

#Use: rooms.pl nil_* >.rooms
#Find roomnames from ansi-enchanted arctic logfiles
foreach my $log ($ARC->logs(@ARGV)) {
    Progress->show;

    my $file  = $log->file;
    my $rooms = {};
    foreach ($log->greps('[36m', '-F')) {
	    my $line = $_;

	    # Remove possible who list entries
	    $line =~ s/\e\[1m\e\[36m.*\;37m//;

	    # Try to remove everything before the last 36m
	    next unless($line =~ s/.*\e\[36m//);

	    # Try to remove everything after the first 37m
	    next unless($line =~ s/\e\[0;37m.*//);

	    $rooms->{$line}++;
	}
    print "$file $_\n" foreach(sort keys %$rooms);
}
Progress->footer;
