ircII.pm 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package Pisg::Parser::Format::ircII;
  2. # Documentation for the Pisg::Parser::Format modules is found in Template.pm
  3. # Parser for logs from ircII
  4. # by James Andrewartha <trs80@tartarus.uwa.edu.au>
  5. # based on Template.pm and Trillian.pm
  6. # Note that you will need some triggers similar to these in your .ircrc to get
  7. # timestamping:
  8. # on #^timer 50 "*0" echo $0
  9. # on #^timer 50 "*5" echo $0
  10. # Known issues: the time of topic changes is only as accurate as the time-
  11. # stamping (the above lines provide 5-minute accuracy).
  12. use strict;
  13. $^W = 1;
  14. # Yes, global variables are bad. But they do need to be global to avoid pain.
  15. my ($global_hour, $global_minute);
  16. sub new
  17. {
  18. my ($type, %args) = @_;
  19. my $self = {
  20. cfg => $args{cfg},
  21. normalline => '^(<([^>]+)> (.*)|> (.*))',
  22. actionline => '^\* (\S+[^>]) (.*)',
  23. thirdline => '^((\d+):(\d+)|\*{3} (.+)|IRC log started \w+ \w+ \w+ (\d+:\d+))',
  24. };
  25. bless($self, $type);
  26. return $self;
  27. }
  28. # Parse a normal line - returns a hash with 'hour', 'nick' and 'saying'
  29. sub normalline
  30. {
  31. my ($self, $line, $lines) = @_;
  32. my %hash;
  33. if ($line =~ /$self->{normalline}/o) {
  34. $hash{hour} = $global_hour;
  35. if ($1 =~ /^<([^>]+)> (.*)/) {
  36. $hash{nick} = $1;
  37. $hash{saying} = $2;
  38. } elsif ($1 =~ /^> (.*)/) {
  39. $hash{nick} = $self->{cfg}->{maintainer};
  40. $hash{saying} = $1;
  41. }
  42. return \%hash;
  43. } else {
  44. return;
  45. }
  46. }
  47. # Parse an action line - returns a hash with 'hour', 'nick' and 'saying'
  48. sub actionline
  49. {
  50. my ($self, $line, $lines) = @_;
  51. my %hash;
  52. if ($line =~ /$self->{actionline}/o) {
  53. $hash{hour} = $global_hour;
  54. $hash{nick} = $1;
  55. $hash{saying} = $2;
  56. return \%hash;
  57. } else {
  58. return;
  59. }
  60. }
  61. sub thirdline
  62. {
  63. my ($self, $line, $lines) = @_;
  64. my %hash;
  65. if ($line =~ /$self->{thirdline}/o) {
  66. # Mainly stolen from Trillian.pm
  67. if ($1 =~ /^\*{3} (\S+) has been kicked off channel (\S+) by (\S+) .+/) {
  68. $hash{nick} = $1;
  69. $hash{kicker} = $3;
  70. } elsif ($1 =~ /^\*{3} (\S+) has changed the topic on channel (\S+) to (.+)/) {
  71. $hash{nick} = $1;
  72. $hash{newtopic} = $3;
  73. } elsif ($1 =~ /^\*{3} Mode change \"(\S+)[^\"]+\".+ by (.+)$/) {
  74. $hash{nick} = $2;
  75. $hash{newmode} = $1;
  76. } elsif ($1 =~ /^\*{3} (\S+) \S+ has joined channel \S+/) {
  77. $hash{nick} = $1;
  78. $hash{newjoin} = $1;
  79. } elsif ($1 =~ /^\*{3} (\S+) is now known as (\S+)/) {
  80. $hash{nick} = $1;
  81. $hash{newnick} = $2;
  82. } elsif ($1 =~ /^(\d+):(\d+)$/) {
  83. $global_hour = $1;
  84. $global_minute = $2;
  85. } elsif ($1 =~ /^IRC log started \w+ \w+ \w+ (\d+):(\d+)/) {
  86. $global_hour = $1;
  87. $global_minute = $2;
  88. }
  89. $hash{hour} = $global_hour;
  90. $hash{min} = $global_minute;
  91. return \%hash;
  92. } else {
  93. return;
  94. }
  95. }
  96. 1;