|
34 | 34 | import time |
35 | 35 |
|
36 | 36 |
|
37 | | -# Ensure that we are running under weechat. |
| 37 | +# Ensure that we are running under WeeChat. |
38 | 38 | try: |
39 | 39 | import weechat |
40 | 40 | except ImportError: |
|
49 | 49 | SCRIPT_AUTHOR = 's3rvac' |
50 | 50 |
|
51 | 51 | # Version of the script. |
52 | | -SCRIPT_VERSION = '0.4' |
| 52 | +SCRIPT_VERSION = '0.5' |
53 | 53 |
|
54 | 54 | # License under which the script is distributed. |
55 | 55 | SCRIPT_LICENSE = 'MIT' |
|
87 | 87 | 'A minimal delay between successive notifications from the same ' |
88 | 88 | 'buffer (in milliseconds; set to 0 to show all notifications).' |
89 | 89 | ), |
| 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 | + ), |
90 | 100 | 'ignore_nicks': ( |
91 | 101 | '', |
92 | 102 | 'A comma-separated list of nicks from which no notifications should ' |
@@ -145,6 +155,15 @@ def default_value_of(option): |
145 | 155 | return OPTIONS[option][0] |
146 | 156 |
|
147 | 157 |
|
| 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 | + |
148 | 167 | def nick_from_prefix(prefix): |
149 | 168 | """Returns a nick from the given prefix. |
150 | 169 |
|
@@ -190,7 +209,10 @@ def notification_should_be_sent_disregarding_time(buffer, nick, is_highlight): |
190 | 209 | if not notify_when_away(): |
191 | 210 | return False |
192 | 211 |
|
193 | | - if ignore_notifications_from(nick): |
| 212 | + if ignore_notifications_from_nick(nick): |
| 213 | + return False |
| 214 | + |
| 215 | + if ignore_notifications_from_buffer(buffer): |
194 | 216 | return False |
195 | 217 |
|
196 | 218 | if is_private_message(buffer): |
@@ -292,7 +314,44 @@ def i_am_author_of_message(buffer, nick): |
292 | 314 | return weechat.buffer_get_string(buffer, 'localvar_nick') == nick |
293 | 315 |
|
294 | 316 |
|
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): |
296 | 355 | """Should notifications from the given nick be ignored?""" |
297 | 356 | if nick in ignored_nicks(): |
298 | 357 | return True |
@@ -423,6 +482,7 @@ def send_notification(notification): |
423 | 482 |
|
424 | 483 | # Initialization. |
425 | 484 | for option, (default_value, description) in OPTIONS.items(): |
| 485 | + description = add_default_value_to(description, default_value) |
426 | 486 | weechat.config_set_desc_plugin(option, description) |
427 | 487 | if not weechat.config_is_set_plugin(option): |
428 | 488 | weechat.config_set_plugin(option, default_value) |
|
0 commit comments