4
0

infobot.pm 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package Pisg::Parser::Format::infobot;
  2. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  3. # Note that infobot log files do not distinguish between action lines and
  4. # normal lines. This parser assumes that people in your channel use correct
  5. # sentence case for normal lines. YMMV.
  6. use strict;
  7. $^W = 1;
  8. sub new
  9. {
  10. my ($type, %args) = @_;
  11. my $self = {
  12. cfg => $args{cfg},
  13. debug => $args{debug},
  14. normalline => '^(\d+) \[\d+\] <([^\/]+)\/[^>]+> ([^a-z].*)',
  15. actionline => '^(\d+) \[\d+\] <([^\/]+)\/[^>]+> ([a-z].*)',
  16. thirdline => '^(\d+) \[\d+\] >>> (.*)',
  17. };
  18. bless($self, $type);
  19. return $self;
  20. }
  21. sub normalline
  22. {
  23. my ($self, $line, $lines) = @_;
  24. my %hash;
  25. my $sec; my $min; my $hour; my $mday; my $mon; my $year;
  26. my $wday; my $yday; my $isdst;
  27. if ($line =~ /$self->{normalline}/) {
  28. $self->{debug}->("[$lines] Normal: $1 $2 $3");
  29. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
  30. $hash{hour} = $hour;
  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. my $sec; my $min; my $hour; my $mday; my $mon; my $year;
  43. my $wday; my $yday; my $isdst;
  44. if ($line =~ /$self->{actionline}/) {
  45. $self->{debug}->("[$lines] Action: $1 $2 $3");
  46. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
  47. $hash{hour} = $hour;
  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. my $sec; my $min; my $hour; my $mday; my $mon; my $year;
  60. my $wday; my $yday; my $isdst;
  61. if ($line =~ /$self->{thirdline}/) {
  62. $self->{debug}->("[$lines] ***: $1 $2");
  63. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
  64. $hash{hour} = $hour;
  65. $hash{min} = $min;
  66. if ($2 =~ /^\[1m([^(\[0m)]*)\[0m was kicked off \[1m[^\[]*\[0m by \[1m([^(\[0m)]*)\[0m .*/) {
  67. $hash{nick} = $1;
  68. $hash{kicker} = $2;
  69. } elsif ($2 =~ /^([^(\[1m)]*)\[1m\S* (:?)(.*)\[1m\]\[0m set the topic: (.*)/) {
  70. $hash{nick} = $1;
  71. $hash{newtopic} = "$3$2$4";
  72. } elsif ($2 =~ /^mode\/\S* \[\[1m([\+\-]o+) .* by \[1m(\S*)\[0m/) {
  73. $hash{newmode} = $1;
  74. $hash{nick} = $2;
  75. } elsif ($2 =~ /^(\S*) \(\S*\) has joined \#\S*/) {
  76. $hash{newjoin} = $1;
  77. } elsif ($2 =~ /^\[1;32m([^(\[0m)]*)\[0m materializes into \[1;32m([^(\[0m)]*)\[0m/) {
  78. $hash{nick} = $1;
  79. $hash{newnick} = $2;
  80. }
  81. return \%hash;
  82. } else {
  83. return;
  84. }
  85. }
  86. 1;