miau.pm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package Pisg::Parser::Format::miau;
  2. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  3. # This Parser works with miau version 0.5.3, your milage may vary.
  4. # 2005-05-07 Kresten Kjeldgaard <gathond@gathond.dk>
  5. # This is a version of the muh2 parser that supports the log file format of the
  6. # miau bouncer, mostly topic changes that are handled differently.
  7. # 2006-10-26 adapted to miau logfile-format 0.6.x by mnh, jha and Myon
  8. use strict;
  9. $^W = 1;
  10. sub new
  11. {
  12. my ($type, %args) = @_;
  13. my $self = {
  14. cfg => $args{cfg},
  15. normalline => '^[a-zA-Z]{3} \d{1,2} (\d+):\d+\S+ <([^>]+)> (.*)$',
  16. actionline => '^[a-zA-Z]{3} \d{1,2} (\d+):\d+\S+ \* (\S+) (.*)$',
  17. thirdline => '^[a-zA-Z]{3} \d{1,2} (\d+):(\d+)\S+ [\-><\*][\-\*]{2} (.+)$'
  18. };
  19. bless($self, $type);
  20. return $self;
  21. }
  22. sub normalline
  23. {
  24. my ($self, $line, $lines) = @_;
  25. my %hash;
  26. if ($line =~ /$self->{normalline}/o) {
  27. $hash{hour} = $1;
  28. ($hash{nick} = $2) =~ s/^[@%\+]//o; # Remove prefix
  29. $hash{saying} = $3;
  30. return \%hash;
  31. } else {
  32. return;
  33. }
  34. }
  35. sub actionline
  36. {
  37. my ($self, $line, $lines) = @_;
  38. my %hash;
  39. if ($line =~ /$self->{actionline}/o) {
  40. $hash{hour} = $1;
  41. ($hash{nick} = $2) =~ s/^[@%\+]//o; # Remove prefix
  42. $hash{saying} = $3;
  43. return \%hash;
  44. } else {
  45. return;
  46. }
  47. }
  48. sub thirdline
  49. {
  50. my ($self, $line, $lines) = @_;
  51. my %hash;
  52. if ($line =~ /$self->{thirdline}/o) {
  53. my @line = split(/\s/, $3);
  54. $hash{hour} = $1;
  55. $hash{min} = $2;
  56. ($hash{nick} = $line[0]) =~ s/^[@%\+]//o; # Remove prefix
  57. if ($#line >= 4 && ($line[1].$line[2]) eq 'waskicked') {
  58. $hash{kicker} = $line[4];
  59. } elsif ($#line >= 6 && (($line[1].$line[2]) eq 'haschanged')) {
  60. $hash{newtopic} = join(' ', @line[6..$#line]);
  61. $hash{newtopic} =~ s/^'//;
  62. $hash{newtopic} =~ s/'$//;
  63. } elsif ($#line >= 3 && ($line[1].$line[2]) eq 'setsmode') {
  64. $hash{newmode} = $line[3];
  65. } elsif ($#line >= 3 && ($line[2].$line[3]) eq 'hasjoined') {
  66. $hash{newjoin} = $line[0];
  67. } elsif ($#line >= 5 && ($line[2].$line[3]) eq 'nowknown') {
  68. $hash{newnick} = $line[5];
  69. }
  70. return \%hash;
  71. } else {
  72. return;
  73. }
  74. }
  75. 1;