mbot.pm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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, %args) = @_;
  8. my $self = {
  9. cfg => $args{cfg},
  10. debug => $args{debug},
  11. normalline => '^\S+ \S+ \d+ (\d+):\d+:\d+ \d+ <([^>]+)> (?!\001ACTION)(.*)',
  12. actionline => '^\S+ \S+ \d+ (\d+):\d+:\d+ \d+ <([^>]+)> \001ACTION (.*)\001$',
  13. thirdline => '^\S+ \S+ \d+ (\d+):(\d+):\d+ \d+ (\S+) (\S+) ?(\S*) ?(\S*) ?(.*)',
  14. };
  15. bless($self, $type);
  16. return $self;
  17. }
  18. sub normalline
  19. {
  20. my ($self, $line, $lines) = @_;
  21. my %hash;
  22. if ($line =~ /$self->{normalline}/) {
  23. $self->{debug}->("[$lines] Normal: $1 $2 $3");
  24. $hash{hour} = $1;
  25. $hash{nick} = $2;
  26. $hash{saying} = $3;
  27. return \%hash;
  28. } else {
  29. return;
  30. }
  31. }
  32. sub actionline
  33. {
  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. my ($self, $line, $lines) = @_;
  49. my %hash;
  50. if ($line =~ /$self->{thirdline}/) {
  51. my $debugstring = "[$lines] ***: $1 $2 $3 $4";
  52. $debugstring .= " $5" if (defined $5);
  53. $debugstring .= " $6" if (defined $6);
  54. $debugstring .= " $7" if (defined $7);
  55. $self->{debug}->($debugstring);
  56. $hash{hour} = $1;
  57. $hash{min} = $2;
  58. $hash{nick} = $3;
  59. if ($4 eq 'KICK') {
  60. $hash{kicker} = $3;
  61. $hash{nick} = $5;
  62. } elsif ($4 eq 'TOPIC') {
  63. $hash{newtopic} = $5;
  64. $hash{newtopic} =~ s/^.*://;
  65. } elsif ($4 eq 'MODE') {
  66. $hash{newmode} = $5;
  67. } elsif ($4 eq 'JOIN') {
  68. $3 =~ /^([^!]+)!/;
  69. $hash{newjoin} = $1;
  70. $hash{nick} = $1;
  71. } elsif ($4 eq 'NICK') {
  72. $hash{newnick} = $5;
  73. }
  74. return \%hash;
  75. } else {
  76. return;
  77. }
  78. }
  79. 1;