muh.pm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package Pisg::Parser::Format::muh;
  2. # This is a Parser vor the well-known "muh-bouncer"
  3. # by Bastian Friedrichs and Sebastian Erlhofer
  4. # parser@boitl.org
  5. use strict;
  6. $^W = 1;
  7. sub new
  8. {
  9. my ($type, %args) = @_;
  10. my $self = {
  11. cfg => $args{cfg},
  12. normalline => '^\[\w\w\w \d\d \w\w\w (\d+):\d+:\d+\] <([^>\s]+)>\s+(.*)',
  13. actionline => '^\[\w\w\w \d\d \w\w\w (\d+):\d+:\d+\] \*\s+(\S+) (.*)',
  14. #thirdline => '^\[\w\w\w \d\d \w\w\w (\d+):(\d+):\d+\] \*\*\*\s+(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)',
  15. thirdline => '^\[\w\w\w \d\d \w\w\w (\d+):(\d+):\d+\] \*\*\*\s+(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (\S*)(.*)',
  16. };
  17. bless($self, $type);
  18. return $self;
  19. }
  20. sub normalline
  21. {
  22. my ($self, $line, $lines) = @_;
  23. my %hash;
  24. if ($line =~ /$self->{normalline}/o) {
  25. $hash{hour} = $1;
  26. $hash{nick} = $2;
  27. $hash{saying} = $3;
  28. return \%hash;
  29. } else {
  30. return;
  31. }
  32. }
  33. sub actionline
  34. {
  35. my ($self, $line, $lines) = @_;
  36. my %hash;
  37. if ($line =~ /$self->{actionline}/o) {
  38. $hash{hour} = $1;
  39. $hash{nick} = $2;
  40. $hash{saying} = $3;
  41. return \%hash;
  42. } else {
  43. return;
  44. }
  45. }
  46. sub thirdline
  47. {
  48. my ($self, $line, $lines) = @_;
  49. my %hash;
  50. if ($line =~ /$self->{thirdline}/o) {
  51. $hash{hour} = $1;
  52. $hash{min} = $2;
  53. $hash{nick} = $3;
  54. # Format-specific stuff goes here.
  55. if (($3.$6) eq 'Kickby') {
  56. $hash{kicker} = $7;
  57. $hash{nick} = $5;
  58. } elsif (($3.$4) eq 'Topicchange') {
  59. $hash{newtopic} = $10;
  60. #$hash{newtopic} = $9.$10;
  61. #$hash{newtopic} =~ s/^.* \):(.*)/$9$10/;
  62. $hash{nick} = $8;
  63. } elsif ($3 eq 'Mode') {
  64. my $nm;
  65. $nm = substr($5, 1);
  66. if (($nm eq "+o") || ($nm eq "-o")) {
  67. $hash{nick} = $8;
  68. $hash{newmode} = $nm;
  69. }
  70. elsif (($nm eq "+oo") || ($nm eq "-oo")) {
  71. $hash{nick} = $9;
  72. $hash{newmode} = $nm;
  73. }
  74. elsif (($nm eq "+ooo") || ($nm eq "-ooo")) {
  75. $hash{nick} = substr($10, 1, index($10, ' ', 1)-1);
  76. $hash{newmode} = $nm;
  77. }
  78. } elsif (($2.$3) eq '\*\*\*Join') {
  79. $hash{newjoin} = $5;
  80. }
  81. return \%hash;
  82. } else {
  83. return;
  84. }
  85. }
  86. 1;