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

29 lines
731 B
Python
Raw Normal View History

2012-02-02 14:05:11 +01:00
import re
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("spellcheck")
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: %s" % locale
dict = enchant.Dict(locale)
2012-08-20 21:49:22 +02:00
is_correct = dict.check(inp)
suggestions = dict.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:
2012-04-19 13:18:12 +02:00
return '"%s" appears to be \x02valid\x02! ' \
2012-08-20 21:49:22 +02:00
'(suggestions: %s)' % (inp, s_string)
2012-02-02 14:05:11 +01:00
else:
2012-04-19 13:18:12 +02:00
return '"%s" appears to be \x02invalid\x02! ' \
2012-08-20 21:49:22 +02:00
'(suggestions: %s)' % (inp, s_string)