html/ignore_log.pl


   1 #!/usr/bin/perl
   2 
   3 # ignore_log.pl (ignore_log -- send [some] ignored events to log), Version 0.1
   4 # this script is dedicated to bormann@IRCNET.
   5 #
   6 # Copyleft (>) 2004 jsn <jason@nichego.net>
   7 #
   8 # This program is free software; you can redistribute it and/or modify
   9 # it under the terms of the GNU General Public License as published by
  10 # the Free Software Foundation; either version 2 of the License, or
  11 # (at your option) any later version.
  12 #
  13 # This program is distributed in the hope that it will be useful,
  14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16 # GNU General Public License for more details.
  17 #
  18 # The complete text of the GNU General Public License can be found
  19 # on the World Wide Web: <URL:http://www.gnu.org/licenses/gpl.html>
  20 
  21 use strict;
  22 use Irssi;
  23 
  24 use	POSIX qw/strftime/ ;
  25 
  26 use vars qw($VERSION %IRSSI);
  27 
  28 $VERSION = "0.1";
  29 %IRSSI = (
  30 	authors		=> 'Dmitry "jsn" Kim',
  31 	contact		=> 'jason@nichego.net',
  32 	name		=> 'ignore_log',
  33 	description	=> 'script to log ignored messages',
  34 	license		=> 'GPL',
  35 	url		=> 'http://',
  36 	changed		=> '2004-09-10',
  37 	changes		=> 'initial version'
  38 );
  39 
  40 Irssi::print("*****\n* $IRSSI{name} $VERSION loaded.");
  41 Irssi::print("*  use `/set ignore_log <filename>' to configure") ;
  42 Irssi::print("*  use `/set ignore_log none' to disable ignore logging") ;
  43 
  44 sub	handle_public {
  45 	my	($srv, $msg, $nick, $addr, $tgt) = @_;
  46 	return if lc(Irssi::settings_get_str("ignore_log")) eq "none" ;
  47 	write_log($nick, $msg, $tgt)
  48 	    if $srv->ignore_check($nick, $addr, $tgt, $msg, MSGLEVEL_PUBLIC) ;
  49 }
  50 
  51 sub	handle_private {
  52 	my	($srv, $msg, $nick, $addr) = @_;
  53 	return if lc(Irssi::settings_get_str("ignore_log")) eq "none" ;
  54 	write_log($nick, $msg)
  55 	    if $srv->ignore_check($nick, $addr, "", $msg, MSGLEVEL_MSGS) ;
  56 }
  57 
  58 sub	write_log {
  59     	my	($nick, $msg, $tgt) = @_ ;
  60 	$tgt ||= "->" ;
  61 	my	($lfile) = glob Irssi::settings_get_str("ignore_log");
  62 	if (open(LF, ">>$lfile")) {
  63 	    my	$ts = strftime("%D %H:%M", localtime()) ;
  64 	    print LF "[$ts] $tgt $nick $msg\n" ;
  65 	    close LF ;
  66 	} else {
  67 	    Irssi::active_win()->print("can't open file `$lfile': $!") ;
  68 	}
  69 }
  70 
  71 Irssi::settings_add_str("ignore_log", "ignore_log", "~/.irssi/ignore.log");
  72 
  73 Irssi::print("*  logging ignored users to `" .
  74 	Irssi::settings_get_str("ignore_log") . "'") ;
  75 
  76 Irssi::signal_add_first("message public", "handle_public") ;
  77 Irssi::signal_add_first("message private", "handle_private") ;
  78