data.py 文件源码

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

项目:InfoBot 作者: gdude2002 项目源码 文件源码
def add_server(self, server_id) -> bool:
        if os.path.exists("data/{}".format(server_id)):
            return False

        os.mkdir("data/{}".format(server_id))

        with open("data/{}/config.yml".format(server_id), "w") as config_fh:
            yaml.safe_dump(DEFAULT_CONFIG, config_fh)

        with open("data/{}/sections.yml".format(server_id), "w") as sections_fh:
            yaml.safe_dump(DEFAULT_SECTIONS, sections_fh)

        with open("data/{}/notes.yml".format(server_id), "w") as notes_fh:
            yaml.safe_dump(DEFAULT_NOTES, notes_fh)

        self.data[server_id] = {
            "config": DEFAULT_CONFIG.copy(),
            "sections": self.load_sections(DEFAULT_SECTIONS)
        }

        self.notes[server_id] = DEFAULT_NOTES

        log.info("Added server: {}".format(server_id))

        return True

    # Convenience functions
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号