DCpp.pm 3.3 KB

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