bxlog.pm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package Pisg::Parser::Format::bxlog;
  2. use strict;
  3. $^W = 1;
  4. sub new
  5. {
  6. my $type = shift;
  7. my $self = {
  8. debug => $_[0],
  9. normalline => '^\[\d+ \S+\/(\d+):\d+\] <([^>]+)> (.*)',
  10. actionline => '^\[\d+ \S+\/(\d+):\d+\] \* (\S+) (.*)',
  11. thirdline => '^\[\d+ \S+\/(\d+):(\d+)\] ([<>@!]) (.*)'
  12. };
  13. bless($self, $type);
  14. return $self;
  15. }
  16. sub normalline
  17. {
  18. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  19. my ($self, $line, $lines) = @_;
  20. my %hash;
  21. if ($line =~ /$self->{normalline}/) {
  22. $self->{debug}->("[$lines] Normal: $1 $2 $3");
  23. $hash{hour} = $1;
  24. $hash{nick} = $2;
  25. $hash{saying} = $3;
  26. return \%hash;
  27. } else {
  28. return;
  29. }
  30. }
  31. sub actionline
  32. {
  33. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  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. # Parses the 'third' line - (the third line is everything else, like
  49. # topic changes, mode changes, kicks, etc.)
  50. # thirdline() have to return a hash with the following keys, for
  51. # every format:
  52. # hour - the hour we're in (for timestamp loggin)
  53. # min - the minute we're in (for timestamp loggin)
  54. # nick - the nick
  55. # kicker - the nick which were kicked (if any)
  56. # newtopic - the new topic (if any)
  57. # newmode - deops or ops, must be '+o' or '-o', or '+ooo'
  58. # newjoin - a new nick which has joined the channel
  59. # newnick - a person has changed nick and this is the new nick
  60. my ($self, $line, $lines) = @_;
  61. my %hash;
  62. if ($line =~ /$self->{thirdline}/) {
  63. $self->{debug}->("[$lines] ***: $1 $2 $3 $4");
  64. $hash{hour} = $1;
  65. $hash{min} = $2;
  66. if ($3 eq '<') {
  67. if ($4 =~ /^([^!]+)!\S+ was kicked off \S+ by ([^!]+)!/) {
  68. $hash{kicker} = $2;
  69. $hash{nick} = $1;
  70. }
  71. } elsif ($3 eq '>') {
  72. if ($4 =~ /^([^!])+!\S+ has joined \S+$/) {
  73. $hash{nick} = $1;
  74. $hash{newjoin} = $1;
  75. }
  76. } elsif ($3 eq '@') {
  77. if ($4 =~ /^Topic by ([^!:])[!:]*: (.*)$/) {
  78. $hash{nick} = $1;
  79. $hash{newtopic} = $2;
  80. } elsif ($4 =~ /^mode \S+ \[([\S]+) [^\]]+\] by ([^!]+)!\S+$/) {
  81. $hash{newmode} = $1;
  82. $hash{nick} = $2;
  83. }
  84. } elsif ($3 eq '!') {
  85. if ($4 =~ /^(\S+) is known as (\S+)$/) {
  86. $hash{nick} = $1;
  87. $hash{newnick} = $2;
  88. }
  89. }
  90. return \%hash;
  91. } else {
  92. return;
  93. }
  94. }
  95. 1;