mbot.pm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package Pisg::Parser::Format::mbot;
  2. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  3. use strict;
  4. $^W = 1;
  5. sub new
  6. {
  7. my $type = shift;
  8. my $self = {
  9. debug => $_[0],
  10. normalline => '^\S+ \S+ \d+ (\d+):\d+:\d+ \d+ <([^>]+)> (?!\001ACTION)(.*)',
  11. actionline => '^\S+ \S+ \d+ (\d+):\d+:\d+ \d+ <([^>]+)> \001ACTION (.*)\001$',
  12. thirdline => '^\S+ \S+ \d+ (\d+):(\d+):\d+ \d+ (\S+) (\S+) ?(\S*) ?(\S*) ?(.*)',
  13. };
  14. bless($self, $type);
  15. return $self;
  16. }
  17. sub normalline
  18. {
  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. my ($self, $line, $lines) = @_;
  34. my %hash;
  35. if ($line =~ /$self->{actionline}/) {
  36. $self->{debug}->("[$lines] Action: $1 $2 $3");
  37. $hash{hour} = $1;
  38. $hash{nick} = $2;
  39. $hash{saying} = $3;
  40. return \%hash;
  41. } else {
  42. return;
  43. }
  44. }
  45. sub thirdline
  46. {
  47. my ($self, $line, $lines) = @_;
  48. my %hash;
  49. if ($line =~ /$self->{thirdline}/) {
  50. my $debugstring = "[$lines] ***: $1 $2 $3 $4";
  51. $debugstring .= " $5" if (defined $5);
  52. $debugstring .= " $6" if (defined $6);
  53. $debugstring .= " $7" if (defined $7);
  54. $self->{debug}->($debugstring);
  55. $hash{hour} = $1;
  56. $hash{min} = $2;
  57. $hash{nick} = $3;
  58. if ($4 eq 'KICK') {
  59. $hash{kicker} = $3;
  60. $hash{nick} = $5;
  61. } elsif ($4 eq 'TOPIC') {
  62. $hash{newtopic} = $5;
  63. $hash{newtopic} =~ s/^.*://;
  64. } elsif ($4 eq 'MODE') {
  65. $hash{newmode} = $5;
  66. } elsif ($4 eq 'JOIN') {
  67. $3 =~ /^([^!]+)!/;
  68. $hash{newjoin} = $1;
  69. $hash{nick} = $1;
  70. } elsif ($4 eq 'NICK') {
  71. $hash{newnick} = $5;
  72. }
  73. return \%hash;
  74. } else {
  75. return;
  76. }
  77. }
  78. 1;