Config: Add command '@config network'.

This commit is contained in:
Valentin Lorentz 2019-08-25 10:25:14 +02:00
parent 2f4644f7b3
commit c07086d7dc
2 changed files with 43 additions and 0 deletions

View File

@ -291,6 +291,30 @@ class Config(callbacks.Plugin):
'channels', 'settableConfigVar',
additional('text')])
def network(self, irc, msg, args, network, group, value):
"""[<network>] <name> [<value>]
If <value> is given, sets the network configuration variable for <name>
to <value> for <network>.
Otherwise, returns the current network configuration value of <name>.
<network> defaults to the current network."""
if not group._networkValue:
irc.error(_('That configuration variable is not a network-specific '
'configuration variable.'))
return
if value is not None:
self._setValue(irc, msg, group.get(':' + network.network), value)
irc.replySuccess()
else:
values = []
private = None
(value, private) = \
self._getValue(irc, msg, group, network)
irc.reply(value, private=private)
network = wrap(network, ['networkIrc', 'settableConfigVar',
additional('text')])
@internationalizeDocstring
def config(self, irc, msg, args, group, value):
"""<name> [<value>]

View File

@ -181,6 +181,25 @@ class ConfigTestCase(ChannelPluginTestCase):
self.assertResponse('config channel #testchan1 reply.whenAddressedBy.strings', '.')
self.assertResponse('config channel #testchan2 reply.whenAddressedBy.strings', '.')
def testNetwork(self):
getTestIrc('testnet1')
getTestIrc('testnet2')
self.assertResponse('config reply.whenAddressedBy.strings ^',
'The operation succeeded.')
self.assertResponse('config network reply.whenAddressedBy.strings @',
'The operation succeeded.')
self.assertResponse('config network reply.whenAddressedBy.strings', '@')
self.assertNotError('config network reply.whenAddressedBy.strings $')
self.assertResponse('config network testnet1 reply.whenAddressedBy.strings', '^')
self.assertResponse('config network testnet2 reply.whenAddressedBy.strings', '^')
self.assertResponse('config network reply.whenAddressedBy.strings', '$')
self.assertResponse('config network testnet1 reply.whenAddressedBy.strings', '^')
self.assertResponse('config network testnet2 reply.whenAddressedBy.strings', '^')
self.assertNotError('config network testnet1 reply.whenAddressedBy.strings =')
self.assertResponse('config network testnet1 reply.whenAddressedBy.strings', '=')
self.assertResponse('config network testnet2 reply.whenAddressedBy.strings', '^')
def testChannelNetwork(self):
irc = self.irc
irc1 = getTestIrc('testnet1')