supy.pm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package Pisg::Parser::Format::supy;
  2. # pisg log parser for supybot bot
  3. # http://supybot.com/
  4. # Copyright Jerome Kerdreux / Licence GPL
  5. # contact Jerome.Kerdreux@finix.eu.org for more information
  6. # This module supports both the old and new logformat (after 1.8.7)
  7. use strict;
  8. $^W = 1;
  9. sub new
  10. {
  11. my ($type, %args) = @_;
  12. my $timestamp = '\d+-[\d\w]+-\d+[ T](\d+):\d+:\d+';
  13. my $thirdtimestamp = '\d+-[\d\w]+-\d+[ T](\d+):(\d+):\d+';
  14. my $self = {
  15. cfg => $args{cfg},
  16. # Old default timestamp format
  17. # [12-Feb-2004 16:59:42] <philipss> plop
  18. # New default timestamp format
  19. # 2004-02-12T16:59:42 <philipss> plop
  20. normalline => '^\[?'.$timestamp.']? <(\S+)> (.*)',
  21. # [05-Mar-2004 17:28:10] * Jkx|home bon je vais pas trainer ..
  22. actionline => '^\[?'.$timestamp.']? \* (\S+) (.*)',
  23. # [17-Feb-2004 08:13:47] *** Jkx changes topic to "Oh my god of topic"
  24. thirdline => '\[?'.$thirdtimestamp.']? \*\*\* (\S+) (\S+) (\S+) (\S+) ?(.*)?',
  25. };
  26. bless($self, $type);
  27. return $self;
  28. }
  29. sub normalline
  30. {
  31. my ($self, $line, $lines) = @_;
  32. my %hash;
  33. if ($line =~ /$self->{normalline}/o) {
  34. $hash{hour} = $1;
  35. $hash{nick} = $2;
  36. $hash{saying} = $3;
  37. return \%hash;
  38. } else {
  39. return;
  40. }
  41. }
  42. sub actionline
  43. {
  44. my ($self, $line, $lines) = @_;
  45. my %hash;
  46. if ($line =~ /$self->{actionline}/o) {
  47. $hash{hour} = $1;
  48. $hash{nick} = $2;
  49. $hash{saying} = $3;
  50. return \%hash;
  51. } else {
  52. return;
  53. }
  54. }
  55. sub thirdline
  56. {
  57. my ($self, $line, $lines) = @_;
  58. my %hash;
  59. if ($line =~ /$self->{thirdline}/o) {
  60. $hash{hour} = $1;
  61. $hash{min} = $2;
  62. $hash{nick} = $3;
  63. # print "*** 1/$1 2/$2 3/$3 4/$4 5/$5 6/$6 7/$7 ***\n";
  64. if (($4.$5) eq 'waskicked') {
  65. $hash{kicker} = $7;
  66. ($hash{kicktext} = $hash{kicker}) =~ s/\S+\s*//;
  67. $hash{kicker} =~ s/\s.*//;
  68. $hash{kicktext} =~ s/^\((.*)\)$/$1/;
  69. } elsif (($4.$5) eq 'changestopic') {
  70. $hash{newtopic} = $7;
  71. } elsif (($4.$5) eq 'setsmode:') {
  72. $hash{newmode} = $6;
  73. $hash{modechanges} = $7;
  74. } elsif (($4.$5) eq 'hasjoined') {
  75. $hash{newjoin} = $3;
  76. } elsif (($5,$6) eq 'nowknown') {
  77. $hash{newnick} = $6;
  78. $hash{newnick} =~ s/^as\s*//;
  79. }
  80. # print %hash;
  81. # print "\n";
  82. return \%hash;
  83. } else {
  84. return;
  85. }
  86. }
  87. 1;