sirc.pm 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package Pisg::Parser::Format::sirc;
  2. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  3. # parser for logs from sirc
  4. # based on module by bartko <bartek09@netscape.net>
  5. # the timestamps are needed for statistics generation
  6. # for timestamping use the timestep script for sirc
  7. # included in scripts/sirc-timestamp.pl
  8. use strict;
  9. $^W = 1;
  10. sub new
  11. {
  12. my ($type, %args) = @_;
  13. my $self = {
  14. cfg => $args{cfg},
  15. normalline => '(\d+):\d+ <([^>\s]+)>\s+(.*)',
  16. actionline => '(\d+):\d+ \* (\S+) (.*)',
  17. thirdline => '(\d+):(\d+) \*(.)\* (.*)',
  18. };
  19. bless($self, $type);
  20. return $self;
  21. }
  22. sub normalline
  23. {
  24. my ($self, $line, $lines) = @_;
  25. my %hash;
  26. if ($line =~ /$self->{normalline}/o) {
  27. $hash{hour} = $1;
  28. $hash{nick} = $2;
  29. $hash{saying} = $3;
  30. return \%hash;
  31. } else {
  32. return;
  33. }
  34. }
  35. sub actionline
  36. {
  37. my ($self, $line, $lines) = @_;
  38. my %hash;
  39. if ($line =~ /$self->{actionline}/o) {
  40. $hash{hour} = $1;
  41. $hash{nick} = $2;
  42. $hash{saying} = $3;
  43. return \%hash;
  44. } else {
  45. return;
  46. }
  47. }
  48. sub thirdline
  49. {
  50. my ($self, $line, $lines) = @_;
  51. my %hash;
  52. if ($line =~ /$self->{thirdline}/o) {
  53. $hash{hour} = $1;
  54. $hash{min} = $2;
  55. if ($3 eq '>') {
  56. if ($4 =~ /^(\S+) \S+ has joined channel \S+$/) {
  57. $hash{newjoin} = $1;
  58. $hash{nick} = $1;
  59. } elsif ($4 =~ /^You have joined channel \S+$/) {
  60. $hash{newjoin} = $self->{cfg}->{maintainer};
  61. $hash{nick} = $self->{cfg}->{maintainer};
  62. }
  63. } elsif ($3 eq '<') {
  64. if ($4 =~ /^(\S+) has been kicked off channel \S+ by (\S+) \((.*)\)$/) {
  65. $hash{kicker} = $2;
  66. $hash{nick} = $1;
  67. $hash{kicktext} = $3;
  68. } elsif ($4 =~ /^You have been kicked off channel \S+ by (\S+)/) {
  69. $hash{kicker} = $1;
  70. $hash{nick} = $self->{cfg}->{maintainer};
  71. $hash{kicktext} = $2;
  72. }
  73. } elsif ($3 eq 'T') {
  74. if ($4 =~ /^(\S+) has changed the topic on channel \S+ to \"(.+)\"$/) {
  75. $hash{newtopic} = $2;
  76. $hash{nick} = $1;
  77. } elsif ($4 =~ /^You have changed the topic on channel \S+ to \"(.+)\"$/) {
  78. $hash{newtopic} = $1;
  79. $hash{nick} = $self->{cfg}->{maintainer};
  80. } elsif ($4 =~ /^Topic for \S+: (.+)$/) {
  81. $self->{topic_temp} = $1;
  82. } elsif ($self->{topic_temp} && ($4 =~ /^Topic for \S+ set by ([^!]+)!\S+/)) {
  83. $hash{nick} = $1;
  84. $hash{newtopic} = $self->{topic_temp};
  85. delete $self->{topic_temp};
  86. }
  87. } elsif ($3 eq '+' && ($4 =~ /^Mode change \"(\S+) ([^\"]+)\" on channel \S+ by (\S+)/)) {
  88. $hash{newmode} = $1;
  89. $hash{modechanges} = $2;
  90. $hash{nick} = $3;
  91. } elsif ($3 eq 'N' && ($4 =~ /^(S+) is now known as (S+)$/)) {
  92. $hash{nick} = $1;
  93. $hash{newnick} = $2;
  94. }
  95. return \%hash;
  96. } else {
  97. return;
  98. }
  99. }
  100. 1;