oer.pm 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package Pisg::Parser::Format::oer;
  2. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  3. use strict;
  4. use POSIX qw(strftime);
  5. $^W = 1;
  6. sub new
  7. {
  8. my ($type, %args) = @_;
  9. my $self = {
  10. cfg => $args{cfg},
  11. normalline => '^(\d+)\s+:([^!]+)[^ ]+ PRIVMSG (\#[^ ]+) :([^\001].*)',
  12. actionline => '^(\d+)\s+:([^!]+)[^ ]+ PRIVMSG (\#[^ ]+) :\001ACTION (.*)',
  13. thirdline => '^(\d+)\s+:([^!]+)[^ ]+ ([A-Z]+) (.*)',
  14. };
  15. bless($self, $type);
  16. return $self;
  17. }
  18. sub normalline
  19. {
  20. my ($self, $line, $lines) = @_;
  21. my %hash;
  22. if ($line =~ /$self->{normalline}/o && lc($3) eq lc($self->{cfg}->{channel})) {
  23. $hash{hour} = strftime "%H", localtime($1);
  24. $hash{nick} = $2;
  25. $hash{saying} = $4;
  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 && lc($3) eq lc($self->{cfg}->{channel})) {
  36. $hash{hour} = strftime "%H", localtime($1);
  37. $hash{nick} = $2;
  38. $hash{saying} = $4;
  39. return \%hash;
  40. } else {
  41. return;
  42. }
  43. }
  44. sub thirdline
  45. {
  46. my ($self, $line, $lines) = @_;
  47. my %hash;
  48. my $tmp;
  49. if ($line =~ /$self->{thirdline}/o) {
  50. $hash{hour} = strftime "%H", localtime($1);
  51. $hash{min} = strftime "%M", localtime($1);
  52. $hash{nick} = $2;
  53. my @arr = split(" ", $4);
  54. if ($3 eq 'KICK' && lc($arr[0]) eq lc($self->{cfg}->{channel})) {
  55. $hash{kicker} = $hash{nick};
  56. $hash{nick} = $arr[1];
  57. } elsif ($3 eq 'TOPIC' && lc($arr[0]) eq lc($self->{cfg}->{channel})) {
  58. $tmp = join(" ", @arr[1..$#arr]);
  59. $tmp =~ s/^://;
  60. $hash{newtopic} = $tmp;
  61. } elsif ($3 eq 'MODE' && lc($arr[0]) eq lc($self->{cfg}->{channel})) {
  62. $hash{newmode} = $arr[1];
  63. } elsif ($3 eq 'JOIN' && lc($arr[0]) eq ":".lc($self->{cfg}->{channel})) {
  64. $hash{newjoin} = $3;
  65. } elsif ($3 eq 'NICK') {
  66. $arr[0] =~ s/^://;
  67. $hash{newnick} = $arr[0];
  68. }
  69. return \%hash;
  70. } else {
  71. return;
  72. }
  73. }
  74. 1;