moobot.pm 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package Pisg::Parser::Format::moobot;
  2. use strict;
  3. $^W = 1;
  4. sub new
  5. {
  6. my ($type, %args) = @_;
  7. my $self = {
  8. cfg => $args{cfg},
  9. normalline => '^\d{4}-\d{2}-\d{2} (\d{2}):\d{2}:\d{2} :([^! ]+)(?:![^ ]+)? PUBMSG ([^ ]+) :(.*)',
  10. actionline => '^\d{4}-\d{2}-\d{2} (\d{2}):\d{2}:\d{2} :([^! ]+)(?:![^ ]+)? CTCP ([^ ]+) :ACTION (.*)',
  11. thirdline => '^\d{4}-\d{2}-\d{2} (\d{2}):(\d{2}):\d{2} :([^! ]+)(?:![^ ]+)? ([^ ]+) :?([^ ]+) ?(.*)',
  12. };
  13. bless($self, $type);
  14. return $self;
  15. }
  16. sub normalline
  17. {
  18. my ($self, $line, $lines) = @_;
  19. my %hash;
  20. if ($line =~ /$self->{normalline}/o and
  21. lc($3) eq lc($self->{cfg}->{channel})) {
  22. $hash{hour} = $1;
  23. $hash{nick} = $2;
  24. $hash{saying} = $4;
  25. return \%hash;
  26. } else {
  27. return;
  28. }
  29. }
  30. sub actionline
  31. {
  32. my ($self, $line, $lines) = @_;
  33. my %hash;
  34. if ($line =~ /$self->{actionline}/o and
  35. lc($3) eq lc($self->{cfg}->{channel})) {
  36. $hash{hour} = $1;
  37. $hash{nick} = $2;
  38. $hash{saying} = $4;
  39. return \%hash;
  40. } else {
  41. return;
  42. }
  43. }
  44. sub thirdline
  45. {
  46. my ($self, $line, $lines) = @_;
  47. my %hash;
  48. if ($line =~ /$self->{thirdline}/o and
  49. lc($5) eq ($self->{cfg}->{channel})) {
  50. my $args = $6;
  51. $hash{hour} = $1;
  52. $hash{min} = $2;
  53. $hash{nick} = $3;
  54. if ($4 eq "KICK") {
  55. $hash{kicker} = $3;
  56. $args =~ /^([^ ]+)/;
  57. $hash{nick} = $1;
  58. } elsif ($4 eq "TOPIC") {
  59. $args =~ s/^://;
  60. $hash{newtopic} = $args;
  61. } elsif ($4 eq "MODE") {
  62. $hash{newmode} = $args;
  63. } elsif ($4 eq "JOIN") {
  64. $hash{newjoin} = $3;
  65. }
  66. return \%hash;
  67. # Nick changes do not have an associated channel.
  68. } elsif ($line =~ /$self->{thirdline}/o and
  69. $4 eq "NICK") {
  70. $hash{hour} = $1;
  71. $hash{min} = $2;
  72. $hash{nick} = $3;
  73. $hash{newnick} = $5;
  74. return \%hash;
  75. } else {
  76. return;
  77. }
  78. }
  79. 1;