miau.pm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. use strict;
  8. $^W = 1;
  9. sub new
  10. {
  11. my ($type, %args) = @_;
  12. my $self = {
  13. cfg => $args{cfg},
  14. normalline => '^\[(\d+):\d+\S+ <([^>]+)> (.*)$',
  15. actionline => '^\[(\d+):\d+\S+ \* (\S+) (.*)$',
  16. thirdline => '^\[(\d+):(\d+)\S+ [\-><\*][\-\*]{2} (.+)$'
  17. };
  18. bless($self, $type);
  19. return $self;
  20. }
  21. sub normalline
  22. {
  23. my ($self, $line, $lines) = @_;
  24. my %hash;
  25. if ($line =~ /$self->{normalline}/o) {
  26. $hash{hour} = $1;
  27. ($hash{nick} = $2) =~ s/^[@%\+]//o; # Remove prefix
  28. $hash{saying} = $3;
  29. return \%hash;
  30. } else {
  31. return;
  32. }
  33. }
  34. sub actionline
  35. {
  36. my ($self, $line, $lines) = @_;
  37. my %hash;
  38. if ($line =~ /$self->{actionline}/o) {
  39. $hash{hour} = $1;
  40. ($hash{nick} = $2) =~ s/^[@%\+]//o; # Remove prefix
  41. $hash{saying} = $3;
  42. return \%hash;
  43. } else {
  44. return;
  45. }
  46. }
  47. sub thirdline
  48. {
  49. my ($self, $line, $lines) = @_;
  50. my %hash;
  51. if ($line =~ /$self->{thirdline}/o) {
  52. my @line = split(/\s/, $3);
  53. $hash{hour} = $1;
  54. $hash{min} = $2;
  55. ($hash{nick} = $line[0]) =~ s/^[@%\+]//o; # Remove prefix
  56. if ($#line >= 4 && ($line[1].$line[2]) eq 'waskicked') {
  57. $hash{kicker} = $line[4];
  58. } elsif ($#line >= 6 && (($line[1].$line[2]) eq 'haschanged')) {
  59. $hash{newtopic} = join(' ', @line[6..$#line]);
  60. $hash{newtopic} =~ s/^'//;
  61. $hash{newtopic} =~ s/'$//;
  62. } elsif ($#line >= 3 && ($line[1].$line[2]) eq 'setsmode') {
  63. $hash{newmode} = $line[3];
  64. } elsif ($#line >= 3 && ($line[2].$line[3]) eq 'hasjoined') {
  65. $hash{newjoin} = $line[0];
  66. } elsif ($#line >= 5 && ($line[2].$line[3]) eq 'nowknown') {
  67. $hash{newnick} = $line[5];
  68. }
  69. return \%hash;
  70. } else {
  71. return;
  72. }
  73. }
  74. 1;