xchat.pm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package Pisg::Parser::Format::xchat;
  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 => '^(\d+):\d+:\d+ <([^>]+)>\s+(.*)',
  11. actionline => '^(\d+):\d+:\d+ \*\s+(\S+) (.*)',
  12. thirdline => '^(\d+):(\d+):\d+ .--\s+(\S+) (\S+) (\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. $self->{debug}->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8 $9");
  51. $hash{hour} = $1;
  52. $hash{min} = $2;
  53. $hash{nick} = $3;
  54. if (($4.$5) eq 'haskicked') {
  55. $hash{kicker} = $3;
  56. $hash{nick} = $6;
  57. } elsif (($4.$5) eq 'haschanged') {
  58. $hash{newtopic} = $9;
  59. } elsif (($4.$5) eq 'giveschannel') {
  60. $hash{newmode} = '+o';
  61. } elsif (($4.$5) eq 'removeschannel') {
  62. $hash{newmode} = '-o';
  63. } elsif (($5.$6) eq 'hasjoined') {
  64. $hash{newjoin} = $1;
  65. } elsif (($5.$6) eq 'nowknown') {
  66. $hash{newnick} = $8;
  67. }
  68. return \%hash;
  69. } else {
  70. return;
  71. }
  72. }
  73. 1;