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

30 lines
753 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-02-28 03:03:43 +01:00
".spell <word> -- Check spelling of <word>."
2012-04-19 13:18:12 +02:00
word = inp
if ' ' in word:
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)
is_correct = dict.check(word)
suggestions = dict.suggest(word)
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! ' \
'(suggestions: %s)' % (word, 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! ' \
'(suggestions: %s)' % (word, s_string)