xchat.pm 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package Pisg::Parser::Format::xchat;
  2. use strict;
  3. $^W = 1;
  4. my $normalline = '^(\d+):\d+:\d+ <([^>]+)>\s+(.*)';
  5. my $actionline = '^(\d+):\d+:\d+ \*\s+(\S+) (.*)';
  6. my $thirdline = '^(\d+):(\d+):\d+ .--\s+(\S+) (\S+) (\S+) (\S+) (\S+) (\S+) (.*)';
  7. my ($debug);
  8. # Preloaded methods go here.
  9. sub new
  10. {
  11. my $self = shift;
  12. $debug = shift;
  13. return bless {};
  14. }
  15. sub normalline
  16. {
  17. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  18. my ($self, $line, $lines) = @_;
  19. my %hash;
  20. if ($line =~ /$normalline/) {
  21. $debug->("[$lines] Normal: $1 $2 $3");
  22. $hash{hour} = $1;
  23. $hash{nick} = $2;
  24. $hash{saying} = $3;
  25. return \%hash;
  26. } else {
  27. return;
  28. }
  29. }
  30. sub actionline
  31. {
  32. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  33. my ($self, $line, $lines) = @_;
  34. my %hash;
  35. if ($line =~ /$actionline/) {
  36. $debug->("[$lines] Action: $1 $2 $3");
  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. # Parses the 'third' line - (the third line is everything else, like
  48. # topic changes, mode changes, kicks, etc.)
  49. # thirdline() have to return a hash with the following keys, for
  50. # every format:
  51. # hour - the hour we're in (for timestamp loggin)
  52. # min - the minute we're in (for timestamp loggin)
  53. # nick - the nick
  54. # kicker - the nick which were kicked (if any)
  55. # newtopic - the new topic (if any)
  56. # newmode - deops or ops, must be '+o' or '-o', or '+ooo'
  57. # newjoin - a new nick which has joined the channel
  58. # newnick - a person has changed nick and this is the new nick
  59. my ($self, $line, $lines) = @_;
  60. my %hash;
  61. if ($line =~ /$thirdline/) {
  62. $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7 $8 $9");
  63. $hash{hour} = $1;
  64. $hash{min} = $2;
  65. $hash{nick} = $3;
  66. if (($4.$5) eq 'haskicked') {
  67. $hash{kicker} = $3;
  68. $hash{nick} = $6;
  69. } elsif (($4.$5) eq 'haschanged') {
  70. $hash{newtopic} = $9;
  71. } elsif (($4.$5) eq 'giveschannel') {
  72. $hash{newmode} = '+o';
  73. } elsif (($4.$5) eq 'removeschannel') {
  74. $hash{newmode} = '-o';
  75. } elsif (($5.$6) eq 'hasjoined') {
  76. $hash{newjoin} = $1;
  77. } elsif (($5.$6) eq 'nowknown') {
  78. $hash{newnick} = $8;
  79. }
  80. return \%hash;
  81. } else {
  82. return;
  83. }
  84. }
  85. 1;