bxlog.pm 2.5 KB

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