/
nohilight.pl
84 lines (68 loc) · 1.81 KB
/
nohilight.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
78
79
80
81
82
83
use strict;
use warnings;
# nohilight.pl is for ignoring hilight mistake.
#
# You can use this for hilight 'foobar' but ignoring 'foobarbaz'.
#
# Usage:
# /nohilight
# Show current nohilight list.
# /nohilight add <text>
# Append new nohilight.
# /nohilight del [n]
# Remove `n` nohilight.
#
use Irssi;
use POSIX ();
use utf8;
use LWP::UserAgent;
use HTTP::Request::Common;
use Digest::SHA1 qw/sha1_hex/;
use URI;
use URI::Escape;
our $VERSION = '0.1';
our %IRSSI = (
name => 'nohilight',
description => 'setting ignore hilight',
authors => 'cho45',
);
Irssi::settings_add_str('nohilight' => 'nohilight', '');
our $nohilight;
sub load {
[ split /\|/, (Irssi::settings_get_str('nohilight') || '') ];
}
sub save {
Irssi::settings_set_str('nohilight' => join '|', @$nohilight);
}
$nohilight = load();
Irssi::signal_add_first('print text', sub {
my ($dest, $text, $stripped) = @_;
return unless $dest->{level} & MSGLEVEL_HILIGHT;
my $regexp = join '|', @$nohilight;
if ($stripped =~ /$regexp/ || $dest->{target} =~ /$regexp/) {
$dest->{level} ^= MSGLEVEL_HILIGHT;
$dest->{level} |= MSGLEVEL_NOHILIGHT;
$dest->{window}->print($dest->{target} . ": " . $text, $dest->{level});
Irssi::signal_stop;
}
});
Irssi::command_bind('nohilight', sub {
my ($data, $server, $witem) = @_;
my ($act, $arg) = split /\s+/, $data, 2;
local $_ = $act || '';
/add/ and return do {
push @$nohilight, $arg;
save();
Irssi::print('Added Nohilight: ' . $arg, MSGLEVEL_CLIENTCRAP);
};
/del|re?m/ and return do {
my $r = $arg ? splice(@$nohilight, $arg - 1, 1) : pop(@$nohilight);
save();
Irssi::print('Removed Nohilight: ' . $r, MSGLEVEL_CLIENTCRAP);
};
Irssi::print('Nohilights:', MSGLEVEL_CLIENTCRAP);
my $i = 1;
for (@$nohilight) {
Irssi::print(sprintf('% 4d %s', $i++, $_), MSGLEVEL_CLIENTCRAP);
}
});