tools.py 文件源码

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

项目:Harmonbot 作者: Harmon758 项目源码 文件源码
def tag(self, ctx, tag : str = ""):
        '''Tags/notes that you can trigger later'''
        if not tag:
            await self.bot.embed_reply("Add a tag with `{0}tag add [tag] [content]`\nUse `{0}tag [tag]` to trigger the tag you added\n`{0}tag edit [tag] [content]` to edit it and `{0}tag delete [tag]` to delete it".format(ctx.prefix))
            return
        if tag in self.tags_data.get(ctx.message.author.id, {}).get("tags", []):
            await self.bot.reply(self.tags_data[ctx.message.author.id]["tags"][tag])
        elif tag in self.tags_data["global"]:
            await self.bot.reply(self.tags_data["global"][tag]["response"])
            self.tags_data["global"][tag]["usage_counter"] += 1
            with open("data/tags.json", 'w') as tags_file:
                json.dump(self.tags_data, tags_file, indent = 4)
        else:
            close_matches = difflib.get_close_matches(tag, list(self.tags_data.get(ctx.message.author.id, {}).get("tags", {}).keys()) + list(self.tags_data["global"].keys()))
            close_matches = "\nDid you mean:\n{}".format('\n'.join(close_matches)) if close_matches else ""
            await self.bot.embed_reply("Tag not found{}".format(close_matches))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号