4
0

Trillian.pm 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package Pisg::Parser::Format::Trillian;
  2. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  3. # old format:
  4. # [hh:mm] <nick> says something
  5. # new v3 format:
  6. # [hh:mm] nick: says something
  7. use strict;
  8. $^W = 1;
  9. sub new
  10. {
  11. my ($type, %args) = @_;
  12. my $self = {
  13. cfg => $args{cfg},
  14. normalline => '^\[(\d+):\d+[^ ]+ <?([^*:>]+)[^ ]+ (.*)',
  15. actionline => '^\[(\d+):\d+[^ ]+ \* (\S+) (.*)',
  16. thirdline => '^\[(\d+):(\d+)[^ ]+ \*{3}\s(.+)',
  17. };
  18. bless($self, $type);
  19. return $self;
  20. }
  21. sub normalline
  22. {
  23. my ($self, $line, $lines) = @_;
  24. my %hash;
  25. if ($line =~ /$self->{normalline}/o) {
  26. $hash{hour} = $1;
  27. ($hash{nick} = $2) =~ s/^[@%\+~&]//o; # Remove prefix
  28. $hash{saying} = $3;
  29. $hash{saying} =~ s/\(Link: (((http|https|ftp|telnet|news):\/\/|).*?)\)\1/$1/;
  30. return \%hash;
  31. } else {
  32. return;
  33. }
  34. }
  35. sub actionline
  36. {
  37. my ($self, $line, $lines) = @_;
  38. my %hash;
  39. if ($line =~ /$self->{actionline}/o) {
  40. $hash{hour} = $1;
  41. ($hash{nick} = $2) =~ s/^[@%\+~&]//o; # Remove prefix
  42. $hash{saying} = $3;
  43. $hash{saying} =~ s/\(Link: (((http|https|ftp|telnet|news):\/\/|).*?)\)\1/$1/;
  44. return \%hash;
  45. } else {
  46. return;
  47. }
  48. }
  49. sub thirdline
  50. {
  51. my ($self, $line, $lines) = @_;
  52. my %hash;
  53. if ($line =~ /$self->{thirdline}/o) {
  54. $hash{hour} = $1;
  55. $hash{min} = $2;
  56. ($hash{nick} = $3) =~ s/^[@%\+~&]//o; # Remove prefix
  57. if ($3 =~ /^(\S+) has been kicked off channel (\S+) by (\S+) .+/) {
  58. ($hash{nick} = $1) =~ s/^[@%\+~&]//o; # Remove prefix
  59. $hash{kicker} = $3;
  60. } elsif ($3 =~ /^(\S+) has changed the topic on channel (\S+) to (.+)/) {
  61. ($hash{nick} = $1) =~ s/^[@%\+~&]//o; # Remove prefix
  62. $hash{newtopic} = $3;
  63. } elsif ($3 =~ /^Mode change \"(\S+)[^\"]+\".+ by (.+)$/) {
  64. ($hash{nick} = $2) =~ s/^[@%\+~&]//o; # Remove prefix
  65. $hash{newmode} = $1;
  66. } elsif ($3 =~ /^(\S+) \S+ has joined channel \S+/) {
  67. $hash{nick} = $1;
  68. $hash{newjoin} = $1;
  69. } elsif ($3 =~ /^(\S+) is now known as (\S+)/) {
  70. ($hash{nick} = $1) =~ s/^[@%\+~&]//o; # Remove prefix
  71. $hash{newnick} = $2;
  72. }
  73. return \%hash;
  74. } else {
  75. return;
  76. }
  77. }
  78. 1;