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