Improved old spell check plugin

This commit is contained in:
Luke Rogers 2012-04-19 23:18:12 +12:00
parent 64981d429b
commit 4a0d424f9a

View file

@ -1,22 +1,30 @@
import re import re
from util import hook
import enchant import enchant
from util import hook
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>."
d = enchant.Dict("en_US") word = inp
if not (inp.split()[-1] == inp): if ' ' in word:
return "This command only supports one word at a time." return "This command only supports one word at a time."
is_correct = d.check(inp) if not enchant.dict_exists(locale):
suggestions = d.suggest(inp) return "Could not find dictionary: %s" % locale
s_string = ', '.join(suggestions)
dict = enchant.Dict(locale)
is_correct = dict.check(word)
suggestions = dict.suggest(word)
s_string = ', '.join(suggestions[:10])
if is_correct: if is_correct:
return "That word appears to be valid! (suggestions: " + s_string + ")" return '"%s" appears to be \x02valid\x02! ' \
'(suggestions: %s)' % (word, s_string)
else: else:
return "That word appears to be invalid! (suggestions: " + s_string + ")" return '"%s" appears to be \x02invalid\x02! ' \
'(suggestions: %s)' % (word, s_string)