def spellcheck(self, message, word):
"""
Says whether the given word is spelled correctly, and gives suggestions if
it's not.
"""
if word == '':
await self.provide_help('spell', message)
return
word = word.split(' ', 1)[0]
dictionary = enchant.Dict("en_US")
dictionary_uk = enchant.Dict("en_GB")
# I don't want to make anyone angry, so I check both American and British English.
if dictionary_uk.check(word):
if dictionary.check(word):
await self.client.send_message(message.channel, word + " is spelled correctly")
else:
await self.client.send_message(message.channel, word + " is spelled correctly (British)")
elif dictionary.check(word):
await self.client.send_message(message.channel, word + " is spelled correctly (American)")
else:
msg = word + " is not spelled correctly. Maybe you want one of these spellings:"
sugWords = []
for suggested_word in dictionary.suggest(word):
sugWords.append(suggested_word)
for suggested_word in dictionary_uk.suggest(word):
sugWords.append(suggested_word)
for suggested_word in sorted(set(sugWords)): # removes duplicates
msg = msg + " '" + suggested_word + "',"
await self.client.send_message(message.channel, msg)
评论列表
文章目录