From dcca9f9637ed761997b7a0419a036c84fb20262c Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 11 Jan 2022 20:13:39 +0100 Subject: [PATCH] RSS: Make feed announces actually network-specific .getSpecific() always returned the channel-specific but non-network-specific var, unless the channel-specific and network-specific one was manually set. --- plugins/RSS/plugin.py | 5 +++-- src/registry.py | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index 76b7e3da2..ff8b15e4b 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -575,7 +575,8 @@ class RSS(callbacks.Plugin): S = announce.getSpecific(channel=channel, network=irc.network)() for name in feeds: S.add(name) - announce.getSpecific(channel=channel, network=irc.network).setValue(S) + announce.getSpecific(channel=channel, network=irc.network, + fallback_to_channel=False).setValue(S) irc.replySuccess() for name in feeds: feed = plugin.get_feed(name) @@ -606,7 +607,7 @@ class RSS(callbacks.Plugin): remove_from_var(announce.get(channel)) remove_from_var(announce.getSpecific( - channel=channel, network=irc.network)) + channel=channel, network=irc.network, fallback_to_channel=False)) irc.replySuccess() remove = wrap(remove, [('checkChannelCapability', 'op'), diff --git a/src/registry.py b/src/registry.py index a0d737e0b..792d73c62 100644 --- a/src/registry.py +++ b/src/registry.py @@ -381,13 +381,21 @@ class Value(Group): e.value = self raise e - def getSpecific(self, network=None, channel=None, check=True): + def getSpecific(self, network=None, channel=None, check=True, + fallback_to_channel=True): """Gets the network-specific and/or channel-specific value of this Value. - If `check=True` (the default), this will raise an error if `network` - (resp. `channel`) is provided but this Value is not network-specific - (resp. channel-specific). If `check=False`, then `network` and/or - `channel` may be silently ignored. + If ``check=True`` (the default), this will raise an error if ``network`` + (resp. ``channel``) is provided but this Value is not network-specific + (resp. channel-specific). If ``check=False``, then ``network`` and/or + ``channel`` may be silently ignored. + + If ``fallback_to_channel=True`` (the default) and the network-specific + + channel-specific value is not set, but the channel-specific value is + set, it will return the latter. + This is useful to upgrade from existing bot configuration, that did not + support network-specific values; but it may be undesirable when setting + new values. """ if network and not self._networkValue: if check: @@ -452,6 +460,7 @@ class Value(Group): # 3. it's inherited from the chan specific value (which is not a # actually a parent in the registry tree, but we need this to # load configuration from old bots). + # 4. it was never set at all # # The choice between 2 and 3 is done by checking which of the # net-specific and chan-specific values was set explicitly by @@ -464,9 +473,12 @@ class Value(Group): if network_value._wasSet or network_channel_value._wasSet: # cases 1 and 2 return network_channel_value - else: + elif channel_value._wasSet and fallback_to_channel: # case 3 return channel_value + else: + # case 4 + return network_channel_value elif network: return self.get(':' + network) elif channel: