This repository has been archived on 2023-04-13. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
CloudBot/plugins/spellcheck.py
2012-02-28 10:41:53 +08:00

23 lines
574 B
Python

import re
from util import hook
import enchant
@hook.command("spellcheck")
def spell(inp):
".spell <word> -- Check spelling of <word>."
d = enchant.Dict("en_US")
if not (inp.split()[-1] == inp):
return "This command only supports one word at a time."
is_correct = d.check(inp)
suggestions = d.suggest(inp)
s_string = ', '.join(suggestions)
if is_correct:
return "That word appears to be valid! (suggestions: " + s_string + ")"
else:
return "That word appears to be invalid! (suggestions: " + s_string + ")"