# Script to highlight IRC logs of Konversation # Author: Alan Haggai Alavi #!/usr/bin/perl use strict; use warnings; die( "Format:\t$0 inputfile outputfile" ) unless $#ARGV == 1 || $#ARGV == 2; my %members; my %members_messages; my %members_actions; my @colours = ( '#e90e7f', '#8e55e9', '#18b33c', '#b39875', '#3176b3', '#d76e5c', '#de7008', '#febd0f', '#483030', '#c6d639', '#d9c952', '#f34607', '#6087d3', '#eda164', '#a24d4d', ); open FH1, $ARGV[ 0 ]; # Get all the chat participants in the %member hash while( ) { if( /^\[.+\] <(.+?)>/ ) { $members{ $1 } = undef; $members_messages{ $1 } ++; } } open FH2, '>', $ARGV[ 1 ] or die( "$ARGV[ 1 ] cannot be opened" ); chomp( my $date = `date -u` ); my $title = "$ARGV[ 2 ] - $date"; print FH2 ' '. $title . '
Participants:
'; { my $i = 0; foreach( keys %members ) { $i = 0 if $i == 15; $members{ $_ } = $colours[ $i ++ ]; print FH2 " $_" unless /^Guest\d*/; } } print FH2 "
"; seek FH1, 0, 0; while( ) { s//>/; # Smileys s!:-?\)!!g; s!:-?D!!g; s!:-?\(!!g; s!;-?\(!!g; s!:-?O!!g; s!:-?\?!!g; s!8-?\)!!g; s!:-?\){2,}!!g; s!(?:x|X)-?D!!g; s!:-?\|!!g; if( /^\[.+\] (?:\[.+\]|\*\*\*|-->|<--)/ ) { # Gray out all server messages, joins, parts, and notices. Also emphasise the topic. s/\n/
/; s/channel topic is/channel topic is / && s/$/<\/span>/; print FH2 "$_"; } elsif( /<(.+?)>/ ) { # Colour and bolden and gray out [11:11:11] my $name = $1; my $colour = $members{ $name }; if( exists $members{ $name } ) { s!<$name>!<$name>!; s!(\[.+\])!$1!; print FH2 $_, "
"; } } elsif( /^\[.+\] \* \b(.+?)\b/ ) { # Colour and bolden /me and gray out [11:11:11] my $name = $1; my $colour = $members{ $name }; if( exists $members{ $name } ) { s!$name!$name!; s!(\[.+\])!$1!; print FH2 $_, "
"; } } } close FH1; print FH2 '

Statistics

Top posts: '; { my $i = 0; foreach( sort { $members_messages{ $b } <=> $members_messages{ $a } or "\L$a" cmp "\L$b" } ( keys( %members_messages ) ) ) { $i = 0 if $i == 15; $members{ $_ } = $colours[ $i ++ ]; print FH2 " $_ ($members_messages{ $_ })" unless /^Guest\d*/; } } print FH2 '
'; close FH2; 1;