mozbot.pm 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. package Pisg::Parser::Format::mozbot;
  2. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  3. # This is a parser for Mozbot's XMLLogger module, NOT the standard logs!
  4. # File amended from Template.pm by Adam "Fatman" Richardson
  5. use strict;
  6. $^W = 1;
  7. sub new
  8. {
  9. my ($type, %args) = @_;
  10. my $self = {
  11. cfg => $args{cfg},
  12. normalline => '<msg channel="#.+" nick="(.+)" time="(.+)">(.+)</msg>',
  13. actionline => '<emote channel="#.+" nick="(.+)" time="(.+)">(.+)</emote>',
  14. thirdline => '<(.+) channel="#.+" nick="(.+)" time="(.+)">(.*)</.+>',
  15. };
  16. bless($self, $type);
  17. return $self;
  18. }
  19. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  20. sub normalline
  21. {
  22. my ($self, $line, $lines) = @_;
  23. my %hash;
  24. if ($line =~ /$self->{normalline}/o) {
  25. my $time = $2;
  26. $hash{nick} = $1;
  27. $hash{saying} = convert($3);
  28. $time =~ /T(\d\d)/;
  29. $hash{hour} = int($1);
  30. return \%hash;
  31. } else {
  32. return;
  33. }
  34. }
  35. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  36. sub actionline
  37. {
  38. my ($self, $line, $lines) = @_;
  39. my %hash;
  40. if ($line =~ /$self->{actionline}/o) {
  41. my $time = $2;
  42. $hash{nick} = $1;
  43. $hash{saying} = convert($3);
  44. $time =~ /T(\d\d)/;
  45. $hash{hour} = int($1);
  46. return \%hash;
  47. } else {
  48. return;
  49. }
  50. }
  51. # Parses the 'third' line - (the third line is everything else, like
  52. # topic changes, mode changes, kicks, etc.)
  53. sub thirdline
  54. {
  55. my ($self, $line, $lines) = @_;
  56. my %hash;
  57. if ($line =~ /$self->{thirdline}/o) {
  58. my $time = $3;
  59. my $act = $1;
  60. my $nick = $2;
  61. my $doing = convert($4);
  62. $time =~ /T(\d\d):(\d\d)/;
  63. $hash{hour} = int($1);
  64. $hash{min} = int($2);
  65. $hash{nick} = $nick;
  66. if ($act eq 'kick') {
  67. $hash{nick} = $doing;
  68. $hash{kicker} = $nick;
  69. $hash{kicktext} = '';
  70. } elsif ($act eq 'mode') {
  71. $hash{newmode} = $doing;
  72. } elsif ($act eq 'join') {
  73. $hash{newjoin} = $nick;
  74. } elsif ($act eq 'topic') {
  75. $hash{newtopic} = $doing;
  76. }
  77. return \%hash;
  78. } else {
  79. return;
  80. }
  81. }
  82. # Convert XML-entities
  83. sub convert
  84. {
  85. my $string = shift;
  86. $string =~ s/&apos;/\'/g;
  87. $string =~ s/&quot;/\"/g;
  88. $string =~ s/&gt;/>/g;
  89. $string =~ s/&lt;/</g;
  90. $string =~ s/&amp;/&/g;
  91. return $string;
  92. }
  93. 1;