From 253ffaafdab72b887cadb91a23fd9225f677e66a Mon Sep 17 00:00:00 2001 From: Fletcher Boyd Date: Wed, 4 Sep 2013 23:48:56 +0800 Subject: [PATCH] Added multiword support. --- plugins/spellcheck.py | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/plugins/spellcheck.py b/plugins/spellcheck.py index 95b1699..2b116dc 100755 --- a/plugins/spellcheck.py +++ b/plugins/spellcheck.py @@ -7,21 +7,33 @@ locale = "en_US" @hook.command def spell(inp): """spell -- Check spelling of .""" - - if ' ' in inp: - return "This command only supports one word at a time." - + words = inp.split(" ") + if words[0] == "": + words = [] if not enchant.dict_exists(locale): return "Could not find dictionary: {}".format(locale) dictionary = enchant.Dict(locale) - is_correct = dictionary.check(inp) - suggestions = dictionary.suggest(inp) - s_string = ', '.join(suggestions[:10]) - if is_correct: - return '"{}" appears to be \x02valid\x02! ' \ - '(suggestions: {})'.format(inp, s_string) + if len(words) > 1: + out = [] + 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: - return '"{}" appears to be \x02invalid\x02! ' \ - '(suggestions: {})'.format(inp, s_string) + is_correct = dictionary.check(words[0]) + 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) +