This repository has been archived on 2023-04-13. You can view files and clone it, but cannot push or open issues or pull requests.
CloudBot/plugins/spellcheck.py
Luke Rogers 7bdbb376b8 Pepping
2012-08-21 07:49:22 +12:00

29 lines
731 B
Python
Executable file

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