blootbot.pm 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # This is a template for blootbot logs http://blootbot.sf.net/
  2. # hacked up by Tim Riker <Tim@Rikers.org>
  3. package Pisg::Parser::Format::blootbot;
  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. # blootbot puts hh:mm.ss at the start.
  14. # note that one log can contain more than one channel.
  15. # FIXME it would be nice if pisg would process them all in one pass!
  16. #
  17. # Normal lines are like:
  18. #
  19. # 01:02.03 <nick/#channel> normal
  20. # 01:02.03 * nick/#channel action
  21. sub new
  22. {
  23. my ($type, %args) = @_;
  24. my $self = {
  25. cfg => $args{cfg},
  26. normalline => '^(\d\d):\d\d\.\d\d <([^\/]+)\/(#[^>]+)> (.*)',
  27. actionline => '^(\d\d):\d\d\.\d\d \* (.*)/(#\S*) (.*)',
  28. thirdline => '^(\d\d):(\d\d)\.\d\d >>> (.*)',
  29. };
  30. bless($self, $type);
  31. return $self;
  32. }
  33. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  34. sub normalline
  35. {
  36. my ($self, $line, $lines) = @_;
  37. my %hash;
  38. if ($line =~ /$self->{normalline}/o and
  39. lc $3 eq lc $self->{cfg}->{channel}) {
  40. # Most log formats are regular enough that you can just match the
  41. # appropriate things with parentheses in the regular expression.
  42. $hash{hour} = $1;
  43. $hash{nick} = $2;
  44. $hash{channel} = $3;
  45. $hash{saying} = $4;
  46. return \%hash;
  47. } else {
  48. return;
  49. }
  50. }
  51. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  52. sub actionline
  53. {
  54. my ($self, $line, $lines) = @_;
  55. my %hash;
  56. if ($line =~ /$self->{actionline}/o and
  57. lc $3 eq lc $self->{cfg}->{channel}) {
  58. # Most log formats are regular enough that you can just match the
  59. # appropriate things with parentheses in the regular expression.
  60. $hash{hour} = $1;
  61. $hash{nick} = $2;
  62. $hash{channel} = $3;
  63. $hash{saying} = $4;
  64. return \%hash;
  65. } else {
  66. return;
  67. }
  68. }
  69. # Parses the 'third' line - (the third line is everything else, like
  70. # topic changes, mode changes, kicks, etc.)
  71. # thirdline() has to return a hash with the following keys, for
  72. # every format:
  73. # hour - the hour we're in (for timestamp logging)
  74. # min - the minute we're in (for timestamp logging)
  75. # nick - the nick
  76. # kicker - the nick which kicked somebody (if any)
  77. # newtopic - the new topic (if any)
  78. # newmode - deops or ops, must be '+o' or '-o', or '+ooo'
  79. # newjoin - a new nick which has joined the channel
  80. # newnick - a person has changed nick and this is the new nick
  81. #
  82. # It should return a hash with the following (for formatting lines in html)
  83. #
  84. # kicktext - the kick reason (if any)
  85. # modechanges - data of the mode change ('Nick' in '+o Nick')
  86. #
  87. # The hash may also have a "repeated" key indicating the number of times
  88. # the line was repeated. (Used by eggdrops log for example.)
  89. sub thirdline
  90. {
  91. my ($self, $line, $lines) = @_;
  92. my %hash;
  93. if ($line =~ /$self->{thirdline}/o) {
  94. $hash{hour} = $1;
  95. $hash{min} = $2;
  96. # Format-specific stuff goes here.
  97. if ($3 =~ /^topic\/(#\S*) by (\S*) -> (.*)/) {
  98. # 01:02.03 >>> topic/#channel by nick -> topic...
  99. $hash{channel} = $1;
  100. $hash{nick} = $2;
  101. $hash{newtopic} = "$3";
  102. } elsif ($3 =~ /^mode\/(#\S*) \[([\+\-]o*) (.*)\] by (\S*)/) {
  103. # 01:02.03 >>> mode/#channel [+o nick] by ChanServ
  104. $hash{channel} = $1;
  105. $hash{newmode} = $2;
  106. $hash{modechanges} = $3;
  107. $hash{nick} = $4;
  108. } elsif ($3 =~ /^join\/(#\S*) (\S*) \(\S*\)/) {
  109. # 01:02.03 >>> join/#channel nick (~user@example.com)
  110. $hash{channel} = $1;
  111. $hash{newjoin} = $2;
  112. } elsif ($3 =~ /^kick\/(#\S*) \[(\S*)!.*\] by (\S*) \((.*\))/) {
  113. # 01:02.03 >>> kick/#channel [nick!~user@example.com] by nick (reason)
  114. $hash{channel} = $1;
  115. $hash{nick} = $2;
  116. $hash{kicker} = $3;
  117. $hash{kicktext} = $4;
  118. } elsif ($3 =~ /^(\S*) materializes into (\S*)/) {
  119. # 01:02.03 >>> nick_ materializes into nick
  120. $hash{nick} = $1;
  121. $hash{newnick} = $2;
  122. # no channel so return now
  123. return \%hash;
  124. }
  125. return \%hash if ($hash{channel} and lc $hash{channel} eq lc $self->{cfg}->{channel});
  126. return;
  127. } else {
  128. return;
  129. }
  130. }
  131. 1;