infobot.pm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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.
  5. use strict;
  6. $^W = 1;
  7. sub new
  8. {
  9. my ($type, %args) = @_;
  10. my $self = {
  11. cfg => $args{cfg},
  12. normalline => '^(\d+) \[\d+\] <([^\/]+)\/[^>]+> (.*)',
  13. actionline => '^NA',
  14. thirdline => '^(\d+) \[\d+\] >>> (.*)',
  15. };
  16. bless($self, $type);
  17. return $self;
  18. }
  19. sub normalline
  20. {
  21. my ($self, $line, $lines) = @_;
  22. my %hash;
  23. my $sec; my $min; my $hour; my $mday; my $mon; my $year;
  24. my $wday; my $yday; my $isdst;
  25. if ($line =~ /$self->{normalline}/o) {
  26. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
  27. $hash{hour} = $hour;
  28. $hash{nick} = $2;
  29. $hash{saying} = $3;
  30. return \%hash;
  31. } else {
  32. return;
  33. }
  34. }
  35. sub actionline
  36. {
  37. my ($self, $line, $lines) = @_;
  38. my %hash;
  39. my $sec; my $min; my $hour; my $mday; my $mon; my $year;
  40. my $wday; my $yday; my $isdst;
  41. if ($line =~ /$self->{actionline}/o) {
  42. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
  43. $hash{hour} = $hour;
  44. $hash{nick} = $2;
  45. $hash{saying} = $3;
  46. return \%hash;
  47. } else {
  48. return;
  49. }
  50. }
  51. sub thirdline
  52. {
  53. my ($self, $line, $lines) = @_;
  54. my %hash;
  55. my $sec; my $min; my $hour; my $mday; my $mon; my $year;
  56. my $wday; my $yday; my $isdst;
  57. if ($line =~ /$self->{thirdline}/o) {
  58. ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($1);
  59. $hash{hour} = $hour;
  60. $hash{min} = $min;
  61. if ($2 =~ /^\[1m([^(\[0m)]*)\[0m was kicked off \[1m[^\[]*\[0m by \[1m([^(\[0m)]*)\[0m .*/) {
  62. $hash{nick} = $1;
  63. $hash{kicker} = $2;
  64. } elsif ($2 =~ /^([^(\[1m)]*)\[1m\[\[0m#[^\[ ]+( ?:?)(.*)\[1m\]\[0m set the topic: (.*)/) {
  65. $hash{nick} = $1;
  66. $hash{newtopic} = "$3$2$4";
  67. } elsif ($2 =~ /^mode\/\S* \[\[1m([\+\-]o+) .* by \[1m(\S*)\[0m/) {
  68. $hash{newmode} = $1;
  69. $hash{nick} = $2;
  70. } elsif ($2 =~ /^(\S*) \(\S*\) has joined \#\S*/) {
  71. $hash{newjoin} = $1;
  72. } elsif ($2 =~ /^\[1;32m([^(\[0m)]*)\[0m materializes into \[1;32m([^(\[0m)]*)\[0m/) {
  73. $hash{nick} = $1;
  74. $hash{newnick} = $2;
  75. }
  76. return \%hash;
  77. } else {
  78. return;
  79. }
  80. }
  81. 1;