dircproxy.pm 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package Pisg::Parser::Format::dircproxy2;
  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 => '^<([^!]+)![^>]+>\s\[(\d{2}):\d{2}\]\s(.+)$',
  11. actionline => '^\[([^!]+)![^\]]+\]\s\[(\d{2}):\d{2}\]\sACTION\s(.+)$',
  12. thirdline => '^\-(\S+)\-\s\[(\d{2}:\d{2})\]\s(.+)$',
  13. normalline_old => '^@(\d+)\s<([^!]+)![^>]+>\s(.+)$',
  14. actionline_old => '^@(\d+)\s\[([^!]+)![^\]]+\]\sACTION\s(.+)$',
  15. thirdline_old => '^@(\d+)\s\S+\s(.+)$'
  16. };
  17. bless($self, $type);
  18. return $self;
  19. }
  20. sub normalline
  21. {
  22. my ($self, $line, $lines) = @_;
  23. my %hash;
  24. if ($line =~ /$self->{normalline}/o) {
  25. $hash{hour} = $2;
  26. $hash{nick} = $1;
  27. $hash{saying} = $3;
  28. return \%hash;
  29. } elsif ($line =~ /$self->{normalline_old}/o) {
  30. $hash{hour} = (localtime($1))[2];
  31. $hash{nick} = $2;
  32. $hash{saying} = $3;
  33. return \%hash;
  34. } else {
  35. return;
  36. }
  37. }
  38. sub actionline
  39. {
  40. my ($self, $line, $lines) = @_;
  41. my %hash;
  42. if ($line =~ /$self->{actionline}/o) {
  43. $hash{hour} = $2;
  44. $hash{nick} = $1;
  45. $hash{saying} = $3;
  46. return \%hash;
  47. } elsif ($line =~ /$self->{actionline_old}/o) {
  48. $hash{hour} = (localtime($1))[2];
  49. $hash{nick} = $2;
  50. $hash{saying} = $3;
  51. return \%hash;
  52. } else {
  53. return;
  54. }
  55. }
  56. sub thirdline
  57. {
  58. my ($self, $line, $lines) = @_;
  59. my %hash;
  60. my @word;
  61. if ($line =~ /$self->{thirdline}/o) {
  62. return if ($1 eq 'dircproxy');
  63. @word = split(/\s+/, $3);
  64. my @time = split(/:/, $2);
  65. $hash{hour} = $time[0];
  66. $hash{min} = $time[1];
  67. } elsif ($line =~ /$self->{thirdline_old}/o) {
  68. return if ($1 eq 'dircproxy');
  69. @word = split(/\s+/, $2);
  70. $hash{hour} = (localtime($1))[2];
  71. $hash{min} = (localtime($1))[1];
  72. } else {
  73. return;
  74. }
  75. # the real parser here for thirdline...
  76. $hash{nick} = $word[0];
  77. if (defined($word[3]) && $word[0] eq 'Kicked') {
  78. $hash{kicker} = $word[3];
  79. $hash{nick} = $self->{cfg}->{maintainer};
  80. } elsif (defined($word[4]) && $word[1] eq 'kicked') {
  81. $hash{kicker} = $word[4];
  82. } elsif (defined($word[3]) && $word[2] eq 'changed') {
  83. if ($word[3] eq 'mode:') {
  84. $hash{newmode} = join(' ', @word[4..$#word]);
  85. } elsif ($word[3] eq 'topic:') {
  86. $hash{newtopic} = join(' ', @word[4..$#word]);
  87. }
  88. } elsif (defined($word[2]) && $word[2] eq 'joined') {
  89. $hash{newjoin} = $hash{nick};
  90. }
  91. # elsif ($word[0] eq 'NICK') {
  92. # $hash{newnick} = $word[1];
  93. # $hash{newnick} =~ s/^://;
  94. #}
  95. return \%hash;
  96. }
  97. 1;