diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2019-01-20 09:49:03 +0100 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2019-01-26 12:51:07 +0100 |
commit | a9a2ffc6a9db25eba33378544f24ff4a7204fd5a (patch) | |
tree | 9a2a89a0cea4e2341868a9a2f613460ad376575f /wee_slack.py | |
parent | 1055742e196ea1beb39835a41efdf9415ea20e26 (diff) | |
download | wee-slack-a9a2ffc6a9db25eba33378544f24ff4a7204fd5a.tar.gz |
Simplify code for distracting channels
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/wee_slack.py b/wee_slack.py index b6f23bb..56f493d 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -3649,16 +3649,12 @@ def command_distracting(data, current_buffer, args): """ channel = EVENTROUTER.weechat_controller.buffers[current_buffer] fullname = channel.formatted_name(style="long_default") - if config.distracting_channels.count(fullname) == 0: - config.distracting_channels.append(fullname) + if fullname in config.distracting_channels: + config.distracting_channels.remove(fullname) else: - config.distracting_channels.pop(config.distracting_channels.index(fullname)) - save_distracting_channels() - return w.WEECHAT_RC_OK_EAT - - -def save_distracting_channels(): + config.distracting_channels.append(fullname) w.config_set_plugin('distracting_channels', ','.join(config.distracting_channels)) + return w.WEECHAT_RC_OK_EAT @slack_buffer_required @@ -3740,18 +3736,10 @@ def command_nodistractions(data, current_buffer, args): """ global hide_distractions hide_distractions = not hide_distractions - if config.distracting_channels != ['']: - for channel in config.distracting_channels: - dbg('hiding channel {}'.format(channel)) - # try: - for c in EVENTROUTER.weechat_controller.buffers.itervalues(): - if c == channel: - dbg('found channel {} to hide'.format(channel)) - w.buffer_set(c.channel_buffer, "hidden", str(int(hide_distractions))) - # except: - # dbg("Can't hide channel {} .. removing..".format(channel), main_buffer=True) -# config.distracting_channels.pop(config.distracting_channels.index(channel)) -# save_distracting_channels() + channels = [channel for channel in EVENTROUTER.weechat_controller.buffers.itervalues() + if channel in config.distracting_channels] + for channel in channels: + w.buffer_set(channel.channel_buffer, "hidden", str(int(hide_distractions))) return w.WEECHAT_RC_OK_EAT @@ -4248,7 +4236,7 @@ class PluginConfig(object): get_unfurl_auto_link_display = get_string def get_distracting_channels(self, key): - return [x.strip() for x in w.config_get_plugin(key).split(',')] + return [x.strip() for x in w.config_get_plugin(key).split(',') if x] def get_server_aliases(self, key): alias_list = w.config_get_plugin(key) |