mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-22 02:19:24 +01:00
Autocomplete (+ Fediverse): configure Black.
This commit is contained in:
parent
7710edb5fe
commit
6f5d8c3011
@ -56,7 +56,9 @@ def _commonPrefix(L):
|
||||
def _getAutocompleteResponse(irc, msg, payload):
|
||||
"""Returns the value of the +draft/autocomplete-response tag for the given
|
||||
+draft/autocomplete-request payload."""
|
||||
tokens = callbacks.tokenize(payload, channel=msg.channel, network=irc.network)
|
||||
tokens = callbacks.tokenize(
|
||||
payload, channel=msg.channel, network=irc.network
|
||||
)
|
||||
normalized_payload = " ".join(tokens)
|
||||
|
||||
candidate_commands = _getCandidates(irc, normalized_payload)
|
||||
@ -81,12 +83,16 @@ def _getAutocompleteResponse(irc, msg, payload):
|
||||
candidate[len(common_prefix)] for candidate in tokenized_candidates
|
||||
}
|
||||
|
||||
commands = [" ".join(common_prefix + [word]) for word in words_after_prefix]
|
||||
commands = [
|
||||
" ".join(common_prefix + [word]) for word in words_after_prefix
|
||||
]
|
||||
|
||||
# strip what the user already typed
|
||||
assert all(command.startswith(normalized_payload) for command in commands)
|
||||
normalized_payload_length = len(normalized_payload)
|
||||
response_items = [command[normalized_payload_length:] for command in commands]
|
||||
response_items = [
|
||||
command[normalized_payload_length:] for command in commands
|
||||
]
|
||||
|
||||
return "\t".join(sorted(response_items))
|
||||
|
||||
@ -103,7 +109,9 @@ def _getCandidates(irc, normalized_payload):
|
||||
cb_commands += [plugin_name + " " + command for command in cb_commands]
|
||||
|
||||
candidates |= {
|
||||
command for command in cb_commands if command.startswith(normalized_payload)
|
||||
command
|
||||
for command in cb_commands
|
||||
if command.startswith(normalized_payload)
|
||||
}
|
||||
|
||||
return candidates
|
||||
|
@ -41,7 +41,10 @@ class AutocompleteTestCase(PluginTestCase):
|
||||
self.irc.feedMsg(
|
||||
ircmsgs.IrcMsg(
|
||||
prefix="foo!bar@baz",
|
||||
server_tags={"msgid": "1234", "+draft/autocomplete-request": request},
|
||||
server_tags={
|
||||
"msgid": "1234",
|
||||
"+draft/autocomplete-request": request,
|
||||
},
|
||||
command="TAGMSG",
|
||||
args=[self.nick],
|
||||
)
|
||||
@ -86,7 +89,9 @@ class AutocompleteTestCase(PluginTestCase):
|
||||
with conf.supybot.protocols.irc.experimentalExtensions.context(True):
|
||||
with conf.supybot.plugins.Autocomplete.enabled.context(True):
|
||||
self._assertAutocompleteResponse("misc t", "ell")
|
||||
self._assertAutocompleteResponse("misc c", "learmores\tompletenick")
|
||||
self._assertAutocompleteResponse(
|
||||
"misc c", "learmores\tompletenick"
|
||||
)
|
||||
|
||||
def testSinglePluginName(self):
|
||||
with conf.supybot.protocols.irc.experimentalExtensions.context(True):
|
||||
@ -119,7 +124,10 @@ class AutocompleteChannelTestCase(ChannelPluginTestCase):
|
||||
self.irc.feedMsg(
|
||||
ircmsgs.IrcMsg(
|
||||
prefix="foo!bar@baz",
|
||||
server_tags={"msgid": "1234", "+draft/autocomplete-request": request},
|
||||
server_tags={
|
||||
"msgid": "1234",
|
||||
"+draft/autocomplete-request": request,
|
||||
},
|
||||
command="TAGMSG",
|
||||
args=[self.channel],
|
||||
)
|
||||
|
4
pyproject.toml
Normal file
4
pyproject.toml
Normal file
@ -0,0 +1,4 @@
|
||||
[tool.black]
|
||||
line-length = 79
|
||||
|
||||
include = 'plugins/(Autocomplete|Fediverse)/.*\.pyi?$'
|
Loading…
Reference in New Issue
Block a user