Trillian.pm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. package Pisg::Parser::Format::Trillian;
  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+)[^ ]+ \*{3}\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) =~ s/^[@%\+]//o; # Remove prefix
  24. $hash{saying} = $3;
  25. $hash{saying} =~ s/\(Link: ((http|https|ftp|telnet|news):\/\/.*?)\)\1/$1/;
  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) =~ s/^[@%\+]//o; # Remove prefix
  38. $hash{saying} = $3;
  39. $hash{saying} =~ s/\(Link: ((http|https|ftp|telnet|news):\/\/.*?)\)\1/$1/;
  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}/o) {
  50. $hash{hour} = $1;
  51. $hash{min} = $2;
  52. ($hash{nick} = $3) =~ s/^[@%\+]//o; # Remove prefix
  53. if ($3 =~ /^(\S+) has been kicked off channel (\S+) by (\S+) .+/) {
  54. ($hash{nick} = $1) =~ s/^[@%\+]//o; # Remove prefix
  55. $hash{kicker} = $3;
  56. } elsif ($3 =~ /^(\S+) has changed the topic on channel (\S+) to (.+)/) {
  57. ($hash{nick} = $1) =~ s/^[@%\+]//o; # Remove prefix
  58. $hash{newtopic} = $3;
  59. } elsif ($3 =~ /^Mode change \"(\S+)[^\"]+\".+ by (.+)$/) {
  60. ($hash{nick} = $2) =~ s/^[@%\+]//o; # Remove prefix
  61. $hash{newmode} = $1;
  62. } elsif ($3 =~ /^(\S+) \S+ has joined channel \S+/) {
  63. $hash{nick} = $1;
  64. $hash{newjoin} = $1;
  65. } elsif ($3 =~ /^(\S+) is now known as (\S+)/) {
  66. ($hash{nick} = $1) =~ s/^[@%\+]//o; # Remove prefix
  67. $hash{newnick} = $2;
  68. }
  69. return \%hash;
  70. } else {
  71. return;
  72. }
  73. }
  74. 1;