hydra.pm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package Pisg::Parser::Format::hydra;
  2. use strict;
  3. $^W = 1;
  4. sub new
  5. {
  6. my ($type, %args) = @_;
  7. my $self = {
  8. cfg => $args{cfg},
  9. normalline => '^\[\d+-\d+-\d+ (\d+):\d+:\d+\] <([^>\s]+)> (.*)',
  10. actionline => '^\[\d+-\d+-\d+ (\d+):\d+:\d+\] \* (\S+) (.+)',
  11. thirdline => '^\[\d+-\d+-\d+ (\d+):(\d+):\d+\] \*{3} (.+)',
  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) {
  21. $hash{hour} = $1;
  22. $hash{nick} = $2;
  23. $hash{saying} = $3;
  24. return \%hash;
  25. } else {
  26. return;
  27. }
  28. }
  29. sub actionline
  30. {
  31. my ($self, $line, $lines) = @_;
  32. my %hash;
  33. if ($line =~ /$self->{actionline}/o) {
  34. $hash{hour} = $1;
  35. $hash{nick} = $2;
  36. $hash{saying} = $3;
  37. return \%hash;
  38. } else {
  39. return;
  40. }
  41. }
  42. sub thirdline
  43. {
  44. my ($self, $line, $lines) = @_;
  45. my %hash;
  46. if ($line =~ /$self->{thirdline}/o) {
  47. $hash{hour} = $1;
  48. $hash{min} = $2;
  49. $hash{nick} = $3;
  50. # Format-specific stuff goes here.
  51. if ($3 =~ /^(\S+) was kicked from (\S+) by (\S+) (.+)/) {
  52. $hash{nick} = $1;
  53. $hash{kicker} = $3;
  54. $hash{kicktext} = $4;
  55. } elsif ($3 =~ /^(\S+) changed topic to (.+)/) {
  56. $hash{nick} = $1;
  57. $hash{newtopic} = $2;
  58. } elsif ($3 =~ /^(\S+) sets channel \S+ mode (\S+) (.+)/) {
  59. $hash{nick} = $1;
  60. $hash{newmode} = $2;
  61. $hash{modechanges} = $3;
  62. } elsif ($3 =~ /^(\S+) \S+ has joined channel \S+/) {
  63. $hash{nick} = $1;
  64. $hash{newjoin} = $1;
  65. } elsif ($3 =~ /^(\S+) changed nick to (\S+)/) {
  66. $hash{nick} = $1;
  67. $hash{newnick} = $2;
  68. }
  69. return \%hash;
  70. } else {
  71. return;
  72. }
  73. }
  74. 1;