4
0

RacBot.pm 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package Pisg::Parser::Format::RacBot;
  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+):\d+:\d+\]\s+<([^>]+)> (.*)',
  11. actionline => '^\[(\d+):\d+:\d+\]\s+\*(\S+)\s+(.*)',
  12. thirdline => '^\[(\d+):(\d+):\d+\]\s+([^-\$!#].*)',
  13. };
  14. bless($self, $type);
  15. return $self;
  16. }
  17. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  18. sub normalline
  19. {
  20. my ($self, $line, $lines) = @_;
  21. my %hash;
  22. if ($line =~ /$self->{normalline}/o) {
  23. $hash{hour} = $1;
  24. $hash{nick} = $2;
  25. $hash{saying} = $3;
  26. return \%hash;
  27. } else {
  28. return;
  29. }
  30. }
  31. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  32. sub actionline
  33. {
  34. my ($self, $line, $lines) = @_;
  35. my %hash;
  36. if ($line =~ /$self->{actionline}/o) {
  37. $hash{hour} = $1;
  38. $hash{nick} = $2;
  39. $hash{saying} = $3;
  40. return \%hash;
  41. } else {
  42. return;
  43. }
  44. }
  45. sub thirdline
  46. {
  47. my ($self, $line, $lines) = @_;
  48. my %hash;
  49. if ($line =~ /$self->{thirdline}/o) {
  50. $hash{hour} = $1;
  51. $hash{min} = $2;
  52. my @line = split /\s+/, $3;
  53. if ($#line >= 5 && $line[1].$line[2].$line[3] eq 'hasbeenkicked') {
  54. ($hash{kicker} = $line[5]) =~ s/!.*$//;
  55. ($hash{nick} = $line[0]) =~ s/!.*$//;
  56. } elsif ($line[0].$line[1] eq 'Topicchanged') {
  57. if ($line[2] eq 'to') {
  58. $hash{newtopic} = join ' ', @line[3 .. ($#line-2)];
  59. $hash{newtopic} =~ s/^"//;
  60. $hash{newtopic} =~ s/"$//;
  61. ($hash{nick} = $line[$#line]) =~ s/!.*$//;
  62. } elsif ($line[2] eq 'on') {
  63. $hash{newtopic} = join ' ', @line[7 .. $#line];
  64. $hash{newtopic} =~ s/^"//;
  65. $hash{newtopic} =~ s/"$//;
  66. ($hash{nick} = $line[5]) =~ s/!.*$//;
  67. } else {
  68. return;
  69. }
  70. } elsif ($#line >= 4 && $line[2].$line[3] eq 'hasjoined') {
  71. $hash{newjoin} = $line[0];
  72. } elsif ($#line >= 5 && $line[1].$line[2].$line[3].$line[4] eq 'isnowknownas') {
  73. $hash{newnick} = $line[5];
  74. $hash{nick} = $line[0];
  75. } elsif ($line[0].$line[$#line-1] eq 'MODEby') {
  76. ($hash{nick} = $line[$#line]) =~ s/!.*$//;
  77. $hash{newmode} = $line[1];
  78. $hash{newmode} =~ s/^"//;
  79. } else {
  80. return;
  81. }
  82. return \%hash;
  83. } else {
  84. return;
  85. }
  86. }
  87. 1;