rbot.pm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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} = undef;
  54. } elsif ($3 and (($3) eq 'Quit')) {
  55. $hash{nick} = $4;
  56. } elsif (($3) eq 'Mode') {
  57. if (($4) eq '+o') {
  58. $hash{newmode} = '+o';
  59. $hash{nick} = $5;
  60. } elsif (($4) eq '-o') {
  61. $hash{newmode} = '-o';
  62. $hash{nick} = $5;
  63. } elsif (($4) eq '+v') {
  64. $hash{newmode} = '+v';
  65. $hash{nick} = $5;
  66. } elsif (($4) eq '-v') {
  67. $hash{newmode} = '-v';
  68. $hash{nick} = $5;
  69. }
  70. }elsif (($4.$5) eq 'joinedchannel') {
  71. $hash{nick} = $3;
  72. $hash{newjoin} = $3;
  73. }elsif (($4.$5) eq 'settopic') {
  74. my $newtopic;
  75. if ($8 and $7 and $6) {
  76. $newtopic = "$6 $7 $8";
  77. } elsif ($7 and $6) {
  78. $newtopic = "$6 $7";
  79. } else {
  80. $newtopic = $6;
  81. }
  82. $hash{newtopic} = $newtopic;
  83. }elsif (($4.$5.$6.$7) eq 'isnowknownas') {
  84. $hash{nick} = $3;
  85. $hash{newnick} = $8;
  86. }
  87. return \%hash;
  88. } else {
  89. return;
  90. }
  91. }
  92. 1;