Explorar el Código

Add a sub to format output of 'for example' lines to a standard (mIRC-style) line, and impliment it

sbingner hace 24 años
padre
commit
8587f69ab6

+ 1 - 0
docs/Changelog

@@ -2,6 +2,7 @@ pisg (x.xx)
    * ircII logfile support added (thanks, James Andrewartha)
    * Changed behavior of most active nicks to print an action line if no
      normal line is available for that nick
+   * Added support for formatting of "for example" lines to standard format
 
 pisg (0.41) - Sun Aug, 11th 2002
    * Fix a bug in the winbot logfile format where lines containing the channel

+ 1 - 0
modules/Pisg.pm

@@ -474,6 +474,7 @@ _END
         }
 
         my $stats = $analyzer->analyze();
+        $self->{cfg}->{analyzer} = $analyzer;
 
         # Initialize HTMLGenerator object
         my $generator;

+ 39 - 7
modules/Pisg/HTMLGenerator.pm

@@ -415,7 +415,7 @@ sub _activenicks
         my $randomline;
         if (not defined $self->{stats}->{sayings}{$nick}) {
             if ($self->{stats}->{actions}{$nick}) {
-                $randomline = htmlentities($self->{stats}->{actionlines}{$nick});
+                $randomline = htmlentities($self->_format_line($self->{stats}->{actionlines}{$nick}));
             } else {
                 $randomline = "";
             }
@@ -672,7 +672,7 @@ sub _capspeople
         my %hash = (
             nick => $caps[0],
             per  => $cpercent{$caps[0]},
-            line => htmlentities($self->{stats}->{allcaplines}{$caps[0]})
+            line => htmlentities($self->_format_line($self->{stats}->{allcaplines}{$caps[0]}))
         );
 
         my $text = $self->_template_text('allcaps1', %hash);
@@ -713,7 +713,7 @@ sub _violent
         my %hash = (
             nick    => $aggressors[0],
             attacks => $self->{stats}->{violence}{$aggressors[0]},
-            line    => htmlentities($self->{stats}->{violencelines}{$aggressors[0]})
+            line    => htmlentities($self->_format_line($self->{stats}->{violencelines}{$aggressors[0]}))
         );
         my $text = $self->_template_text('violent1', %hash);
         if($self->{cfg}->{showviolentlines}) {
@@ -747,7 +747,7 @@ sub _violent
         my %hash = (
             nick    => $victims[0],
             attacks => $self->{stats}->{attacked}{$victims[0]},
-            line    => htmlentities($self->{stats}->{attackedlines}{$victims[0]})
+            line    => htmlentities($self->_format_line($self->{stats}->{attackedlines}{$victims[0]}))
         );
         my $text = $self->_template_text('attacked1', %hash);
         if($self->{cfg}->{showviolentlines}) {
@@ -781,7 +781,7 @@ sub _gotkicks
         my %hash = (
             nick  => $gotkick[0],
             kicks => $self->{stats}->{gotkicked}{$gotkick[0]},
-            line  => $self->{stats}->{kicklines}{$gotkick[0]}
+            line  => $self->_format_line($self->{stats}->{kicklines}{$gotkick[0]})
         );
 
         my $text = $self->_template_text('gotkick1', %hash);
@@ -1014,7 +1014,7 @@ sub _mostfoul
         my %hash = (
             nick => $foul[0],
             per  => $spercent{$foul[0]},
-            line => htmlentities($self->{stats}{foullines}{$foul[0]}),
+            line => htmlentities($self->_format_line($self->{stats}{foullines}{$foul[0]})),
         );
 
         my $text = $self->_template_text('foul1', %hash);
@@ -1275,10 +1275,11 @@ sub _mostactions
                         keys %{ $self->{stats}->{actions} };
 
     if (@actions) {
+        my %linehash =
         my %hash = (
             nick    => $actions[0],
             actions => $self->{stats}->{actions}{$actions[0]},
-            line    => htmlentities($self->{stats}->{actionlines}{$actions[0]})
+            line    => htmlentities($self->_format_line($self->{stats}->{actionlines}{$actions[0]}))
         );
         my $text = $self->_template_text('action1', %hash);
         if($self->{cfg}->{showactionline}) {
@@ -1440,6 +1441,37 @@ sub _template_text
     return $text;
 }
 
+sub _format_line
+{
+    # This function formats a action/normal line to be more readable
+    my ($self,$line) = @_;
+    my $hashref;
+    if ($hashref = $self->{cfg}->{analyzer}->{parser}->normalline($line)) {
+        return '<' . $hashref->{nick} . '> ' . $hashref->{saying};
+    } elsif ($hashref = $self->{cfg}->{analyzer}->{parser}->actionline($line)) {
+        return '* ' . $hashref->{nick} . ' ' . $hashref->{saying};
+    } elsif ($hashref = $self->{cfg}->{analyzer}->{parser}->thirdline($line)) {
+        if (defined($hashref->{kicker})) {
+            $line = '*** ' . $hashref->{nick} . ' was kicked by ' . $hashref->{kicker};
+            $line .= ' (' . $hashref->{kicktext} . ')' 
+                if (defined($hashref->{kicktext}));
+        } elsif (defined($hashref->{newtopic})) {
+            $line = '*** ' . $hashref->{nick} . ' changes topic to \'' . $hashref->{newtopic} . '\'';
+        } elsif (defined($hashref->{newmode})) {
+            $line = '*** ' . $hashref->{nick} . ' sets mode ' . $hashref->{newmode};
+            $line .= ' ' . $hashref->{modechanges}
+                if (defined($hashref->{kicktext}));
+        } elsif (defined($hashref->{newjoin})) {
+            $line = '*** Joins: ' . $hashref->{nick};
+        } elsif (defined($hashref->{newnick})) {
+            $line = '*** ' . $hashref->{nick} . ' is now known as ' . $hashref->{newnick};
+        }
+        return $line;
+    } else {
+        return $line;
+    }
+}
+
 sub _get_subst
 {
     # This function looks at the user definition and see if there is sex

+ 5 - 0
modules/Pisg/Parser/Format/Template.pm

@@ -82,6 +82,11 @@ sub actionline
 #   newmode         - deops or ops, must be '+o' or '-o', or '+ooo'
 #   newjoin         - a new nick which has joined the channel
 #   newnick         - a person has changed nick and this is the new nick
+# 
+# It should return a hash with the following (for formatting lines in html)
+#
+#   kicktext        - the kick reason (if any)
+#   modechanges     - data of the mode change ('Nick' in '+o Nick')
 #
 # The hash may also have a "repeated" key indicating the number of times
 # the line was repeated. (Used by eggdrops log for example.)

+ 5 - 3
modules/Pisg/Parser/Format/eggdrop.pm

@@ -65,7 +65,8 @@ sub thirdline
         $hash{nick} = $3;
 
         if (($4.$5) eq 'kickedfrom') {
-            $7 =~ /^ by ([\S]+):.*/;
+            $7 =~ /^ by ([\S]+):\s*(.*)/;
+            $hash{kicktext} = $2;
             $1 =~ /([^!]+)/;    # Remove anything after the !
             $hash{kicker} = $1;
 
@@ -76,8 +77,9 @@ sub thirdline
 
         } elsif (($4.$5) eq 'modechange') {
             my $newmode = $6;
-            if ($7 =~ /^ .+ by ([\S]+)!.*/) {
-                $hash{nick} = $1;
+            if ($7 =~ /^ (.+) by ([\S]+)!.*/) {
+                $hash{modechanges} = $2;
+                $hash{nick} = $2;
                 $newmode =~ s/^\'//;
                 $hash{newmode} = $newmode;
             }