4
0

mIRC.pm 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package Pisg::Parser::Format::mIRC;
  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+\S+ <([^>]+)> (.*)$',
  11. actionline => '^\[(\d+):\d+\S+ \* (\S+) (.*)$',
  12. thirdline => '^\[(\d+):(\d+)\S+ \*{3} (.+)$'
  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{nick} = $2) =~ s/^[@%\+]//o; # Remove prefix
  24. $hash{saying} = $3;
  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{nick} = $2) =~ s/^[@%\+]//o; # Remove prefix
  37. $hash{saying} = $3;
  38. return \%hash;
  39. } else {
  40. return;
  41. }
  42. }
  43. sub thirdline
  44. {
  45. my ($self, $line, $lines) = @_;
  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{nick} = $line[0]) =~ s/^[@%\+]//o; # Remove prefix
  52. if ($#line >= 4 && ($line[1].$line[2]) eq 'waskicked') {
  53. $hash{kicker} = $line[4];
  54. } elsif ($#line >= 4 && ($line[1] eq 'changes')) {
  55. $hash{newtopic} = join(' ', @line[4..$#line]);
  56. $hash{newtopic} =~ s/^'//;
  57. $hash{newtopic} =~ s/'$//;
  58. } elsif ($#line >= 3 && ($line[1].$line[2]) eq 'setsmode:') {
  59. $hash{newmode} = $line[3];
  60. } elsif ($#line >= 3 && ($line[2].$line[3]) eq 'hasjoined') {
  61. $hash{newjoin} = $line[0];
  62. } elsif ($#line >= 5 && ($line[2].$line[3]) eq 'nowknown') {
  63. $hash{newnick} = $line[5];
  64. }
  65. return \%hash;
  66. } else {
  67. return;
  68. }
  69. }
  70. 1;