pircbot.pm 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. package Pisg::Parser::Format::pircbot;
  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 $ctcpchr = chr(1);
  9. my $self = {
  10. cfg => $args{cfg},
  11. normalline => '^(\d+)\s:([^!]+)![^@]+@\S+\sPRIVMSG\s([#&+!]\S+)\s:([^' . $ctcpchr . '].*)$'
  12. . '|' .
  13. '^(\d+)\s(>>>)PRIVMSG\s([#&+!]\S+)\s:([^' . $ctcpchr . '].*)$',
  14. actionline => '^(\d+)\s:([^!]+)![^@]+@\S+\sPRIVMSG\s([#&+!]\S+)\s:' . $ctcpchr . 'ACTION (.+)' . $ctcpchr . '\s*$'
  15. . '|' .
  16. '^(\d+)\s(>>>)PRIVMSG\s([#&+!]\S+)\s:' . $ctcpchr . 'ACTION (.+)' . $ctcpchr . '\s*$',
  17. thirdline => '^(\d+)\s:([^!]+)![^@]+@\S+\s(.+)$'
  18. . '|' .
  19. '^(\d+)\s(>>>)([^P].+)$',
  20. };
  21. bless($self, $type);
  22. return $self;
  23. }
  24. sub normalline
  25. {
  26. my ($self, $line, $lines) = @_;
  27. my %hash;
  28. if ($line =~ /$self->{normalline}/o) {
  29. if (defined($8)) {
  30. return unless (lc($7) eq lc($self->{cfg}->{channel}));
  31. my @time = localtime($5 / 1000);
  32. $hash{hour} = $time[2];
  33. $hash{nick} = $6;
  34. $hash{saying} = $8;
  35. } else {
  36. return unless (lc($3) eq lc($self->{cfg}->{channel}));
  37. my @time = localtime($1 / 1000);
  38. $hash{hour} = $time[2];
  39. $hash{nick} = $2;
  40. $hash{saying} = $4;
  41. }
  42. $hash{nick} = $self->{cfg}->{maintainer}
  43. if ($hash{nick} eq '>>>');
  44. return \%hash;
  45. } else {
  46. return;
  47. }
  48. }
  49. sub actionline
  50. {
  51. my ($self, $line, $lines) = @_;
  52. my %hash;
  53. if ($line =~ /$self->{actionline}/o) {
  54. if (defined($8)) {
  55. return unless (lc($7) eq lc($self->{cfg}->{channel}));
  56. my @time = localtime($5 / 1000);
  57. $hash{hour} = $time[2];
  58. $hash{nick} = $6;
  59. $hash{saying} = $8;
  60. } else {
  61. return unless (lc($3) eq lc($self->{cfg}->{channel}));
  62. my @time = localtime($1 / 1000);
  63. $hash{hour} = $time[2];
  64. $hash{nick} = $2;
  65. $hash{saying} = $4;
  66. }
  67. $hash{nick} = $self->{cfg}->{maintainer}
  68. if ($hash{nick} eq '>>>');
  69. return \%hash;
  70. } else {
  71. return;
  72. }
  73. }
  74. sub thirdline
  75. {
  76. my ($self, $line, $lines) = @_;
  77. my %hash;
  78. if ($line =~ /$self->{thirdline}/o) {
  79. my ($time, @line);
  80. if (defined($6)) {
  81. my @time = localtime($4 / 1000);
  82. $hash{hour} = $time[2];
  83. $hash{min} = $time[1];
  84. $hash{nick} = $self->{cfg}->{maintainer};
  85. @line = split(/\s+/, $6);
  86. } else {
  87. my @time = localtime($1 / 1000);
  88. $hash{hour} = $time[2];
  89. $hash{min} = $time[1];
  90. $hash{nick} = $2;
  91. @line = split(/\s+/, $3);
  92. }
  93. if ($line[0] eq 'KICK') {
  94. return unless (lc($line[1]) eq lc($self->{cfg}->{channel}));
  95. $hash{kicker} = $hash{nick};
  96. $hash{nick} = $line[2];
  97. } elsif ($line[0] eq 'TOPIC') {
  98. return unless (lc($line[1]) eq lc($self->{cfg}->{channel}));
  99. $hash{newtopic} = join(' ', @line[2..$#line]);
  100. $hash{newtopic} =~ s/^://;
  101. } elsif ($line[0] eq 'MODE') {
  102. return unless (lc($line[1]) eq lc($self->{cfg}->{channel}));
  103. $hash{newmode} = join(' ', @line[2..$#line]);
  104. } elsif ($line[0] eq 'JOIN') {
  105. return unless (lc($line[1]) eq ':' . lc($self->{cfg}->{channel}));
  106. $hash{newjoin} = $hash{nick};
  107. } elsif ($line[0] eq 'NICK') {
  108. $hash{newnick} = $line[1];
  109. $hash{newnick} =~ s/^://;
  110. }
  111. return \%hash;
  112. } else {
  113. return;
  114. }
  115. }
  116. 1;