-
Notifications
You must be signed in to change notification settings - Fork 0
/
wmii_notify.pl
132 lines (101 loc) · 3.5 KB
/
wmii_notify.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
use strict;
use vars qw($VERSION %IRSSI);
use Irssi;
$VERSION = '1.00';
%IRSSI = (
authors => 'Mike Maxim',
contact => '[email protected]',
name => 'wmii notifier',
description => 'Alert user through wmii bottom var',
license => 'Public'
);
#------------------------------------------------------------------------------
sub wmii_clear_note {
my ($type, $name) = @_;
open STDERR, '>/dev/null';
system("wmiir remove /rbar/irssi_" . $type . '_' . $name);
}
#------------------------------------------------------------------------------
sub wmii_create_note {
my ($type, $name) = @_;
open STDERR, '>/dev/null';
my $echo_cmd = 'echo \'#ffffff #ff0000 #aaaaaa irssi alert - ' . $type . ' - ' .
$name . '\'';
my $cmd = $echo_cmd . ' | wmiir create /rbar/irssi_' . $type . '_' .$name;
system($cmd);
}
#------------------------------------------------------------------------------
sub get_nick {
my $server = Irssi::active_server();
return $server->{nick};
}
#------------------------------------------------------------------------------
sub map_type_name {
my $ty = $_[0];
if ($ty eq "QUERY") {
return "privmsg";
} elsif ($ty eq "CHANNEL") {
return "chanmsg";
} else {
return "";
}
}
#------------------------------------------------------------------------------
sub clear_note {
my ($data, $server, $witem, $type) = @_;
if (length($data) > 0) {
wmii_clear_note($type, $data);
} elsif ($witem->{type} eq "QUERY" ||
$witem->{type} eq "CHANNEL") {
wmii_clear_note(map_type_name($witem->{type}), $witem->{name});
}
}
#------------------------------------------------------------------------------
sub cmd_clear_note {
my @arg = @_;
my ($data, $server, $witem, $type) = @_;
if (length($data) > 0) {
if (substr($data, 0, 1) eq '#') {
push(@arg, 'chanmsg');
} else {
push(@arg, 'privmsg');
}
} else {
push(@arg, '');
}
clear_note(@arg);
}
#------------------------------------------------------------------------------
sub event_windowchanged {
my ($window, $window_old) = @_;
my $witem = $window->{active};
wmii_clear_note(map_type_name($witem->{type}), $witem->{name});
}
#------------------------------------------------------------------------------
sub event_messagepublic {
my ($server, $msg, $nick, $address, $target) = @_;
my @keywords = ("okdev", "okevents", get_nick());
foreach (@keywords) {
if ($msg =~ m/$_/) {
wmii_create_note('chanmsg', $target);
last;
}
}
}
#------------------------------------------------------------------------------
sub event_messageprivate {
my ($server, $msg, $nick, $address) = @_;
wmii_create_note('privmsg', $nick);
}
#------------------------------------------------------------------------------
sub event_mymessageprivate {
my ($server, $msg, $target, $orig_target) = @_;
wmii_clear_note('privmsg', $orig_target);
}
#------------------------------------------------------------------------------
Irssi::command_bind wclear => \&cmd_clear_note;
Irssi::signal_add("window changed", "event_windowchanged");
Irssi::signal_add("message public", "event_messagepublic");
Irssi::signal_add("message private", "event_messageprivate");
Irssi::signal_add("message own_private", "event_mymessageprivate");
#------------------------------------------------------------------------------