Added multiword support.
This commit is contained in:
parent
9d6aef731e
commit
253ffaafda
1 changed files with 24 additions and 12 deletions
|
@ -7,21 +7,33 @@ locale = "en_US"
|
||||||
@hook.command
|
@hook.command
|
||||||
def spell(inp):
|
def spell(inp):
|
||||||
"""spell <word> -- Check spelling of <word>."""
|
"""spell <word> -- Check spelling of <word>."""
|
||||||
|
words = inp.split(" ")
|
||||||
if ' ' in inp:
|
if words[0] == "":
|
||||||
return "This command only supports one word at a time."
|
words = []
|
||||||
|
|
||||||
if not enchant.dict_exists(locale):
|
if not enchant.dict_exists(locale):
|
||||||
return "Could not find dictionary: {}".format(locale)
|
return "Could not find dictionary: {}".format(locale)
|
||||||
|
|
||||||
dictionary = enchant.Dict(locale)
|
dictionary = enchant.Dict(locale)
|
||||||
is_correct = dictionary.check(inp)
|
|
||||||
suggestions = dictionary.suggest(inp)
|
|
||||||
s_string = ', '.join(suggestions[:10])
|
|
||||||
|
|
||||||
if is_correct:
|
if len(words) > 1:
|
||||||
return '"{}" appears to be \x02valid\x02! ' \
|
out = []
|
||||||
'(suggestions: {})'.format(inp, s_string)
|
for x in words:
|
||||||
|
is_correct = dictionary.check(x)
|
||||||
|
suggestions = dictionary.suggest(x)
|
||||||
|
s_string = '/'.join(suggestions[:2])
|
||||||
|
if is_correct:
|
||||||
|
out.append(x)
|
||||||
|
else:
|
||||||
|
out.append('\x02'+s_string+'\x02')
|
||||||
|
return " ".join(out)
|
||||||
else:
|
else:
|
||||||
return '"{}" appears to be \x02invalid\x02! ' \
|
is_correct = dictionary.check(words[0])
|
||||||
'(suggestions: {})'.format(inp, s_string)
|
suggestions = dictionary.suggest(words[0])
|
||||||
|
s_string = ', '.join(suggestions[:10])
|
||||||
|
if is_correct:
|
||||||
|
return '"{}" appears to be \x02valid\x02! ' \
|
||||||
|
'(suggestions: {})'.format(inp, s_string)
|
||||||
|
else:
|
||||||
|
return '"{}" appears to be \x02invalid\x02! ' \
|
||||||
|
'(suggestions: {})'.format(inp, s_string)
|
||||||
|
|
||||||
|
|
Reference in a new issue