Skip to content

Commit 1fbc360

Browse files
committed
Merge branch 'release-0.5'.
2 parents 669cf89 + 17367b8 commit 1fbc360

File tree

5 files changed

+233
-20
lines changed

5 files changed

+233
-20
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
__pycache__
33
*.py[co]
44

5-
# Unit tests and coverage reports
5+
# Code coverage settings and reports
66
/.coverage
77
/coverage

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ dev
66

77
* -
88

9+
0.5 (2016-05-27)
10+
----------------
11+
12+
* Added a new option: `ignore_buffers`. It is a comma-separated list of buffers
13+
from which no notifications should be shown.
14+
* Added a new option: `ignore_buffers_starting_with`. It is a comma-separated
15+
list of buffer prefixes from which no notifications should be shown.
16+
* Show default values of options in their descriptions (e.g. when viewed via
17+
`iset.pl`).
18+
919
0.4 (2016-04-23)
1020
----------------
1121

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ plugins.var.python.notify_send.XXX YYY` or by using the
4545
notifications from the same buffer. It is used to protect from floods/spam.
4646
Set it to `0` to disable this feature (i.e. all notifications will be shown).
4747
Default: `500` milliseconds.
48+
* `ignore_buffers`: A comma-separated list of buffers from which no
49+
notifications should be shown. You can use either short names (`#buffer`) or
50+
full names (`network.#buffer`). Default: `''`.
51+
* `ignore_buffers_starting_with`: A comma-separated list of buffer prefixes
52+
from which no notifications should be shown. Default: `''`.
4853
* `ignore_nicks`: A comma-separated list of nicks from which no notifications
4954
should be shown. Default: `''`.
5055
* `ignore_nicks_starting_with`: A comma-separated list of nick prefixes from

notify_send.py

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import time
3535

3636

37-
# Ensure that we are running under weechat.
37+
# Ensure that we are running under WeeChat.
3838
try:
3939
import weechat
4040
except ImportError:
@@ -49,7 +49,7 @@
4949
SCRIPT_AUTHOR = 's3rvac'
5050

5151
# Version of the script.
52-
SCRIPT_VERSION = '0.4'
52+
SCRIPT_VERSION = '0.5'
5353

5454
# License under which the script is distributed.
5555
SCRIPT_LICENSE = 'MIT'
@@ -87,6 +87,16 @@
8787
'A minimal delay between successive notifications from the same '
8888
'buffer (in milliseconds; set to 0 to show all notifications).'
8989
),
90+
'ignore_buffers': (
91+
'',
92+
'A comma-separated list of buffers from which no notifications should '
93+
'be shown.'
94+
),
95+
'ignore_buffers_starting_with': (
96+
'',
97+
'A comma-separated list of buffer prefixes from which no '
98+
'notifications should be shown.'
99+
),
90100
'ignore_nicks': (
91101
'',
92102
'A comma-separated list of nicks from which no notifications should '
@@ -145,6 +155,15 @@ def default_value_of(option):
145155
return OPTIONS[option][0]
146156

147157

158+
def add_default_value_to(description, default_value):
159+
"""Adds the given default value to the given option description."""
160+
# All descriptions end with a period, so do not add another period.
161+
return '{} Default: {}.'.format(
162+
description,
163+
default_value if default_value else '""'
164+
)
165+
166+
148167
def nick_from_prefix(prefix):
149168
"""Returns a nick from the given prefix.
150169
@@ -190,7 +209,10 @@ def notification_should_be_sent_disregarding_time(buffer, nick, is_highlight):
190209
if not notify_when_away():
191210
return False
192211

193-
if ignore_notifications_from(nick):
212+
if ignore_notifications_from_nick(nick):
213+
return False
214+
215+
if ignore_notifications_from_buffer(buffer):
194216
return False
195217

196218
if is_private_message(buffer):
@@ -292,7 +314,44 @@ def i_am_author_of_message(buffer, nick):
292314
return weechat.buffer_get_string(buffer, 'localvar_nick') == nick
293315

294316

295-
def ignore_notifications_from(nick):
317+
def ignore_notifications_from_buffer(buffer):
318+
"""Should notifications from the given buffer be ignored?"""
319+
# The 'buffer' parameter is actually the buffer's ID (e.g. '0x2719cf0'). We
320+
# have to check its name (e.g. 'freenode.#weechat') and short name (e.g.
321+
# '#weechat').
322+
buffer_names = [
323+
weechat.buffer_get_string(buffer, 'short_name'),
324+
weechat.buffer_get_string(buffer, 'name')
325+
]
326+
327+
for buffer_name in buffer_names:
328+
if buffer_name and buffer_name in ignored_buffers():
329+
return True
330+
331+
for buffer_name in buffer_names:
332+
for prefix in ignored_buffer_prefixes():
333+
if prefix and buffer_name and buffer_name.startswith(prefix):
334+
return True
335+
336+
return False
337+
338+
339+
def ignored_buffers():
340+
"""A generator of buffers from which notifications should be ignored."""
341+
for buffer in weechat.config_get_plugin('ignore_buffers').split(','):
342+
yield buffer.strip()
343+
344+
345+
def ignored_buffer_prefixes():
346+
"""A generator of buffer prefixes from which notifications should be
347+
ignored.
348+
"""
349+
prefixes = weechat.config_get_plugin('ignore_buffers_starting_with')
350+
for prefix in prefixes.split(','):
351+
yield prefix.strip()
352+
353+
354+
def ignore_notifications_from_nick(nick):
296355
"""Should notifications from the given nick be ignored?"""
297356
if nick in ignored_nicks():
298357
return True
@@ -423,6 +482,7 @@ def send_notification(notification):
423482

424483
# Initialization.
425484
for option, (default_value, description) in OPTIONS.items():
485+
description = add_default_value_to(description, default_value)
426486
weechat.config_set_desc_plugin(option, description)
427487
if not weechat.config_is_set_plugin(option):
428488
weechat.config_set_plugin(option, default_value)

0 commit comments

Comments
 (0)