lulubot.pm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # This is the lulubot log parser by Vianney Lecroart <acemtp@free.fr>
  2. # More info about lulubot here: http://lulubot.berlios.de and
  3. # here: http://developer.berlios.de/projects/lulubot
  4. # Version tested with the CVS the 12/04/04
  5. # [22-11-2004/14:42] *** Joined ace (~ace@154.25.145.85)
  6. # [22-11-2004/15:00] <ace> morning
  7. # [22-11-2004/15:01] * ace is back
  8. package Pisg::Parser::Format::lulubot;
  9. use strict;
  10. $^W = 1;
  11. sub new
  12. {
  13. my ($type, %args) = @_;
  14. my $self = {
  15. cfg => $args{cfg},
  16. normalline => '^\[[^/]+/(\d+):\d+\] <([^>]+)> (.*)$',
  17. actionline => '^\[[^/]+/(\d+):\d+\] \* (\S+) (.*)$',
  18. thirdline => '^\[[^/]+/(\d+):(\d+)\] \*{3} (\S+) (\S+) (.*)$',
  19. };
  20. bless($self, $type);
  21. return $self;
  22. }
  23. sub normalline
  24. {
  25. my ($self, $line, $lines) = @_;
  26. my %hash;
  27. if ($line =~ /$self->{normalline}/o) {
  28. # Most log formats are regular enough that you can just match the
  29. # appropriate things with parentheses in the regular expression.
  30. $hash{hour} = $1;
  31. $hash{nick} = $2;
  32. $hash{saying} = $3;
  33. return \%hash;
  34. } else {
  35. return;
  36. }
  37. }
  38. sub actionline
  39. {
  40. my ($self, $line, $lines) = @_;
  41. my %hash;
  42. if ($line =~ /$self->{actionline}/o) {
  43. # Most log formats are regular enough that you can just match the
  44. # appropriate things with parentheses in the regular expression.
  45. $hash{hour} = $1;
  46. $hash{nick} = $2;
  47. $hash{saying} = $3;
  48. return \%hash;
  49. } else {
  50. return;
  51. }
  52. }
  53. sub thirdline
  54. {
  55. my ($self, $line, $lines) = @_;
  56. my %hash;
  57. if ($line =~ /$self->{thirdline}/o) {
  58. $hash{hour} = $1;
  59. $hash{min} = $2;
  60. $hash{nick} = $3;
  61. # Format-specific stuff goes here.
  62. if ($3 eq 'Joined') {
  63. $hash{newjoin} = $4;
  64. $hash{nick} = $4;
  65. } elsif ($4 eq 'changed') {
  66. $5 =~ /^topic to (.*)$/;
  67. $hash{newtopic} = $1;
  68. } elsif ($4 eq 'is') {
  69. $5 =~ /^now known as (.*)$/;
  70. $hash{newnick} = $1;
  71. }
  72. return \%hash;
  73. } else {
  74. return;
  75. }
  76. }
  77. 1;