Skip to content

Commit ab5fa92

Browse files
committed
added
1 parent af5e2ac commit ab5fa92

File tree

2 files changed

+273
-7
lines changed

2 files changed

+273
-7
lines changed

weechat-plugins/beep.pl

+269
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
#
2+
# Copyright (C) 2006-2012 Sebastien Helleu <flashcode@flashtux.org>
3+
# Copyright (C) 2011 Nils Görs <weechatter@arcor.de>
4+
# Copyright (C) 2011 ArZa <arza@arza.us>
5+
#
6+
# This program is free software; you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation; either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
#
19+
#
20+
# Beep (terminal bell) and/or run command on highlight/private message or new DCC.
21+
#
22+
# History:
23+
# 2015 and onwards: customised by proycon
24+
# 2012-06-05, ldvx<ldvx@freenode>:
25+
# version 1.1: Added wildcard support for whitelist_nicks.
26+
# 2012-05-09, ldvx <ldvx@freenode>:
27+
# version 1.0: Added beep_pv_blacklist, beep_highlight_blacklist, blacklist_nicks,
28+
# and wildcard support for blacklist_nicks.
29+
# 2012-05-02, ldvx <ldvx@freenode>:
30+
# version 0.9: fix regex for nick in tags, add options "whitelist_channels"
31+
# and "bell_always"
32+
# 2012-04-19, ldvx <ldvx@freenode>:
33+
# version 0.8: add whitelist, trigger, use hook_process for commands,
34+
# rename option "beep_command" to "beep_command_pv", add help for options
35+
# 2011-04-16, ArZa <arza@arza.us>:
36+
# version 0.7: fix default beep command
37+
# 2011-03-11, nils_2 <weechatter@arcor.de>:
38+
# version 0.6: add additional command options for dcc and highlight
39+
# 2011-03-09, nils_2 <weechatter@arcor.de>:
40+
# version 0.5: add option for beep command and dcc
41+
# 2009-05-02, Sebastien Helleu <flashcode@flashtux.org>:
42+
# version 0.4: sync with last API changes
43+
# 2008-11-05, Sebastien Helleu <flashcode@flashtux.org>:
44+
# version 0.3: conversion to WeeChat 0.3.0+
45+
# 2007-08-10, Sebastien Helleu <flashcode@flashtux.org>:
46+
# version 0.2: upgraded licence to GPL 3
47+
# 2006-09-02, Sebastien Helleu <flashcode@flashtux.org>:
48+
# version 0.1: initial release
49+
50+
use strict;
51+
my $SCRIPT_NAME = "beep";
52+
my $VERSION = "1.1";
53+
54+
# default values in setup file (~/.weechat/plugins.conf)
55+
my %options_default = ('beep_pv' => ['on', 'beep on private message'],
56+
'beep_pv_whitelist' => ['off', 'turn whitelist for private messages on or off'],
57+
'beep_pv_blacklist' => ['off', 'turn blacklist for private messages on or off'],
58+
'beep_highlight' => ['on', 'beep on highlight'],
59+
'beep_highlight_whitelist' => ['off', 'turn whitelist for highlights on or off'],
60+
'beep_highlight_blacklist' => ['off', 'turn blacklist for highlights on or off'],
61+
'beep_dcc' => ['on', 'beep on dcc'],
62+
'beep_trigger_pv' => ['', 'word that will trigger execution of beep_command_pv (it empty, anything will trigger)'],
63+
'beep_trigger_highlight' => ['', 'word that will trigger execution of beep_command_highlight (if empty, anything will trigger)'],
64+
'beep_command_pv' => ['$bell', 'command for beep on private message, special value "$bell" is allowed, as well as "$bell;command"'],
65+
'beep_command_highlight' => ['$bell', 'command for beep on highlight, special value "$bell" is allowed, as well as "$bell;command"'],
66+
'beep_command_dcc' => ['$bell', 'command for beep on dcc, special value "$bell" is allowed, as well as "$bell;command"'],
67+
'beep_command_timeout' => ['30000', 'timeout for command run (in milliseconds, 0 = never kill (not recommended))'],
68+
'whitelist_nicks' => ['', 'comma-separated list of "server.nick": if not empty, only these nicks will trigger execution of commands (example: "freenode.nick1,freenode.nick2")'],
69+
'blacklist_nicks' => ['', 'comma-separated list of "server.nick": if not empty, these nicks will not be able to trigger execution of commands. Cannot be used in conjuction with whitelist (example: "freenode.nick1,freenode.nick2")'],
70+
'whitelist_channels' => ['', 'comma-separated list of "server.#channel": if not empty, only these channels will trigger execution of commands (example: "freenode.#weechat,freenode.#channel2")'],
71+
'bell_always' => ['', 'use $bell on private messages and/or highlights regardless of trigger and whitelist settings (example: "pv,highlight")'],
72+
);
73+
my %options = ();
74+
75+
weechat::register($SCRIPT_NAME, "FlashCode <flashcode\@flashtux.org>", $VERSION,
76+
"GPL3", "Beep (terminal bell) and/or run command on highlight/private message or new DCC", "", "");
77+
init_config();
78+
79+
weechat::hook_config("plugins.var.perl.$SCRIPT_NAME.*", "toggle_config_by_set", "");
80+
weechat::hook_print("", "", "", 1, "pv_and_highlight", "");
81+
weechat::hook_signal("irc_dcc", "dcc", "");
82+
83+
sub pv_and_highlight
84+
{
85+
my ($data, $buffer, $date, $tags, $displayed, $highlight, $prefix, $message) = @_;
86+
87+
# return if message is filtered
88+
return weechat::WEECHAT_RC_OK if ($displayed != 1);
89+
90+
# return if nick in message is own nick
91+
my $nick = "";
92+
$nick = $2 if ($tags =~ m/(^|,)nick_([^,]*)(,|$)/);
93+
my $channel = weechat::buffer_get_string($buffer, "short_name");
94+
return weechat::WEECHAT_RC_OK if ($channel eq "*status");
95+
return weechat::WEECHAT_RC_OK if (weechat::buffer_get_string($buffer, "localvar_nick") eq $nick);
96+
97+
# highlight
98+
if ($highlight)
99+
{
100+
return weechat::WEECHAT_RC_OK if (substr($message,0,1) eq "["); #these may be highlights from earlier sessions by ZNC
101+
# Always print visual bel, regardless of whitelist and trigger settings
102+
# beep_command_highlight does not need to contain $bell
103+
if ($options{bell_always} =~ m/(^|,)highlight(,|$)/)
104+
{
105+
print STDERR "\a";
106+
}
107+
# Channels whitelist for highlights
108+
if ($options{beep_highlight} eq "on")
109+
{
110+
if ($options{whitelist_channels} ne "")
111+
{
112+
my $serverandchannel = weechat::buffer_get_string($buffer, "localvar_server"). "." .
113+
weechat::buffer_get_string($buffer, "localvar_channel");
114+
if ($options{beep_trigger_highlight} eq "" or $message =~ m/\b$options{beep_trigger_highlight}\b/)
115+
{
116+
if ($options{whitelist_channels} =~ /(^|,)$serverandchannel(,|$)/)
117+
{
118+
beep_exec_command($options{beep_command_highlight},$nick, $channel);
119+
}
120+
# What if we are highlighted and we're in a PM? For now, do nothing.
121+
}
122+
}
123+
else
124+
{
125+
# Execute $bell and/or command with trigger and whitelist/blacklist settings
126+
beep_trigger_whitelist_blacklist($buffer, $message, $nick, $options{beep_trigger_highlight},
127+
$options{beep_highlight_whitelist}, $options{beep_highlight_blacklist},
128+
$options{beep_command_highlight});
129+
}
130+
}
131+
}
132+
# private message
133+
elsif (weechat::buffer_get_string($buffer, "localvar_type") eq "private" and $tags =~ m/(^|,)notify_private(,|$)/)
134+
{
135+
# Always print visual bel, regardless of whitelist and trigger settings
136+
# beep_command_pv does not need to contain $bell
137+
if ($options{bell_always} =~ m/(^|,)pv(,|$)/)
138+
{
139+
print STDERR "\a";
140+
}
141+
# Execute $bell and/or command with trigger and whitelist/blacklist settings
142+
if ($options{beep_pv} eq "on")
143+
{
144+
beep_trigger_whitelist_blacklist($buffer, $message, $nick, $options{beep_trigger_pv},
145+
$options{beep_pv_whitelist}, $options{beep_pv_blacklist},
146+
$options{beep_command_pv});
147+
}
148+
}
149+
return weechat::WEECHAT_RC_OK;
150+
}
151+
152+
sub dcc
153+
{
154+
beep_exec_command($options{beep_command_dcc}) if ($options{beep_dcc} eq "on");
155+
return weechat::WEECHAT_RC_OK;
156+
}
157+
158+
sub beep_trigger_whitelist_blacklist
159+
{
160+
my ($buffer, $message, $nick, $trigger, $whitelist, $blacklist, $command) = @_;
161+
my $channel = weechat::buffer_get_string($buffer, "short_name");
162+
163+
if ($trigger eq "" or $message =~ m/\b$trigger\b/)
164+
{
165+
my $serverandnick = weechat::buffer_get_string($buffer, "localvar_server").".".$nick;
166+
# v-- PATCHED by proycon, use only nick without server part
167+
if ($whitelist eq "on" and $options{whitelist_nicks} ne "")
168+
{
169+
# What to do if there's a wildcard in the whitelit
170+
if ($options{whitelist_nicks} =~ m/\*/ and
171+
match_in_wild_card($nick, $options{whitelist_nicks}))
172+
{
173+
beep_exec_command($command,$nick, $channel);
174+
}
175+
# What to do if there's no wildcard in the whitelist
176+
elsif ($options{whitelist_nicks} =~ /(^|,)$nick(,|$)/)
177+
{
178+
beep_exec_command($command,$nick, $channel);
179+
}
180+
}
181+
elsif ($blacklist eq "on" and $options{blacklist_nicks} ne "")
182+
{
183+
# What to do if there's a wildcard in the blacklist
184+
if ($options{blacklist_nicks} =~ m/\*/ and
185+
!match_in_wild_card($nick, $options{blacklist_nicks}))
186+
{
187+
beep_exec_command($command,$nick, $channel);
188+
}
189+
# What to do if there's no wildcard in the blacklist
190+
elsif ($options{blacklist_nicks} !~ /(^|,)$nick(,|$)/)
191+
{
192+
beep_exec_command($command,$nick, $channel);
193+
}
194+
}
195+
# What to do if we are not using whitelist of blacklist feature
196+
elsif ($whitelist eq "off" and $blacklist eq "off")
197+
{
198+
beep_exec_command($command,$nick, $channel);
199+
}
200+
}
201+
}
202+
203+
sub beep_exec_command
204+
{
205+
my $command = $_[0];
206+
if ($command =~ /^\$bell/)
207+
{
208+
print STDERR "\a";
209+
($command) = $command =~ /^\$bell;(.+)$/;
210+
}
211+
my $nick = $_[1];
212+
my $channel = $_[2];
213+
my $timestamp = time();
214+
$command =~ s/\$nick/$nick/;
215+
$command =~ s/\$channel/$channel/;
216+
$command =~ s/\$timestamp/$timestamp/;
217+
weechat::hook_process($command, $options{beep_command_timeout}, "my_process", "") if ($command);
218+
}
219+
220+
sub match_in_wild_card
221+
{
222+
my ($serverandnick, $white_or_black) = @_;
223+
my $nick_iter;
224+
my @array_of_nicks = split(",", $white_or_black);
225+
226+
foreach $nick_iter (@array_of_nicks)
227+
{
228+
$nick_iter =~ s/\*/[^,]*/g;
229+
if ($serverandnick =~ /$nick_iter/)
230+
{
231+
return 1;
232+
}
233+
}
234+
return 0;
235+
}
236+
237+
sub my_process
238+
{
239+
return weechat::WEECHAT_RC_OK;
240+
}
241+
242+
sub toggle_config_by_set
243+
{
244+
my ($pointer, $name, $value) = @_;
245+
$name = substr($name, length("plugins.var.perl.".$SCRIPT_NAME."."), length($name));
246+
$options{$name} = $value;
247+
return weechat::WEECHAT_RC_OK;
248+
}
249+
250+
sub init_config
251+
{
252+
my $version = weechat::info_get("version_number", "") || 0;
253+
foreach my $option (keys %options_default)
254+
{
255+
if (!weechat::config_is_set_plugin($option))
256+
{
257+
weechat::config_set_plugin($option, $options_default{$option}[0]);
258+
$options{$option} = $options_default{$option}[0];
259+
}
260+
else
261+
{
262+
$options{$option} = weechat::config_get_plugin($option);
263+
}
264+
if ($version >= 0x00030500)
265+
{
266+
weechat::config_set_desc_plugin($option, $options_default{$option}[1]." (default: \"".$options_default{$option}[0]."\")");
267+
}
268+
}
269+
}

weechat-plugins/himan.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
SCRIPT_LICENSE = 'GPL3'
3737
SCRIPT_DESC = "What have they been saying about you?"
3838

39-
OPTIONS = {'buffer_color' : ("gray", 'color of buffer name'),
40-
'nick_color' : ("gray", 'color of mentioners nick'),
39+
OPTIONS = {'buffer_color' : ("magenta", 'color of buffer name'),
40+
'nick_color' : ("green", 'color of mentioners nick'),
4141
'nick_blacklist' : ("gitlama,f00f", 'comma separated list of nicks to ignore, case insensitive'),
4242
'buffer_blacklist' : ("gitlama", 'comma separated list of buffers to ignore, case insensitive'),
4343
'notify' : ("off", 'highlight (notify) buffer if written to'),
@@ -96,9 +96,6 @@ def checker(data, buffer, date, tags, displayed, highlight, prefix, message):
9696
nick = tags[idx][5:]
9797
nick_colored = c(cg('nick_color')) + tags[idx][5:] + rst
9898

99-
100-
return w.WEECHAT_RC_OK
101-
10299
buffername = w.buffer_get_string(buffer, 'short_name')
103100

104101
if nick.lower() in [ x.strip().lower() for x in cg('nick_blacklist').split(',') ] or buffername.lower() in [ x.strip().lower() for x in cg('buffer_blacklist').split(',') ]:
@@ -118,10 +115,10 @@ def checker(data, buffer, date, tags, displayed, highlight, prefix, message):
118115

119116
w.prnt(himan_buffer, outp_left + nick_colored + outp_sep + buffername_colored + outp_right + sp + message)
120117

121-
if len(message) >= 10 and not (message.startswith("[") and message[9] == "]"): #this is likely a timestamp from ZNC, we don't notify for those
118+
if not (message.startswith("[") and len(message) >= 10 and message[9] == "]"): #this is likely a timestamp from ZNC, we don't notify for those
122119
os.system(f"notify-send -t \"{nick}@{buffername}\" \"{message}\"")
123120
if int(time.time()) - lastchime > 10:
124-
os.system(f"play ~/dotfiles/media/chime.wav &")
121+
os.system(f"mpv --no-video ~/dotfiles/media/chime.wav &")
125122
lastchime = int(time.time())
126123

127124
return w.WEECHAT_RC_OK

0 commit comments

Comments
 (0)