weechat.pm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package Pisg::Parser::Format::weechat;
  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+ \S+ \d+ (\d+):\d+[^<]+<([^>]+)> (.*)',
  11. actionline => '^\d+ \S+ \d+ (\d+):\d+:\d+ -\*- (\S+) (.*)',
  12. thirdline => '^\d+ \S+ \d+ (\d+):(\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 'haskicked') {
  52. $hash{nick} = $6;
  53. $hash{kicker} = $3;
  54. } elsif ($4.$5.$6 eq 'haschangedtopic') {
  55. $hash{newtopic} = $8;
  56. $hash{newtopic} =~ m/to:(.*)/;
  57. $hash{newtopic} = $1;
  58. } elsif ($3 eq 'Mode') {
  59. $hash{newmode} = substr($5, 1);
  60. $hash{nick} = $8 || $7;
  61. $hash{nick} =~ s/.* (\S+)$/$1/; # Get the last word of the string
  62. } elsif (($5.$6) eq 'hasjoined') {
  63. $hash{newjoin} = $3;
  64. } elsif (($5.$6) eq 'nowknown') {
  65. if ($8 =~ /^\s+(\S+)/) {
  66. $hash{newnick} = $1;
  67. }
  68. }
  69. return \%hash;
  70. } else {
  71. return;
  72. }
  73. }
  74. 1;