irssi.pm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package Pisg::Parser::Format::irssi;
  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. normalline => '^(\d+):\d+ <[@+ ]?([^>]+)> (.*)',
  11. actionline => '^(\d+):\d+ \* (\S+) (.*)',
  12. thirdline => '^(\d+):(\d+) -\!- (\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}/o) {
  22. $hash{hour} = $1;
  23. $hash{nick} = $2;
  24. return unless index($hash{nick}, ' ') == -1;
  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}/o) {
  36. $hash{hour} = $1;
  37. $hash{nick} = $2;
  38. $hash{saying} = $3;
  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) {
  49. $hash{hour} = $1;
  50. $hash{min} = $2;
  51. $hash{nick} = $3;
  52. if (($4.$5) eq 'waskicked') {
  53. $hash{kicker} = $8;
  54. $hash{kicker} =~ m/by (\S+)/;
  55. $hash{kicker} = $1;
  56. } elsif ($4 eq 'changed') {
  57. $hash{newtopic} = $8;
  58. $hash{newtopic} =~ m/to:(.*)/;
  59. $hash{newtopic} = $1;
  60. } elsif (substr($3, 0, 5) eq 'mode/') {
  61. $hash{newmode} = substr($4, 1);
  62. $hash{nick} = $8 || $7;
  63. $hash{nick} =~ s/.* (\S+)$/$1/; # Get the last word of the string
  64. } elsif (($5.$6) eq 'hasjoined') {
  65. $hash{newjoin} = $3;
  66. } elsif (($4.$5) eq 'nowknown') {
  67. $hash{newnick} = $8;
  68. }
  69. return \%hash;
  70. } else {
  71. return;
  72. }
  73. }
  74. 1;