spellcheck.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:GLaDOS2 作者: TheComet 项目源码 文件源码
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)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号