grufti.pm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package Pisg::Parser::Format::grufti;
  2. use strict;
  3. $^W = 1;
  4. my $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
  5. my $actionline = '^\[(\d+):\d+\] \* (\S+) (.*)';
  6. my $thirdline = '^\[(\d+):(\d+)\] (\S+) (\S+) (\S+) (\S+) (\S+) (\S+)(.*)';
  7. my ($debug);
  8. sub new
  9. {
  10. my $self = shift;
  11. $debug = shift;
  12. return bless {};
  13. }
  14. sub normalline
  15. {
  16. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  17. my ($self, $line, $lines) = @_;
  18. my %hash;
  19. if ($line =~ /$normalline/) {
  20. $debug->("[$lines] Normal: $1 $2 $3");
  21. $hash{hour} = $1;
  22. $hash{nick} = $2;
  23. $hash{saying} = $3;
  24. return \%hash;
  25. } else {
  26. return;
  27. }
  28. }
  29. sub actionline
  30. {
  31. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  32. my ($self, $line, $lines) = @_;
  33. my %hash;
  34. if ($line =~ /$actionline/) {
  35. $debug->("[$lines] Action: $1 $2 $3");
  36. $hash{hour} = $1;
  37. $hash{nick} = $2;
  38. $hash{saying} = $3;
  39. return \%hash;
  40. } else {
  41. return;
  42. }
  43. }
  44. sub thirdline
  45. {
  46. # Parses the 'third' line - (the third line is everything else, like
  47. # topic changes, mode changes, kicks, etc.)
  48. # thirdline() have to return a hash with the following keys, for
  49. # every format:
  50. # hour - the hour we're in (for timestamp loggin)
  51. # min - the minute we're in (for timestamp loggin)
  52. # nick - the nick
  53. # kicker - the nick which were kicked (if any)
  54. # newtopic - the new topic (if any)
  55. # newmode - deops or ops, must be '+o' or '-o', or '+ooo'
  56. # newjoin - a new nick which has joined the channel
  57. # newnick - a person has changed nick and this is the new nick
  58. my ($self, $line, $lines) = @_;
  59. my %hash;
  60. if ($line =~ /$thirdline/) {
  61. if (defined $9) {
  62. $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8 $9");
  63. } else {
  64. $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8");
  65. }
  66. $hash{hour} = $1;
  67. $hash{min} = $2;
  68. $hash{nick} = $3;
  69. if ($5 eq 'kicked') {
  70. $hash{kicker} = $3;
  71. $hash{nick} = $6;
  72. } elsif (($4.$5) eq 'haschanged') {
  73. $hash{newtopic} = $9;
  74. } elsif (($4.$5) eq 'modechange') {
  75. $hash{newmode} = substr($6, 1);
  76. $hash{nick} = $9;
  77. $hash{nick} =~ /.*[by ](\S+)/;
  78. $hash{nick} = $1;
  79. } elsif ($5 eq 'joined') {
  80. $hash{newjoin} = $1;
  81. } elsif (($3.$4) eq 'Nickchange') {
  82. $hash{nick} = $7;
  83. $hash{newnick} = $9;
  84. }
  85. return \%hash;
  86. } else {
  87. return;
  88. }
  89. }
  90. 1;