4
0

zcbot.pm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. package Pisg::Parser::Format::zcbot;
  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+):[^ ]+ :([^!]+)[^ ]+ PRIVMSG (\#[^ ]+) :([^\001].*)',
  11. actionline => '^[^ ]+ (\d+):[^ ]+ :([^!]+)[^ ]+ PRIVMSG (\#[^ ]+) :\001ACTION (.*)',
  12. thirdline => '^[^ ]+ (\d+):(\d+):\d+ :([^!]+)[^ ]+ ([A-Z]+) (.*)',
  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 && lc($3) eq lc($self->{cfg}->{channel})) {
  22. $hash{hour} = $1;
  23. $hash{nick} = $2;
  24. $hash{saying} = $4;
  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 && lc($3) eq lc($self->{cfg}->{channel})) {
  35. $hash{hour} = $1;
  36. $hash{nick} = $2;
  37. $hash{saying} = $4;
  38. return \%hash;
  39. } else {
  40. return;
  41. }
  42. }
  43. sub thirdline
  44. {
  45. my ($self, $line, $lines) = @_;
  46. my %hash;
  47. my $tmp;
  48. if ($line =~ /$self->{thirdline}/o) {
  49. $hash{hour} = $1;
  50. $hash{min} = $2;
  51. $hash{nick} = $3;
  52. my @arr = split(" ", $5);
  53. if ($4 eq 'KICK' && lc($arr[0]) eq lc($self->{cfg}->{channel})) {
  54. $hash{kicker} = $hash{nick};
  55. $hash{nick} = $arr[1];
  56. } elsif ($4 eq 'TOPIC' && lc($arr[0]) eq lc($self->{cfg}->{channel})) {
  57. $tmp = join(" ", @arr[1..$#arr]);
  58. $tmp =~ s/^://;
  59. $hash{newtopic} = $tmp;
  60. } elsif ($4 eq 'MODE' && lc($arr[0]) eq lc($self->{cfg}->{channel})) {
  61. $hash{newmode} = $arr[1];
  62. } elsif ($4 eq 'JOIN' && lc($arr[0]) eq ":".lc($self->{cfg}->{channel})) {
  63. $hash{newjoin} = $3;
  64. } elsif ($4 eq 'NICK') {
  65. $arr[0] =~ s/^://;
  66. $hash{newnick} = $arr[0];
  67. }
  68. return \%hash;
  69. } else {
  70. return;
  71. }
  72. }
  73. 1;