mIRC6.pm 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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{nick} = remove_prefix($2);
  23. $hash{saying} = $3;
  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} = remove_prefix($line[0]);
  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 == 3 && ($line[1].$line[2]) 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} eq "You're not channel operator") ||
  69. ($hash{nick} eq 'Attempting' && $hash{saying} =~ /^to rejoin channel/) ||
  70. ($hash{nick} eq 'Rejoined' && $hash{saying} =~ /^channel/) ||
  71. ($hash{saying} =~ /^Retrieving #\S+ info\.\.\./)
  72. ) {
  73. return 0;
  74. } else {
  75. $hash{saying} =~ s/^\Q$hash{nick}\E //;
  76. return \%hash;
  77. }
  78. } else {
  79. return;
  80. }
  81. return \%hash
  82. unless ($action);
  83. }
  84. return;
  85. }
  86. sub remove_prefix
  87. {
  88. my $str = shift;
  89. $str =~ s/^@//;
  90. $str =~ s/^\+//;
  91. $str =~ s/^%//;
  92. return $str;
  93. }
  94. 1;