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

28 lines
739 B
Python
Raw Normal View History

2012-02-02 14:05:11 +01:00
import enchant
2012-04-19 13:18:12 +02:00
from util import hook
locale = "en_US"
2012-02-02 14:05:11 +01:00
@hook.command
2012-02-02 14:05:11 +01:00
def spell(inp):
2012-05-16 05:07:27 +02:00
"spell <word> -- Check spelling of <word>."
2012-08-20 21:49:22 +02:00
if ' ' in inp:
2012-02-02 14:05:11 +01:00
return "This command only supports one word at a time."
2012-04-19 13:18:12 +02:00
if not enchant.dict_exists(locale):
return "Could not find dictionary: {}".format(locale)
2012-04-19 13:18:12 +02:00
dictionary = enchant.Dict(locale)
is_correct = dictionary.check(inp)
suggestions = dictionary.suggest(inp)
2012-04-19 13:18:12 +02:00
s_string = ', '.join(suggestions[:10])
2012-02-02 14:05:11 +01:00
if is_correct:
return '"{}" appears to be \x02valid\x02! ' \
'(suggestions: {})'.format(inp, s_string)
2012-02-02 14:05:11 +01:00
else:
return '"{}" appears to be \x02invalid\x02! ' \
'(suggestions: {})'.format(inp, s_string)