mbot.pm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package Pisg::Parser::Format::mbot;
  2. use strict;
  3. $^W = 1;
  4. sub new
  5. {
  6. my $type = shift;
  7. my $self = {
  8. debug => $_[0],
  9. normalline => '^\S+ \S+ \d+ (\d+):\d+:\d+ \d+ <([^>]+)> (?!\001ACTION)(.*)',
  10. actionline => '^\S+ \S+ \d+ (\d+):\d+:\d+ \d+ <([^>]+)> \001ACTION (.*)\001$',
  11. thirdline => '^\S+ \S+ \d+ (\d+):(\d+):\d+ \d+ (\S+) (\S+) ?(\S*) ?(\S*) ?(.*)',
  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. my $debugstring = "[$lines] ***: $1 $2 $3 $4";
  64. $debugstring .= " $5" if (defined $5);
  65. $debugstring .= " $6" if (defined $6);
  66. $debugstring .= " $7" if (defined $7);
  67. $self->{debug}->($debugstring);
  68. $hash{hour} = $1;
  69. $hash{min} = $2;
  70. $hash{nick} = $3;
  71. if ($4 eq 'KICK') {
  72. $hash{kicker} = $3;
  73. $hash{nick} = $5;
  74. } elsif ($4 eq 'TOPIC') {
  75. $hash{newtopic} = $5;
  76. $hash{newtopic} =~ s/^.*://;
  77. } elsif ($4 eq 'MODE') {
  78. $hash{newmode} = $5;
  79. } elsif ($4 eq 'JOIN') {
  80. $3 =~ /^([^!]+)!/;
  81. $hash{newjoin} = $1;
  82. $hash{nick} = $1;
  83. } elsif ($4 eq 'NICK') {
  84. $hash{newnick} = $5;
  85. }
  86. return \%hash;
  87. } else {
  88. return;
  89. }
  90. }
  91. 1;