infobot.pm 2.6 KB

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