DCpp.pm 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package Pisg::Parser::Format::DCpp;
  2. use strict;
  3. $^W = 1;
  4. sub new
  5. {
  6. my ($type, %args) = @_;
  7. my $self = {
  8. cfg => $args{cfg},
  9. normalline => '^\[\d+\-\d+\-\d+\s(\d+):\d+\]\s+\<([^>]+)\> (.+)',
  10. actionline => '^NA',
  11. thirdline => '^\[\d+\-\d+\-\d+\s(\d+):(\d+)\]\s+\<([^>]+)\> (.+)',
  12. };
  13. bless($self, $type);
  14. return $self;
  15. }
  16. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  17. sub normalline
  18. {
  19. my ($self, $line, $lines) = @_;
  20. my %hash;
  21. if ($line =~ /$self->{normalline}/o) {
  22. # Most log formats are regular enough that you can just match the
  23. # appropriate things with parentheses in the regular expression.
  24. $hash{hour} = $1;
  25. $hash{nick} = $2;
  26. $hash{saying} = $3;
  27. if ($self->{cfg}->{botnicks} =~ /\b$hash{nick}\b/) {
  28. return;
  29. }
  30. return \%hash;
  31. } else {
  32. return;
  33. }
  34. }
  35. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  36. sub actionline
  37. {
  38. my ($self, $line, $lines) = @_;
  39. my %hash;
  40. if ($line =~ /$self->{actionline}/o) {
  41. # Most log formats are regular enough that you can just match the
  42. # appropriate things with parentheses in the regular expression.
  43. $hash{hour} = $1;
  44. $hash{nick} = $2;
  45. $hash{saying} = $3;
  46. return \%hash;
  47. } else {
  48. return;
  49. }
  50. }
  51. # Parses the 'third' line - (the third line is everything else, like
  52. # topic changes, mode changes, kicks, etc.)
  53. # thirdline() has to return a hash with the following keys, for
  54. # every format:
  55. # hour - the hour we're in (for timestamp logging)
  56. # min - the minute we're in (for timestamp logging)
  57. # nick - the nick
  58. # kicker - the nick which kicked somebody (if any)
  59. # newtopic - the new topic (if any)
  60. # newmode - deops or ops, must be '+o' or '-o', or '+ooo'
  61. # newjoin - a new nick which has joined the channel
  62. # newnick - a person has changed nick and this is the new nick
  63. #
  64. # It should return a hash with the following (for formatting lines in html)
  65. #
  66. # kicktext - the kick reason (if any)
  67. # modechanges - data of the mode change ('Nick' in '+o Nick')
  68. #
  69. # The hash may also have a "repeated" key indicating the number of times
  70. # the line was repeated. (Used by eggdrops log for example.)
  71. sub thirdline
  72. {
  73. my ($self, $line, $lines) = @_;
  74. my %hash;
  75. if ($line =~ /$self->{thirdline}/o) {
  76. $hash{hour} = $1;
  77. $hash{min} = $2;
  78. $hash{nick} = $3;
  79. my $text = $4;
  80. my @line = split(/\s+/, $text);
  81. # Format-specific stuff goes here.
  82. if ($self->{cfg}->{botnicks} =~ /\b$hash{nick}\b/) {
  83. if (lc($hash{nick}) eq 'hub-security') {
  84. if (defined $line[3] && $line[1].$line[2] eq 'isin') {
  85. $hash{newjoin} = $line[0];
  86. $hash{nick} = $hash{newjoin};
  87. } elsif (defined $line[6] && $line[3].$line[4] eq 'waskicked') {
  88. $hash{kicker} = $line[6];
  89. $hash{nick} = $line[2];
  90. }
  91. }
  92. return \%hash;
  93. } else {
  94. return;
  95. }
  96. } else {
  97. return;
  98. }
  99. }
  100. 1;