rbot.pm 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package Pisg::Parser::Format::rbot;
  2. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  3. #
  4. use strict;
  5. $^W = 1;
  6. sub new
  7. {
  8. my ($type, %args) = @_;
  9. my $self = {
  10. cfg => $args{cfg},
  11. normalline => '\[\d+/\d+/\d+ (\d+):\d+:\d+\] <([^>\s]+)>\s+(.*)',
  12. actionline => '\[\d+/\d+/\d+ (\d+):\d+:\d+\] \*{1,}\s+(\S+) (.*)',
  13. thirdline => '\[\d+/\d+/\d+ (\d+):(\d+):\d+\] @ ([^:\s]+):? ([^:\s]+):? (\S+) (\S+) ?(\S+)? ?(.*)?',
  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) {
  23. $hash{hour} = $1;
  24. $hash{nick} = $2;
  25. $hash{saying} = $3;
  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) {
  36. $hash{hour} = $1;
  37. $hash{nick} = $2;
  38. $hash{saying} = $3;
  39. return \%hash;
  40. } else {
  41. return;
  42. }
  43. }
  44. sub thirdline
  45. {
  46. my ($self, $line, $lines) = @_;
  47. my %hash;
  48. if ($line =~ /$self->{thirdline}/o) {
  49. $hash{hour} = $1;
  50. $hash{min} = $2;
  51. $hash{nick} = $3;
  52. if ($3 and (($3) eq 'Quit')) {
  53. $hash{nick} = $4;
  54. } elsif (($3) eq 'Mode') {
  55. if (($4) eq '+o') {
  56. $hash{newmode} = '+o';
  57. $hash{nick} = $5;
  58. } elsif (($4) eq '-o') {
  59. $hash{newmode} = '-o';
  60. $hash{nick} = $5;
  61. } elsif (($4) eq '+v') {
  62. $hash{newmode} = '+v';
  63. $hash{nick} = $5;
  64. } elsif (($4) eq '-v') {
  65. $hash{newmode} = '-v';
  66. $hash{nick} = $5;
  67. }
  68. }elsif (($4.$5) eq 'joinedchannel') {
  69. $hash{nick} = $3;
  70. $hash{newjoin} = $3;
  71. }elsif (($4.$5) eq 'settopic') {
  72. my $newtopic;
  73. if ($8 and $7 and $6) {
  74. $newtopic = $6.$7.$8;
  75. } elsif ($7 and $6) {
  76. $newtopic = $6.$7;
  77. } else {
  78. $newtopic = $6;
  79. }
  80. $hash{newtopic} = $newtopic;
  81. }elsif (($4.$5.$6.$7) eq 'isnowknownas') {
  82. $hash{nick} = $3;
  83. $hash{newnick} = $8;
  84. }
  85. return \%hash;
  86. } else {
  87. return;
  88. }
  89. }
  90. 1;