eggdrop.pm 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package Pisg::Parser::eggdrop;
  2. use strict;
  3. $^W = 1;
  4. my $normalline = '^\[(\d+):\d+\] <([^>]+)> (.*)';
  5. my $actionline = '^\[(\d+):\d+\] Action: (\S+) (.*)';
  6. my $thirdline = '^\[(\d+):(\d+)\] (\S+) (\S+) (\S+) (\S+)(.*)';
  7. my ($debug);
  8. sub new
  9. {
  10. my $self = shift;
  11. $debug = shift;
  12. return bless {};
  13. }
  14. sub normalline
  15. {
  16. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  17. my ($self, $line, $lines) = @_;
  18. my %hash;
  19. if ($line =~ /$normalline/) {
  20. $debug->("[$lines] Normal: $1 $2 $3");
  21. $hash{hour} = $1;
  22. $hash{nick} = $2;
  23. $hash{saying} = $3;
  24. return \%hash;
  25. } else {
  26. return;
  27. }
  28. }
  29. sub actionline
  30. {
  31. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  32. my ($self, $line, $lines) = @_;
  33. my %hash;
  34. if ($line =~ /$actionline/) {
  35. $debug->("[$lines] Action: $1 $2 $3");
  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. # Parses the 'third' line - (the third line is everything else, like
  47. # topic changes, mode changes, kicks, etc.)
  48. # thirdline() have to return a hash with the following keys, for
  49. # every format:
  50. # hour - the hour we're in (for timestamp loggin)
  51. # min - the minute we're in (for timestamp loggin)
  52. # nick - the nick
  53. # kicker - the nick which were kicked (if any)
  54. # newtopic - the new topic (if any)
  55. # newmode - deops or ops, must be '+o' or '-o', or '+ooo'
  56. # newjoin - a new nick which has joined the channel
  57. # newnick - a person has changed nick and this is the new nick
  58. #
  59. # The hash my also have a "repeated" key indicating the number of times
  60. # the line was repeated.
  61. my ($self, $line, $lines) = @_;
  62. my %hash;
  63. if ($line =~ /$thirdline/) {
  64. if (defined $7) {
  65. $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
  66. } else {
  67. $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6");
  68. }
  69. $hash{hour} = $1;
  70. $hash{min} = $2;
  71. $hash{nick} = $3;
  72. if (($4.$5) eq 'kickedfrom') {
  73. $7 =~ /^ by ([\S]+):.*/;
  74. $hash{kicker} = $1;
  75. } elsif ($3 eq 'Topic') {
  76. $7 =~ /^ by ([\S]+)![\S]+: (.*)/;
  77. $hash{nick} = $1;
  78. $hash{newtopic} = $2;
  79. } elsif (($4.$5) eq 'modechange') {
  80. my $newmode = $6;
  81. if ($7 =~ /^ .+ by ([\S]+)!.*/) {
  82. $hash{nick} = $1;
  83. $newmode =~ s/^\'//;
  84. $hash{newmode} = $newmode;
  85. }
  86. } elsif ($5 eq 'joined') {
  87. $hash{newjoin} = $3;
  88. } elsif (($3.$4) eq 'Nickchange:') {
  89. $hash{nick} = $5;
  90. $7 =~ /([\S]+)/;
  91. $hash{newnick} = $1;
  92. } elsif (($3.$4.$5) eq 'Lastmessagerepeated') {
  93. $hash{repeated} = $6;
  94. }
  95. return \%hash;
  96. } else {
  97. return;
  98. }
  99. }
  100. 1;