Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.62 KB | None | 0 0
  1. package Pisg::Parser::Format::Trillian;
  2.  
  3. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  4.  
  5. # old format:
  6. # [hh:mm] <nick> says something
  7. # new v3 format:
  8. # [hh:mm] nick: says something
  9.  
  10. use strict;
  11. $^W = 1;
  12.  
  13. sub new
  14. {
  15.     my ($type, %args) = @_;
  16.     my $self = {
  17.         cfg => $args{cfg},
  18.         normalline => '^\[(\d+):\d+[^ ]+ <?([^*:>]+)[^ ]+ (.*)', #make this accept: [hh:mm:ss AM] <nick> message
  19.         actionline => '^\[(\d+):\d+[^ ]+ \* (\S+) (.*)', #make this accept: [hh:mm:ss AM] * nick action
  20.         thirdline  => '^\[(\d+):(\d+)[^ ]+ \*{3}\s(.+)', #make this accept: [hh:mm:ss AM] *** nick!~uname@host action
  21.     };
  22.  
  23.     bless($self, $type);
  24.     return $self;
  25. }
  26.  
  27. sub normalline
  28. {
  29.     my ($self, $line, $lines) = @_;
  30.     my %hash;
  31.  
  32.     if ($line =~ /$self->{normalline}/o) {
  33.  
  34.         $hash{hour}   = $1;
  35.         ($hash{nick}  = $2) =~ s/^[@%\+~&]//o; # Remove prefix
  36.         $hash{saying} = $3;
  37.         $hash{saying} =~ s/\(Link: (((http|https|ftp|telnet|news):\/\/|).*?)\)\1/$1/;
  38.  
  39.         return \%hash;
  40.     } else {
  41.         return;
  42.     }
  43. }
  44.  
  45. sub actionline
  46. {
  47.     my ($self, $line, $lines) = @_;
  48.     my %hash;
  49.  
  50.     if ($line =~ /$self->{actionline}/o) {
  51.  
  52.         $hash{hour}   = $1;
  53.         ($hash{nick}  = $2) =~ s/^[@%\+~&]//o; # Remove prefix
  54.         $hash{saying} = $3;
  55.         $hash{saying} =~ s/\(Link: (((http|https|ftp|telnet|news):\/\/|).*?)\)\1/$1/;
  56.  
  57.         return \%hash;
  58.     } else {
  59.         return;
  60.     }
  61. }
  62.  
  63. sub thirdline
  64. {
  65.     my ($self, $line, $lines) = @_;
  66.     my %hash;
  67.  
  68.     if ($line =~ /$self->{thirdline}/o) {
  69.  
  70.         $hash{hour} = $1;
  71.         $hash{min}  = $2;
  72.         ($hash{nick}  = $3) =~ s/^[@%\+~&]//o; # Remove prefix
  73.  
  74.         if ($3 =~ /^(\S+) has been kicked off channel (\S+) by (\S+) .+/) {
  75.             ($hash{nick}  = $1) =~ s/^[@%\+~&]//o; # Remove prefix
  76.             $hash{kicker} = $3;
  77.  
  78.         } elsif ($3 =~ /^(\S+) has changed the topic on channel (\S+) to (.+)/) {
  79.             ($hash{nick}  = $1) =~ s/^[@%\+~&]//o; # Remove prefix
  80.              $hash{newtopic} = $3;
  81.  
  82.         } elsif ($3 =~ /^Mode change \"(\S+)[^\"]+\".+ by (.+)$/) {
  83.             ($hash{nick}  = $2) =~ s/^[@%\+~&]//o; # Remove prefix
  84.              $hash{newmode} = $1;
  85.  
  86.         } elsif ($3 =~ /^(\S+) \S+ has joined channel \S+/) {
  87.             $hash{nick} = $1;
  88.             $hash{newjoin} = $1;
  89.  
  90.         } elsif ($3 =~ /^(\S+) is now known as (\S+)/) {
  91.             ($hash{nick}  = $1) =~ s/^[@%\+~&]//o; # Remove prefix
  92.             $hash{newnick} = $2;
  93.         }
  94.  
  95.         return \%hash;
  96.  
  97.     } else {
  98.         return;
  99.     }
  100. }
  101.  
  102. 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement