mIRC6.pm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package Pisg::Parser::Format::mIRC6;
  2. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  3. # NOTE: mIRC6's logging format is severly damaged by design. Try to use the
  4. # "mIRC6hack" format instead.
  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+:?\d*\] <([^>]+)> (.*)',
  13. thirdline => '^\[(\d+):(\d+):?\d*\] \* (.+)'
  14. };
  15. bless($self, $type);
  16. return $self;
  17. }
  18. sub normalline
  19. {
  20. my ($self, $line, $lines) = @_;
  21. my %hash;
  22. if ($line =~ /$self->{normalline}/o) {
  23. $hash{hour} = $1;
  24. $hash{saying} = $3;
  25. ($hash{nick} = $2) =~ s/^[@%\+~&]//o; # Remove prefix
  26. return \%hash;
  27. } else {
  28. return;
  29. }
  30. }
  31. sub actionline
  32. {
  33. my ($self, $line, $lines) = @_;
  34. my %hash;
  35. return $self->thirdline($line, $lines, 1);
  36. }
  37. sub thirdline
  38. {
  39. my ($self, $line, $lines, $action) = @_;
  40. my %hash;
  41. if ($line =~ /$self->{thirdline}/o) {
  42. my @line = split(/\s/, $3);
  43. $hash{hour} = $1;
  44. $hash{min} = $2;
  45. $hash{saying} = $3;
  46. ($hash{nick} = $line[0]) =~ s/^[@%\+~&]//o; # Remove prefix
  47. if ($#line >= 4 && ($line[1].$line[2]) eq 'waskicked' && ($line[$#line] =~ /\)$/)) {
  48. $hash{kicker} = $line[4];
  49. } elsif ($#line >= 4 && ($line[1].$line[2]) eq 'werekicked' && ($line[$#line] =~ /\)$/)) {
  50. $hash{kicker} = $line[4];
  51. $hash{nick} = $self->{cfg}{maintainer};
  52. } elsif ($#line >= 4 && ($line[1] eq 'changes') && ($line[$#line] =~ /\'$/)) {
  53. $hash{newtopic} = join(' ', @line[4..$#line]);
  54. $hash{newtopic} =~ s/^'//;
  55. $hash{newtopic} =~ s/'$//;
  56. } elsif ($#line >= 3 && ($line[1].$line[2]) eq 'setsmode:') {
  57. $hash{newmode} = $line[3];
  58. } elsif ($#line == 4 && ($line[2].$line[3]) eq 'hasjoined') {
  59. $hash{newjoin} = $line[0];
  60. } elsif ($line[0] eq 'Joins:') { # Alt+O -> IRC -> Options -> Short join/parts
  61. $hash{newjoin} = $line[1];
  62. } elsif ($#line == 5 && ($line[2].$line[3]) eq 'nowknown') {
  63. $hash{newnick} = $line[5];
  64. } elsif ($action) {
  65. if (
  66. ($hash{saying} =~ /^Set by \S+ on \S+ \S+ \d+ \d+:\d+:\d+/) ||
  67. ($hash{saying} =~ /^Now talking in #\S+/) ||
  68. ($hash{saying} =~ /^Topic is \'.*\'/) ||
  69. ($hash{saying} =~ /^Disconnected/) ||
  70. ($hash{saying} =~ /^\S+ has quit IRC \(.+\)/) ||
  71. ($hash{saying} =~ /^\S+ has left \#\S+/) ||
  72. ($hash{saying} =~ /^\S+\s\S+ has left \#\S+/) ||
  73. ($hash{saying} =~ /^\S+\s\S+ Quit \S+/) ||
  74. ($hash{saying} eq "You're not channel operator") ||
  75. ($hash{nick} eq 'Attempting' && $hash{saying} =~ /^to rejoin channel/) ||
  76. ($hash{nick} eq 'Rejoined' && $hash{saying} =~ /^channel/) ||
  77. ($hash{saying} =~ /^Retrieving #\S+ info\.\.\./)
  78. ) {
  79. return 0;
  80. } else {
  81. $hash{saying} =~ s/^\Q$hash{nick}\E //;
  82. return \%hash;
  83. }
  84. } else {
  85. return;
  86. }
  87. return \%hash
  88. unless ($action);
  89. }
  90. return;
  91. }
  92. 1;