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