irssi.pm 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. $hash{saying} = $3;
  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) {
  35. $hash{hour} = $1;
  36. $hash{nick} = $2;
  37. $hash{saying} = $3;
  38. return \%hash;
  39. } else {
  40. return;
  41. }
  42. }
  43. sub thirdline
  44. {
  45. my ($self, $line, $lines) = @_;
  46. my %hash;
  47. if ($line =~ /$self->{thirdline}/o) {
  48. $hash{hour} = $1;
  49. $hash{min} = $2;
  50. $hash{nick} = $3;
  51. if (($4.$5) eq 'waskicked') {
  52. $hash{kicker} = $8;
  53. $hash{kicker} =~ m/by (\S+)/;
  54. $hash{kicker} = $1;
  55. } elsif ($4 eq 'changed') {
  56. $hash{newtopic} = $8;
  57. $hash{newtopic} =~ m/to:(.*)/;
  58. $hash{newtopic} = $1;
  59. } elsif (substr($3, 0, 5) eq 'mode/') {
  60. $hash{newmode} = substr($4, 1);
  61. $hash{nick} = $8 || $7;
  62. $hash{nick} =~ s/.* (\S+)$/$1/; # Get the last word of the string
  63. } elsif (($5.$6) eq 'hasjoined') {
  64. $hash{newjoin} = $3;
  65. } elsif (($5.$6) eq 'nowknown') {
  66. if ($8 =~ /^\s+(\S+)/) {
  67. $hash{newnick} = $1;
  68. }
  69. }
  70. return \%hash;
  71. } else {
  72. return;
  73. }
  74. }
  75. 1;