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.
This commit is contained in:
Valentin Lorentz 2022-01-11 20:13:39 +01:00
parent 40155ede22
commit dcca9f9637
2 changed files with 21 additions and 8 deletions

View File

@ -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'),

View File

@ -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: