psybnc.pm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package Pisg::Parser::Format::psybnc;
  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 => '^\d+-\d+-\d+-(\d+)-\d+-\d+:[^:]+::([^!]+)[^:]+:(.*)',
  12. actionline => '^\d+-\d+-\d+-(\d+)-\d+-\d+:[^:]+::([^!]+)[^:]+:\001ACTION (.*)',
  13. thirdline => '^\d+-\d+-\d+-(\d+)-(\d+)-\d+:[^:]+::([^!]+)[^ ]+ (\w+) (.*)',
  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}/o) {
  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}/o) {
  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}/o) {
  51. $self->{debug}->("[$lines] ***: $1 $2 $3 $4 $5");
  52. $hash{hour} = $1;
  53. $hash{min} = $2;
  54. $hash{nick} = $3;
  55. my @arr = split(" ", $5);
  56. if ($4 eq 'KICK') {
  57. $hash{kicker} = $hash{nick};
  58. $hash{nick} = $arr[1];
  59. } elsif ($4 eq 'TOPIC') {
  60. $hash{newtopic} = join(" ", @arr[1..@arr]);
  61. } elsif ($4 eq 'MODE') {
  62. $hash{newmode} = $arr[1];
  63. $hash{newtopic} =~ s/^://;
  64. } elsif ($4 eq 'JOIN') {
  65. $hash{newjoin} = $3;
  66. } elsif ($4 eq 'NICK') {
  67. $hash{newnick} = $arr[1];;
  68. }
  69. return \%hash;
  70. } else {
  71. return;
  72. }
  73. }
  74. 1;