Logfile.pm 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. package Pisg::Parser::Logfile;
  2. # Copyright and license, as well as documentation(POD) for this module is
  3. # found at the end of the file.
  4. use strict;
  5. $^W = 1;
  6. # test for Text::Iconv
  7. my $have_iconv = 1;
  8. eval 'use Text::Iconv';
  9. $have_iconv = 0 if $@;
  10. sub new
  11. {
  12. my $type = shift;
  13. my %args = @_;
  14. my $self = {
  15. cfg => $args{cfg},
  16. parser => undef
  17. };
  18. # Import common functions in Pisg::Common
  19. require Pisg::Common;
  20. Pisg::Common->import();
  21. bless($self, $type);
  22. # Pick our parser.
  23. $self->{parser} = $self->_choose_format($self->{cfg}->{format});
  24. if($self->{cfg}->{logcharsetfallback} and not $self->{cfg}->{logcharset}) {
  25. print STDERR "Warning: LogCharset undefined, assuming LogCharset = LogCharsetFallback.\n";
  26. $self->{cfg}->{logcharset} = $self->{cfg}->{logcharsetfallback};
  27. }
  28. if($self->{cfg}->{logcharset}) {
  29. if($have_iconv) {
  30. # use converter if charsets differ or there is a fallback charset
  31. # (in the latter case the converter is also used to test if the
  32. # line is in the proper charset)
  33. if(($self->{cfg}->{logcharset} ne $self->{cfg}->{charset}) or $self->{cfg}->{logcharsetfallback}) {
  34. $self->{iconv} = Text::Iconv->new($self->{cfg}->{logcharset}, $self->{cfg}->{charset});
  35. }
  36. if($self->{cfg}->{logcharsetfallback}) {
  37. $self->{iconvfallback} = Text::Iconv->new($self->{cfg}->{logcharsetfallback}, $self->{cfg}->{charset});
  38. }
  39. } else {
  40. print STDERR "Text::Iconv is not available, skipping charset conversion of logfiles\n";
  41. }
  42. }
  43. return $self;
  44. }
  45. # The function to choose which module to use.
  46. sub _choose_format
  47. {
  48. my $self = shift;
  49. my $format = shift;
  50. $self->{parser} = undef;
  51. eval <<_END;
  52. use lib '$self->{cfg}->{modules_dir}';
  53. use Pisg::Parser::Format::$format;
  54. \$self->{parser} = new Pisg::Parser::Format::$format(
  55. cfg => \$self->{cfg},
  56. );
  57. _END
  58. if ($@) {
  59. print STDERR "Could not load parser for '$format': $@\n";
  60. return undef;
  61. }
  62. return $self->{parser};
  63. }
  64. sub analyze
  65. {
  66. my $self = shift;
  67. my (%stats, %lines);
  68. if (defined $self->{parser}) {
  69. my $starttime = time();
  70. # Just initialize these to 0
  71. $stats{days} = 0;
  72. $stats{parsedlines} = 0;
  73. $stats{totallines} = 0;
  74. if (scalar(@{$self->{cfg}->{logdir}}) > 0) {
  75. # Run through all files in dir
  76. $self->_parse_dir(\%stats, \%lines);
  77. } else {
  78. my %state = (
  79. linecount => 0,
  80. lastnick => '',
  81. monocount => 0,
  82. lastnormal => '',
  83. oldtime => 24
  84. );
  85. foreach my $logfile (@{$self->{cfg}->{logfile}}) {
  86. # Run through the whole logfile
  87. $self->_parse_file(\%stats, \%lines, $logfile, \%state);
  88. }
  89. }
  90. $self->_pick_random_lines(\%stats, \%lines);
  91. _uniquify_nicks(\%stats);
  92. my ($sec,$min,$hour) = gmtime(time() - $starttime);
  93. my $processtime = sprintf('%02d hours, %02d minutes and %02d seconds', $hour, $min, $sec);
  94. $stats{processtime}{hours} = sprintf('%02d', $hour);
  95. $stats{processtime}{mins} = sprintf('%02d', $min);
  96. $stats{processtime}{secs} = sprintf('%02d', $sec);
  97. print "Channel analyzed successfully in $processtime on ",
  98. scalar localtime(time()), "\n"
  99. unless ($self->{cfg}->{silent});
  100. return \%stats;
  101. } else {
  102. print STDERR "Skipping channel '$self->{cfg}->{channel}' due to lack of parser.\n";
  103. return undef
  104. }
  105. # Shouldn't get here.
  106. return undef;
  107. }
  108. sub _parse_dir
  109. {
  110. my $self = shift;
  111. my ($stats, $lines) = @_;
  112. # Loop through each logdir we were given
  113. foreach my $logdir (@{$self->{cfg}->{logdir}}) {
  114. # Add trailing slash when it's not there..
  115. $logdir =~ s/([^\/])$/$1\//;
  116. unless ($self->{cfg}->{silent}) {
  117. unless ($self->{cfg}->{nfiles} > 0) {
  118. print "Going into $logdir and parsing all files there...\n\n"
  119. } else {
  120. print "Going into $logdir and parsing the last $self->{cfg}->{nfiles} file(s) there...\n\n"
  121. }
  122. }
  123. my @filesarray;
  124. opendir(LOGDIR, $logdir) or
  125. die("Can't opendir ${logdir}: $!");
  126. @filesarray = grep {
  127. /^[^\.]/ && /^$self->{cfg}->{logprefix}/ && -f "$logdir/$_"
  128. } readdir(LOGDIR) or
  129. die("No files in \"$logdir\" matched prefix \"$self->{cfg}->{logprefix}\"");
  130. closedir(LOGDIR);
  131. my %state = (
  132. lastnick => '',
  133. monocount => 0,
  134. oldtime => 24
  135. );
  136. if ($self->{cfg}->{logsuffix} ne '') {
  137. my @temparray;
  138. my %months = (
  139. 'jan' => '0',
  140. 'feb' => '1',
  141. 'mar' => '2',
  142. 'apr' => '3',
  143. 'may' => '4',
  144. 'jun' => '5',
  145. 'jul' => '6',
  146. 'aug' => '7',
  147. 'sep' => '8',
  148. 'oct' => '9',
  149. 'nov' => '10',
  150. 'dec' => '11',
  151. );
  152. my ($mreg, $dreg, $yreg) = split(/\|\|/, $self->{cfg}->{logsuffix});
  153. my (@month, @day, @year);
  154. for my $file (@filesarray) {
  155. LOOPSTART:
  156. if ($file =~ /$mreg/) {
  157. my $month = $1;
  158. $month = lc $month;
  159. $month = $months{$month}
  160. if (defined $months{$month});
  161. push @month, $month;
  162. } else {
  163. splice(@filesarray,$#month + 1, 1);
  164. if ($file = $filesarray[$#month + 1]) {
  165. goto LOOPSTART;
  166. } else {
  167. last;
  168. }
  169. }
  170. if ($file =~ /$dreg/) {
  171. push @day, $1;
  172. } else {
  173. splice(@filesarray,$#day + 1, 1);
  174. splice(@month,$#day + 1);
  175. if ($file = $filesarray[$#day + 1]) {
  176. goto LOOPSTART;
  177. } else {
  178. last;
  179. }
  180. }
  181. if ($file =~ /$yreg/) {
  182. push @year, $1;
  183. } else {
  184. splice(@filesarray,$#year + 1, 1);
  185. splice(@month,$#year + 1);
  186. splice(@day,$#year + 1);
  187. if ($file = $filesarray[$#year + 1]) {
  188. goto LOOPSTART;
  189. } else {
  190. last;
  191. }
  192. }
  193. }
  194. my @newarray = @filesarray[ sort {
  195. $year[$a] <=> $year[$b]
  196. ||
  197. $month[$a] <=> $month[$b]
  198. ||
  199. $day[$a] <=> $day[$b]
  200. } 0..$#filesarray ];
  201. @filesarray = @newarray;
  202. } else {
  203. @filesarray = sort {lc($a) cmp lc($b)} @filesarray;
  204. }
  205. if($self->{cfg}->{nfiles} > 0) {
  206. my $shift = @filesarray - $self->{cfg}->{nfiles};
  207. splice(@filesarray, 0, $shift) if $shift > 0;
  208. }
  209. foreach my $file (@filesarray) {
  210. $file = $logdir . $file;
  211. $self->_parse_file($stats, $lines, $file, \%state);
  212. }
  213. }
  214. }
  215. # This parses the file...
  216. sub _parse_file
  217. {
  218. my $self = shift;
  219. my ($stats, $lines, $file, $state) = @_;
  220. print "Analyzing log $file in '$self->{cfg}->{format}' format...\n"
  221. unless ($self->{cfg}->{silent});
  222. if ($file =~ /.bz2?$/ && -f $file) {
  223. open (LOGFILE, "bunzip2 -c $file |") or
  224. die("$0: Unable to open logfile($file): $!\n");
  225. } elsif ($file =~ /.gz$/ && -f $file) {
  226. open (LOGFILE, "gunzip -c $file |") or
  227. die("$0: Unable to open logfile($file): $!\n");
  228. } else {
  229. open (LOGFILE, $file) or
  230. die("$0: Unable to open logfile($file): $!\n");
  231. }
  232. my $lastnormal = '';
  233. while(my $line = <LOGFILE>) {
  234. $line = _strip_mirccodes($line);
  235. $line =~ s/\r+$//; # Strip DOS Formatting
  236. if($self->{iconv}) { # iconv is defined only if LogCharset is set
  237. my $line2 = $self->{iconv}->convert($line);
  238. if(not $line2 and $self->{iconvfallback}) {
  239. $line2 = $self->{iconvfallback}->convert($line);
  240. }
  241. if($line2) {
  242. $line = $line2;
  243. } else {
  244. print STDERR "Charset conversion failed for '$line'\n";
  245. }
  246. }
  247. my $hashref;
  248. # Match normal lines.
  249. if ($hashref = $self->{parser}->normalline($line, $.)) {
  250. my $repeated = 0;
  251. if (defined $hashref->{repeated}) {
  252. $repeated = $hashref->{repeated};
  253. }
  254. my ($hour, $nick, $saying, $i);
  255. for ($i = 0; $i <= $repeated; $i++) {
  256. if ($i > 0) {
  257. $hashref = $self->{parser}->normalline($lastnormal, $.);
  258. #Increment number of lines for repeated lines
  259. }
  260. $hour = $self->_adjusttimeoffset($hashref->{hour});
  261. $nick = find_alias($hashref->{nick});
  262. checkname($hashref->{nick}, $nick, $stats) if ($self->{cfg}->{showmostnicks});
  263. $saying = $hashref->{saying};
  264. if ($hour < $state->{oldtime}) {
  265. $stats->{days}++;
  266. $stats->{day_times}{$stats->{days}}[0] = 0;
  267. $stats->{day_times}{$stats->{days}}[1] = 0;
  268. $stats->{day_times}{$stats->{days}}[2] = 0;
  269. $stats->{day_times}{$stats->{days}}[3] = 0;
  270. $stats->{day_lines}{$stats->{days}} = 0;
  271. }
  272. $state->{oldtime} = $hour;
  273. if (!is_ignored($nick)) {
  274. $stats->{parsedlines}++;
  275. # Timestamp collecting
  276. $stats->{times}{$hour}++;
  277. $stats->{day_times}{$stats->{days}}[int($hour/6)]++;
  278. $stats->{day_lines}{$stats->{days}}++;
  279. $stats->{lines}{$nick}++;
  280. $stats->{lastvisited}{$nick} = $stats->{days};
  281. $stats->{line_times}{$nick}[int($hour/6)]++;
  282. # Count up monologues
  283. if ($state->{lastnick} eq $nick) {
  284. $state->{monocount}++;
  285. if ($state->{monocount} == 5) {
  286. $stats->{monologues}{$nick}++;
  287. }
  288. } else {
  289. $state->{monocount} = 0;
  290. }
  291. $state->{lastnick} = $nick;
  292. my $len = length($saying);
  293. if ($len > $self->{cfg}->{minquote} && $len < $self->{cfg}->{maxquote}) {
  294. push @{ $lines->{sayings}{$nick} }, $saying;
  295. } elsif (!$lines->{sayings}{$nick}) {
  296. # Just fill the users first saying in if he hasn't
  297. # said anything yet, to get rid of empty quotes.
  298. push @{ $lines->{sayings}{$nick} }, substr($saying, 0, $self->{cfg}->{maxquote});
  299. }
  300. $stats->{lengths}{$nick} += $len;
  301. $stats->{questions}{$nick}++
  302. if (index($saying, '?') > -1);
  303. $stats->{shouts}{$nick}++
  304. if (index($saying, '!') > -1);
  305. if ($saying !~ /[a-z]/o && $saying =~ /[A-Z]/o) {
  306. # Ignore single smileys on a line. eg. '<user> :P'
  307. if ($saying !~ /^[8;:=][ ^-o]?[)pPD}\]>]$/o) {
  308. $stats->{allcaps}{$nick}++;
  309. push @{ $lines->{allcaplines}{$nick} }, $line;
  310. }
  311. }
  312. if (my @foul = $saying =~ /($self->{cfg}->{foulwords})/io) {
  313. $stats->{foul}{$nick} += scalar @foul;
  314. push @{ $lines->{foullines}{$nick} }, $line;
  315. }
  316. # Who smiles the most?
  317. # A regex matching al lot of smilies
  318. $stats->{smiles}{$nick}++
  319. if ($saying =~ /[8;:=][ ^-o]?[)pPD}\]>]/o);
  320. if ($saying =~ /[8;:=][ ^-]?[\(\[\\\/{]/o and
  321. $saying !~ /\w+:\/\//o) {
  322. $stats->{frowns}{$nick}++;
  323. }
  324. # Find URLs
  325. if (my @urls = match_urls($saying)) {
  326. foreach my $url (@urls) {
  327. if(!url_is_ignored($url)) {
  328. $url =~ s/&/&amp;/g;
  329. $stats->{urlcounts}{$url}++;
  330. $stats->{urlnicks}{$url} = $nick;
  331. }
  332. }
  333. }
  334. _parse_words($stats, $saying, $nick, $self->{cfg}->{ignorewords}, $hour);
  335. }
  336. }
  337. $lastnormal = $line;
  338. $repeated = 0;
  339. }
  340. # Match action lines.
  341. elsif ($hashref = $self->{parser}->actionline($line, $.)) {
  342. $stats->{parsedlines}++;
  343. my ($hour, $nick, $saying);
  344. $hour = $self->_adjusttimeoffset($hashref->{hour});
  345. $nick = find_alias($hashref->{nick});
  346. checkname($hashref->{nick}, $nick, $stats) if ($self->{cfg}->{showmostnicks});
  347. $saying = $hashref->{saying};
  348. if ($hour < $state->{oldtime}) {
  349. $stats->{days}++;
  350. $stats->{day_times}{$stats->{days}}[0] = 0;
  351. $stats->{day_times}{$stats->{days}}[1] = 0;
  352. $stats->{day_times}{$stats->{days}}[2] = 0;
  353. $stats->{day_times}{$stats->{days}}[3] = 0;
  354. $stats->{day_lines}{$stats->{days}} = 0;
  355. }
  356. $state->{oldtime} = $hour;
  357. if (!is_ignored($nick)) {
  358. # Timestamp collecting
  359. $stats->{times}{$hour}++;
  360. $stats->{day_times}{$stats->{days}}[int($hour/6)]++;
  361. $stats->{day_lines}{$stats->{days}}++;
  362. $stats->{actions}{$nick}++;
  363. push @{ $lines->{actionlines}{$nick} }, $line;
  364. $stats->{lines}{$nick}++;
  365. $stats->{lastvisited}{$nick} = $stats->{days};
  366. $stats->{line_times}{$nick}[int($hour/6)]++;
  367. if ($saying =~ /^($self->{cfg}->{violentwords}) (\S+)(.*)/o) {
  368. my $victim;
  369. unless ($victim = is_nick($2)) {
  370. foreach my $trynick (split(/\s+/, $3)) {
  371. last if ($victim = is_nick($trynick));
  372. }
  373. unless ($victim) {
  374. $victim = $2;
  375. }
  376. }
  377. if (!is_ignored($victim)) {
  378. $stats->{violence}{$nick}++;
  379. $stats->{attacked}{$victim}++;
  380. push @{ $lines->{violencelines}{$nick} }, $line;
  381. push @{ $lines->{attackedlines}{$victim} }, $line;
  382. }
  383. }
  384. $stats->{lengths}{$nick} += length($saying);
  385. _parse_words($stats, $saying, $nick, $self->{cfg}->{ignorewords}, $hour);
  386. }
  387. }
  388. # Match *** lines.
  389. elsif (($hashref = $self->{parser}->thirdline($line, $.)) and $hashref->{nick}) {
  390. $stats->{parsedlines}++;
  391. my ($hour, $min, $nick, $kicker, $newtopic, $newmode, $newjoin);
  392. my ($newnick);
  393. $hour = $self->_adjusttimeoffset($hashref->{hour});
  394. $min = $hashref->{min};
  395. $nick = find_alias($hashref->{nick});
  396. checkname($hashref->{nick}, $nick, $stats) if ($self->{cfg}->{showmostnicks});
  397. $kicker = find_alias($hashref->{kicker})
  398. if ($hashref->{kicker});
  399. $newtopic = $hashref->{newtopic};
  400. $newmode = $hashref->{newmode};
  401. $newjoin = $hashref->{newjoin};
  402. $newnick = $hashref->{newnick};
  403. if ($hour < $state->{oldtime}) {
  404. $stats->{days}++;
  405. $stats->{day_times}{$stats->{days}}[0]=0;
  406. $stats->{day_times}{$stats->{days}}[1]=0;
  407. $stats->{day_times}{$stats->{days}}[2]=0;
  408. $stats->{day_times}{$stats->{days}}[3]=0;
  409. $stats->{day_lines}{$stats->{days}}=0;
  410. }
  411. $state->{oldtime} = $hour;
  412. if (!is_ignored($nick)) {
  413. # Timestamp collecting
  414. $stats->{times}{$hour}++;
  415. $stats->{day_times}{$stats->{days}}[int($hour/6)]++;
  416. $stats->{day_lines}{$stats->{days}}++;
  417. $stats->{lastvisited}{$nick} = $stats->{days};
  418. if (defined($kicker)) {
  419. if (!is_ignored($kicker)) {
  420. $stats->{kicked}{$kicker}++;
  421. $stats->{gotkicked}{$nick}++;
  422. push @{ $lines->{kicklines}{$nick} }, $line;
  423. }
  424. } elsif (defined($newtopic) && $newtopic ne '') {
  425. _topic_change($stats, $newtopic, $nick, $hour, $min);
  426. } elsif (defined($newmode)) {
  427. _modechanges($stats, $newmode, $nick);
  428. } elsif (defined($newjoin)) {
  429. $stats->{joins}{$nick}++;
  430. } elsif (defined($newnick) and ($self->{cfg}->{nicktracking} == 1)) {
  431. # Resolve new nick to the correct alias (this will create a hard-alias if it is using a regex)
  432. $newnick = find_alias($newnick);
  433. add_alias($nick, $newnick);
  434. checkname($nick, $newnick, $stats) if ($self->{cfg}->{showmostnicks});
  435. }
  436. }
  437. }
  438. }
  439. $stats->{totallines} = $.;
  440. close(LOGFILE);
  441. print "Finished analyzing log, $stats->{days} days, $stats->{parsedlines} lines total\n"
  442. unless ($self->{cfg}->{silent});
  443. }
  444. sub _topic_change
  445. {
  446. my $stats = shift;
  447. my $newtopic = shift;
  448. my $nick = shift;
  449. my $hour = shift;
  450. my $min = shift;
  451. my $tcount = 0;
  452. if (defined $stats->{topics}) {
  453. $tcount = @{ $stats->{topics} };
  454. }
  455. $stats->{topics}[$tcount]{topic} = $newtopic;
  456. $stats->{topics}[$tcount]{nick} = $nick;
  457. $stats->{topics}[$tcount]{hour} = $hour;
  458. $stats->{topics}[$tcount]{min} = $min;
  459. }
  460. sub _modechanges
  461. {
  462. my $stats = shift;
  463. my $newmode = shift;
  464. my $nick = shift;
  465. my (@voice, @halfops, @ops, $plus);
  466. foreach (split(//, $newmode)) {
  467. if ($_ eq 'o') {
  468. $ops[$plus]++;
  469. } elsif ($_ eq 'h') {
  470. $halfops[$plus]++;
  471. } elsif ($_ eq 'v') {
  472. $voice[$plus]++;
  473. } elsif ($_ eq '+') {
  474. $plus = 0;
  475. } elsif ($_ eq '-') {
  476. $plus = 1;
  477. }
  478. }
  479. $stats->{gaveops}{$nick} += $ops[0] if $ops[0];
  480. $stats->{tookops}{$nick} += $ops[1] if $ops[1];
  481. $stats->{gavehalfops}{$nick} += $halfops[0] if $halfops[0];
  482. $stats->{tookhalfops}{$nick} += $halfops[1] if $halfops[1];
  483. $stats->{gavevoice}{$nick} += $voice[0] if $voice[0];
  484. $stats->{tookvoice}{$nick} += $voice[1] if $voice[1];
  485. }
  486. sub _parse_words
  487. {
  488. my ($stats, $saying, $nick, $ignorewords, $hour) = @_;
  489. # Cache time of day
  490. my $tod = int($hour/6);
  491. foreach my $word (split(/[\s,!?.:;)(\"]+/o, $saying)) {
  492. $stats->{words}{$nick}++;
  493. $stats->{word_times}{$nick}[$tod]++;
  494. # remove uninteresting words
  495. next if $ignorewords and $word =~ m/$ignorewords/i;
  496. # ignore contractions
  497. next if ($word =~ m/'.{1,2}$/o);
  498. # Also ignore stuff from URLs.
  499. next if ($word =~ m/^https?$|^\/\//o);
  500. # uniquify nicks
  501. if (my $realnick = is_nick($word)) {
  502. $stats->{wordcounts}{$realnick}++;
  503. $stats->{wordnicks}{$realnick} = $nick;
  504. } else {
  505. $stats->{wordcounts}{$word}++;
  506. $stats->{wordnicks}{$word} = $nick;
  507. }
  508. }
  509. }
  510. sub _pick_random_lines
  511. {
  512. my ($self, $stats, $lines) = @_;
  513. foreach my $key (keys %{ $lines }) {
  514. foreach my $nick (keys %{ $lines->{$key} }) {
  515. $stats->{$key}{$nick} = $self->_random_line($stats, $lines, $key, $nick, 0);
  516. }
  517. }
  518. }
  519. sub _random_line
  520. {
  521. my ($self, $stats, $lines, $key, $nick, $count) = @_;
  522. my $random = ${ $lines->{$key}{$nick} }[rand@{ $lines->{$key}{$nick} }];
  523. if ($self->{cfg}->{noignoredquotes} && $random =~ /$self->{cfg}->{ignorewords}/io) {
  524. return '' if ($count > 20);
  525. return $self->_random_line($stats, $lines, $key, $nick, ++$count);
  526. } else {
  527. return $random;
  528. }
  529. }
  530. sub _uniquify_nicks {
  531. my ($stats) = @_;
  532. foreach my $word (keys %{ $stats->{wordcounts} }) {
  533. if (my $realnick = is_nick($word)) {
  534. # The lc() is an attempt at being case insensitive.
  535. if (lc($realnick) ne lc($word)) {
  536. $stats->{wordcounts}{$realnick} += $stats->{wordcounts}{$word};
  537. delete $stats->{wordcounts}{$word};
  538. delete $stats->{wordnicks}{$word};
  539. }
  540. }
  541. }
  542. }
  543. sub _strip_mirccodes
  544. {
  545. my $line = shift;
  546. # boldcode = chr(2) = oct 001
  547. # colorcode = chr(3) = oct 003
  548. # plaincode = chr(15) = oct 017
  549. # reversecode = chr(22) = oct 026
  550. # underlinecode = chr(31) = oct 037
  551. # Strip mIRC color codes
  552. $line =~ s/\003\d{1,2},\d{1,2}//go;
  553. $line =~ s/\003\d{0,2}//go;
  554. # Strip mIRC bold, plain, reverse and underline codes
  555. $line =~ s/[\002\017\026\037]//go;
  556. return $line;
  557. }
  558. sub checkname {
  559. # This function tracks nickchanges and puts them all in a hash->array,
  560. # so we can show all nicks that I user had later (only works properly
  561. # when nicktracking is enabled)
  562. my ($nick, $newnick, $stats) = @_;
  563. $stats->{nicks}{$newnick}{lc($nick)} = $nick;
  564. }
  565. sub _adjusttimeoffset
  566. {
  567. my ($self, $hour) = @_;
  568. if ($self->{cfg}{timeoffset} != 0) {
  569. # Adjust time
  570. $hour += $self->{cfg}{timeoffset};
  571. $hour = $hour % 24;
  572. }
  573. return sprintf('%02d', $hour);
  574. }
  575. 1;
  576. __END__
  577. =head1 NAME
  578. Pisg::Parser::Logfile - class to parse a normal logfile
  579. =head1 DESCRIPTION
  580. C<Pisg::Parser::Logfile> parses a logfile using the configuration variables set in the 'cfg' option passed to the constructor.
  581. =head1 SYNOPSIS
  582. use Pisg::Parser::Logfile;
  583. $analyzer = new Pisg::Parser::Logfile(
  584. cfg => $cfg,
  585. );
  586. =head1 CONSTRUCTOR
  587. =over 4
  588. =item new ( [ OPTIONS ] )
  589. This is the constructor for a new Pisg::Parser::Logfile object. C<OPTIONS> are passed in a hash like fashion using key and value pairs.
  590. Possible options are:
  591. B<cfg> - hashref containing configuration variables, created by the Pisg module.
  592. =back
  593. =head1 AUTHOR
  594. Morten Brix Pedersen <morten@wtf.dk>
  595. =head1 COPYRIGHT
  596. Copyright (C) 2001 Morten Brix Pedersen. All rights resereved.
  597. This program is free software; you can redistribute it and/or modify it
  598. under the terms of the GPL, license is included with the distribution of
  599. this file.
  600. =cut