muh2.pm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package Pisg::Parser::Format::muh2;
  2. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  3. # This Parser works with muh version muh-2.1 and above.
  4. # muh got a new log-format, so this is version 2
  5. # contact: boitl @ IRC, sebastian@mquant.de, 09/2003
  6. # note:
  7. # muh-2.1 is buggy in action-loggin.
  8. # apply http://www.mquant.de/downloads/muh-actionpatch.diff
  9. use strict;
  10. $^W = 1;
  11. sub new
  12. {
  13. my ($type, %args) = @_;
  14. my $self = {
  15. cfg => $args{cfg},
  16. normalline => '^\[(\d+):\d+\S+ <([^>]+)> (.*)$',
  17. actionline => '^\[(\d+):\d+\S+ \* (\S+) (.*)$',
  18. thirdline => '^\[(\d+):(\d+)\S+ \*{3} (.+)$'
  19. };
  20. bless($self, $type);
  21. return $self;
  22. }
  23. sub normalline
  24. {
  25. my ($self, $line, $lines) = @_;
  26. my %hash;
  27. if ($line =~ /$self->{normalline}/o) {
  28. $hash{hour} = $1;
  29. $hash{nick} = remove_prefix($2);
  30. $hash{saying} = $3;
  31. return \%hash;
  32. } else {
  33. return;
  34. }
  35. }
  36. sub actionline
  37. {
  38. my ($self, $line, $lines) = @_;
  39. my %hash;
  40. if ($line =~ /$self->{actionline}/o) {
  41. $hash{hour} = $1;
  42. $hash{nick} = remove_prefix($2);
  43. $hash{saying} = $3;
  44. return \%hash;
  45. } else {
  46. return;
  47. }
  48. }
  49. sub thirdline
  50. {
  51. my ($self, $line, $lines) = @_;
  52. my %hash;
  53. if ($line =~ /$self->{thirdline}/o) {
  54. my @line = split(/\s/, $3);
  55. $hash{hour} = $1;
  56. $hash{min} = $2;
  57. $hash{nick} = remove_prefix($line[0]);
  58. if ($#line >= 4 && ($line[1].$line[2]) eq 'waskicked') {
  59. $hash{kicker} = $line[4];
  60. } elsif ($#line >= 4 && ($line[1] eq 'changes')) {
  61. $hash{newtopic} = join(' ', @line[4..$#line]);
  62. $hash{newtopic} =~ s/^'//;
  63. $hash{newtopic} =~ s/'$//;
  64. } elsif ($#line >= 3 && ($line[1].$line[2]) eq 'setsmode') {
  65. $hash{newmode} = $line[3];
  66. } elsif ($#line >= 3 && ($line[2].$line[3]) eq 'hasjoined') {
  67. $hash{newjoin} = $line[0];
  68. } elsif ($#line >= 5 && ($line[2].$line[3]) eq 'nowknown') {
  69. $hash{newnick} = $line[5];
  70. }
  71. return \%hash;
  72. } else {
  73. return;
  74. }
  75. }
  76. sub remove_prefix
  77. {
  78. my ($str) = @_;
  79. $str =~ s/^[@%\+]//o;
  80. return $str;
  81. }
  82. 1;