mIRC6.pm 3.1 KB

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