bxlog.pm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package Pisg::Parser::Format::bxlog;
  2. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  3. use strict;
  4. $^W = 1;
  5. sub new
  6. {
  7. my ($type, %args) = @_;
  8. my $self = {
  9. cfg => $args{cfg},
  10. debug => $args{debug},
  11. normalline => '^\[\d+ \S+\/(\d+):\d+\] <([^>]+)> (.*)',
  12. actionline => '^\[\d+ \S+\/(\d+):\d+\] \* (\S+) (.*)',
  13. thirdline => '^\[\d+ \S+\/(\d+):(\d+)\] ([<>@!]) (.*)'
  14. };
  15. bless($self, $type);
  16. return $self;
  17. }
  18. sub normalline
  19. {
  20. my ($self, $line, $lines) = @_;
  21. my %hash;
  22. if ($line =~ /$self->{normalline}/) {
  23. $self->{debug}->("[$lines] Normal: $1 $2 $3");
  24. $hash{hour} = $1;
  25. $hash{nick} = $2;
  26. $hash{saying} = $3;
  27. return \%hash;
  28. } else {
  29. return;
  30. }
  31. }
  32. sub actionline
  33. {
  34. my ($self, $line, $lines) = @_;
  35. my %hash;
  36. if ($line =~ /$self->{actionline}/) {
  37. $self->{debug}->("[$lines] Action: $1 $2 $3");
  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}/) {
  51. $self->{debug}->("[$lines] ***: $1 $2 $3 $4");
  52. $hash{hour} = $1;
  53. $hash{min} = $2;
  54. if ($3 eq '<') {
  55. if ($4 =~ /^([^!]+)!\S+ was kicked off \S+ by ([^!]+)!/) {
  56. $hash{kicker} = $2;
  57. $hash{nick} = $1;
  58. }
  59. } elsif ($3 eq '>') {
  60. if ($4 =~ /^([^!])+!\S+ has joined \S+$/) {
  61. $hash{nick} = $1;
  62. $hash{newjoin} = $1;
  63. }
  64. } elsif ($3 eq '@') {
  65. if ($4 =~ /^Topic by ([^!:])[!:]*: (.*)$/) {
  66. $hash{nick} = $1;
  67. $hash{newtopic} = $2;
  68. } elsif ($4 =~ /^mode \S+ \[([\S]+) [^\]]+\] by ([^!]+)!\S+$/) {
  69. $hash{newmode} = $1;
  70. $hash{nick} = $2;
  71. }
  72. } elsif ($3 eq '!') {
  73. if ($4 =~ /^(\S+) is known as (\S+)$/) {
  74. $hash{nick} = $1;
  75. $hash{newnick} = $2;
  76. }
  77. }
  78. return \%hash;
  79. } else {
  80. return;
  81. }
  82. }
  83. 1;