This commit is contained in:
Luke Rogers 2012-08-21 07:49:22 +12:00
parent 2b4e5b3a98
commit 7bdbb376b8

View file

@ -8,23 +8,21 @@ locale = "en_US"
@hook.command("spellcheck") @hook.command("spellcheck")
def spell(inp): def spell(inp):
"spell <word> -- Check spelling of <word>." "spell <word> -- Check spelling of <word>."
word = inp
if ' ' in word: if ' ' in inp:
return "This command only supports one word at a time." return "This command only supports one word at a time."
if not enchant.dict_exists(locale): if not enchant.dict_exists(locale):
return "Could not find dictionary: %s" % locale return "Could not find dictionary: %s" % locale
dict = enchant.Dict(locale) dict = enchant.Dict(locale)
is_correct = dict.check(inp)
is_correct = dict.check(word) suggestions = dict.suggest(inp)
suggestions = dict.suggest(word)
s_string = ', '.join(suggestions[:10]) s_string = ', '.join(suggestions[:10])
if is_correct: if is_correct:
return '"%s" appears to be \x02valid\x02! ' \ return '"%s" appears to be \x02valid\x02! ' \
'(suggestions: %s)' % (word, s_string) '(suggestions: %s)' % (inp, s_string)
else: else:
return '"%s" appears to be \x02invalid\x02! ' \ return '"%s" appears to be \x02invalid\x02! ' \
'(suggestions: %s)' % (word, s_string) '(suggestions: %s)' % (inp, s_string)