Template.pm 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # This is a template for creating your own logfile parser. You can also look
  2. # in the other .pm files in this directory as good examples.
  3. package Pisg::Parser::Format::Template;
  4. use strict;
  5. $^W = 1;
  6. # The 3 variables in the new subrountine, 'normalline', 'actionline' and
  7. # 'thirdline' represents regular expressions for extracting information from
  8. # the logfile. normalline is for lines where the person merely said
  9. # something, actionline is for lines where the person performed an action,
  10. # and thirdline matches everything else, including things like kicks, nick
  11. # changes, and op grants. See the thirdline subroutine for a list of
  12. # everything it should match.
  13. sub new
  14. {
  15. my ($type, %args) = @_;
  16. my $self = {
  17. cfg => $args{cfg},
  18. normalline => '',
  19. actionline => '',
  20. thirdline => '',
  21. };
  22. bless($self, $type);
  23. return $self;
  24. }
  25. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  26. sub normalline
  27. {
  28. my ($self, $line, $lines) = @_;
  29. my %hash;
  30. if ($line =~ /$self->{normalline}/o) {
  31. # Most log formats are regular enough that you can just match the
  32. # appropriate things with parentheses in the regular expression.
  33. $hash{hour} = $1;
  34. $hash{nick} = $2;
  35. $hash{saying} = $3;
  36. return \%hash;
  37. } else {
  38. return;
  39. }
  40. }
  41. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  42. sub actionline
  43. {
  44. my ($self, $line, $lines) = @_;
  45. my %hash;
  46. if ($line =~ /$self->{actionline}/o) {
  47. # Most log formats are regular enough that you can just match the
  48. # appropriate things with parentheses in the regular expression.
  49. $hash{hour} = $1;
  50. $hash{nick} = $2;
  51. $hash{saying} = $3;
  52. return \%hash;
  53. } else {
  54. return;
  55. }
  56. }
  57. # Parses the 'third' line - (the third line is everything else, like
  58. # topic changes, mode changes, kicks, etc.)
  59. # thirdline() has to return a hash with the following keys, for
  60. # every format:
  61. # hour - the hour we're in (for timestamp logging)
  62. # min - the minute we're in (for timestamp logging)
  63. # nick - the nick
  64. # kicker - the nick which kicked somebody (if any)
  65. # newtopic - the new topic (if any)
  66. # newmode - deops or ops, must be '+o' or '-o', or '+ooo'
  67. # newjoin - a new nick which has joined the channel
  68. # newnick - a person has changed nick and this is the new nick
  69. #
  70. # It should return a hash with the following (for formatting lines in html)
  71. #
  72. # kicktext - the kick reason (if any)
  73. # modechanges - data of the mode change ('Nick' in '+o Nick')
  74. #
  75. # The hash may also have a "repeated" key indicating the number of times
  76. # the line was repeated. (Used by eggdrops log for example.)
  77. sub thirdline
  78. {
  79. my ($self, $line, $lines) = @_;
  80. my %hash;
  81. if ($line =~ /$self->{thirdline}/o) {
  82. $hash{hour} = $1;
  83. $hash{min} = $2;
  84. $hash{nick} = $3;
  85. # Format-specific stuff goes here.
  86. return \%hash;
  87. } else {
  88. return;
  89. }
  90. }
  91. 1;