]> git.donarmstrong.com Git - infobot.git/blobdiff - scripts/irclog2html.pl
don't die if can't create file
[infobot.git] / scripts / irclog2html.pl
index 6714ffd2d3039e310dbe002cfb09717cc965f579..9cef0188cd11fd1b5844effc49035cbb15a5e963 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/perl
+#!/usr/bin/perl -w
 
 # irclog2html.pl Version 1.5 - 11th May 2000
 # Copyright (C) 2000, Jeffrey W. Waugh
@@ -61,15 +61,15 @@ sub header {
        my ($channel, $date) = @_;
        my $return = '';
 
-       $return .= qq{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+       $return .= qq{<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 <html>
 <head>
        <title>irclog2html for $channel on $date</title>
        <meta name="generator" content="irclog2html.pl by Jeff Waugh">
-       <meta name="version" content="Version 0.9 - 5th April 2000">
-       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+       <meta name="version" content="Version 1.5 - 11th May 2000">
+       <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 </head>
-<body text="#000000" bgcolor="#ffffff"><tt>
+<body text="#000000" bgcolor="#ffffff">
 <h1>irclog2html for $channel on $date</h1>
 };
 
@@ -91,7 +91,7 @@ sub footer {
 <a href="http://freshmeat.net/appindex/2000/03/28/954251322.html">freshmeat.net</a>!
 Modified by <a href="http://www.Rikers.org">Tim Riker</a> to work with
 <a href="http://blootbot.sourceforge.net/">blootbot</a> logs, split per channel, etc.
-</tt></body></html>
+</body></html>
 };
        return $return;
 }
@@ -107,7 +107,8 @@ sub add_footers {
        foreach $filename (@files) {
                chomp $filename;
                if (!open(OUTPUT, ">>$filename")) {
-                       die "Cannot open $filename for writing!\n\n";
+                       print "Cannot open $filename for writing!\n\n";
+                       return;
                }
                print OUTPUT footer();
                close OUTPUT;
@@ -126,7 +127,8 @@ sub output_line {
 
        mkdir($channel,oct('755')) if ($channel && ! -d $channel);
        if (!open(OUTPUT, ">>$filename")) {
-               die "Cannot open $filename for writing!\n\n";
+               #print "Cannot open $filename for writing!\n\n";
+               return;
        }
        # Begin output #
   print OUTPUT header($channel, $date) if -z $filename;
@@ -160,11 +162,11 @@ sub output_timenicktext {
                $lineout .= "$time " if $time;
                $lineout .= "<font color=\"$htmlcolour\">&lt\;$nick&gt\; $text<\/font><br>\n";
        }
-       output_line($date, $time,$channel,$lineout);
+       output_line($date, $time, $channel, $lineout);
 }
 
 sub output_timeservermsg {
-       my ($date, $time, $line) = @_;
+       my ($date, $time, $channel, $line) = @_;
        my $lineout = '';
 
        if ($STYLE =~ /table/) {
@@ -176,7 +178,7 @@ sub output_timeservermsg {
                $lineout .= "$time " if $time;
                $lineout .= "$line<br>\n";
        }
-       output_line($date, $time,'',$lineout);
+       output_line($date, $time, $channel, $lineout);
 }
 
 sub html_rgb
@@ -188,9 +190,9 @@ sub html_rgb
        my $rgbmin = 240;
 
        my $a = 0.95;                   # tune these for the starting and ending concentrations of R,G,B
-       my $b = 0.5;
+       my $c = 0.5;
 
-       my $rgb = [ [$a,$b,$b], [$b,$a,$b], [$b,$b,$a], [$a,$a,$b], [$a,$b,$a], [$b,$a,$a] ];
+       my $rgb = [ [$a,$c,$c], [$c,$a,$c], [$c,$c,$a], [$a,$a,$c], [$a,$c,$a], [$c,$a,$a] ];
        my $n = $i % @$rgb;
        my $m = $rgbmin + ($rgbmax - $rgbmin) * ($ncolours - $i) / $ncolours;
 
@@ -225,13 +227,13 @@ sub main {
                chomp $line;
 
                if (!$line eq "") {
-
                        # parse out the time
-                       if ($line =~ s/^([0-9:\.]*) (.*)$/\2/) {
+                       if ($line =~ s/^([0-9:\.]*) (.*)$/$2/) {
                                $time = $1;
                        } else {
-                               $time = "";
+                               $time = '';
                        }
+                       $channel = '';
 
                        # Replace ampersands, pointies, control characters #
                        $line =~ s/&/&amp\;/g;
@@ -249,13 +251,14 @@ sub main {
                                $nick = $line;
                                $nick =~ s/^&lt\;([^\/]*?)\/\#.*?&gt\; .*$/$1/;
                                $channel = $line;
-                               $channel =~ s/^&lt\;[^\/]*?\/\#(.*?)&gt\; .*$/$1/;
+                               $channel =~ s/^&lt\;[^\/]*?\/(\#.*?)&gt\; .*$/$1/;
 
                                # $nick =~ tr/[A-Z]/[a-z]/;
                                # <======= move this into another function when getting nick colour
 
                                $text = $line;
                                $text =~ s/^&lt\;.*?&gt\; (.*)$/$1/;
+                               $text =~ s/^ .*/&lt\;PROTECTED&gt\;/g;
                                $text =~ s/  /&nbsp\;&nbsp\;/g;
 
                                $htmlcolour = $colour_nick{$nick};
@@ -269,45 +272,40 @@ sub main {
                                        $htmlcolour = $colour_nick{$nick} = html_rgb($nickcount, $NICKMAX);
                                }
                                output_timenicktext($date, $time, $channel, $nick, $text, $htmlcolour);
-                       }
-
-                       elsif ($line =~ /^&gt\;&gt\;&gt\; /) {
+                       } elsif ($line =~ /^&gt\;&gt\;&gt\; /) {
                                $line =~ s/^&gt\;&gt\;&gt\; /\*\*\* /;
-                                       
-                               # Process changed nick results, and remember colours accordingly #
-                               if ($line =~ /\*\*\* (.*?) are|is now known as (.*)/) {
-                                       my $nick_old;
-                                       my $nick_new;
 
-                                       $nick_old = $line;
-                                       $nick_old =~ s/\*\*\* (.*?) (are|is) now known as .*/$1/;
+                               # Process changed nick results, and remember colours accordingly #
+                               if ($line =~ /\*\*\* (.*?) materializes into (.*)/) {
+                                       my $nick_old = $1;
+                                       my $nick_new = $2;
 
-                                       $nick_new = $line;
-                                       $nick_new =~ s/\*\*\* .*? (are|is) now known as (.*)/$2/;
+                                       #$nick_old = $line;
+                                       #$nick_old =~ s/\*\*\* (.*?) materializes into .*/$1/;
+                                       #$nick_new = $line;
+                                       #$nick_new =~ s/\*\*\* (.*?) materializes into (.*)/$2/;
 
                                        $colour_nick{$nick_new} = $colour_nick{$nick_old};
                                        $colour_nick{$nick_old} = undef;
 
                                        $line =~ s/(\*\*\* .*)/<font color=\"$colour_nickchange\">$1<\/font>/
-                               }
-
-                               # Colourise joined/left/server messages #
-                               elsif ($line =~ /\*\*\* .*left|quit/) {
-                                       $line =~ s/(\*\*\* .*)/<font color=\"$colour_left\">$1<\/font>/;
-                               }
-                               elsif ($line =~ /\*\*\* .*joined/) {
+                               } elsif ($line =~ /\*\*\* (join|mode|topic)\/(.*?) .*/) {
+                                       $channel = lc $2;
                                        $line =~ s/(\*\*\* .*)/<font color=\"$colour_joined\">$1<\/font>/;
-                               }
-                               elsif ($line =~ /\*\*\* /) {
+                               } elsif ($line =~ /\*\*\* (part|kick|banned)\/(.*?) .*/) {
+                                       $channel = lc $2;
+                                       $line =~ s/(\*\*\* .*)/<font color=\"$colour_left\">$1<\/font>/;
+                               } elsif ($line =~ /\*\*\* .* has signed off IRC .*/) {
+                                       # Colourise joined/left/server messages #
+                                       $line =~ s/(\*\*\* .*)/<font color=\"$colour_left\">$1<\/font>/;
+                               } elsif ($line =~ /\*\*\* /) {
                                        $line =~ s/(\*\*\* .*)$/<font color=\"$colour_server\">$1<\/font>/;
-                               }
-
-                               # Colourise the /me's #
-                               elsif ($line =~ /^\* .*$/) {
+                               } elsif ($line =~ /^\* .*$/) {
+                                 # Colourise the /me's #
                                        $line =~ s/^(\*.*)$/<font color=\"$colour_action\">$1<\/font>/;
                                }
 
-                               output_timeservermsg($date, $time, $line);
+                               output_timeservermsg($date, $time, $channel, $line);
                        }
                }
        }