mIRC6hack.pm 3.3 KB

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