psybnc.pm 2.6 KB

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