supy.pm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. package Pisg::Parser::Format::supy;
  2. # pisg log parser for supybot bot
  3. # http://supybot.sf.net
  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 $self = {
  13. cfg => $args{cfg},
  14. # [12-Feb-2004 16:59:42] <philipss> plop
  15. normalline => '^\[\d+-\w+-\d+ (\d+):\d+:\d+] <(\S+)> (.*)',
  16. # [05-Mar-2004 17:28:10] * Jkx|home bon je vais pas trainer ..
  17. actionline => '^\[\d+-\w+-\d+ (\d+):\d+:\d+] \* (\S+) (.*)',
  18. # [17-Feb-2004 08:13:47] *** Jkx changes topic to "Oh my god of topic"
  19. thirdline => '\[\d+-\w+-\d+ (\d+):(\d+):\d+] \*\*\* (\S+) (\S+) (\S+) (\S+) ?(.*)?',
  20. };
  21. bless($self, $type);
  22. return $self;
  23. }
  24. sub normalline
  25. {
  26. my ($self, $line, $lines) = @_;
  27. my %hash;
  28. if ($line =~ /$self->{normalline}/o) {
  29. $hash{hour} = $1;
  30. $hash{nick} = $2;
  31. $hash{saying} = $3;
  32. return \%hash;
  33. } else {
  34. return;
  35. }
  36. }
  37. sub actionline
  38. {
  39. my ($self, $line, $lines) = @_;
  40. my %hash;
  41. if ($line =~ /$self->{actionline}/o) {
  42. $hash{hour} = $1;
  43. $hash{nick} = $2;
  44. $hash{saying} = $3;
  45. return \%hash;
  46. } else {
  47. return;
  48. }
  49. }
  50. sub thirdline
  51. {
  52. my ($self, $line, $lines) = @_;
  53. my %hash;
  54. if ($line =~ /$self->{thirdline}/o) {
  55. $hash{hour} = $1;
  56. $hash{min} = $2;
  57. $hash{nick} = $3;
  58. # print "*** 1/$1 2/$2 3/$3 4/$4 5/$5 6/$6 7/$7 ***\n";
  59. # all action are catched except nick change because
  60. # there aren't in the logfile :(
  61. if (($4.$5) eq 'waskicked') {
  62. $hash{kicker} = $7;
  63. $hash{kicker} =~ s/\s.*//;
  64. } elsif (($4.$5) eq 'changestopic') {
  65. $hash{newtopic} = $7;
  66. } elsif (($4.$5) eq 'setsmode:') {
  67. $hash{newmode} = $6;
  68. } elsif (($4.$5) eq 'hasjoined') {
  69. $hash{newjoin} = $3;
  70. }
  71. # print %hash;
  72. # print "\n";
  73. return \%hash;
  74. } else {
  75. return;
  76. }
  77. }
  78. 1;