eggdrop.pm 2.8 KB

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