activitylog.py 文件源码

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

项目:calebj-cogs 作者: calebj 项目源码 文件源码
def log(self, location, text, timestamp=None, force=False, subfolder=None, mode='a'):
        if not timestamp:
            timestamp = datetime.utcnow()
        if self.lock or not (force or self.should_log(location)):
            return

        path = PATH_LIST.copy()
        entry = [timestamp.strftime(TIMESTAMP_FORMAT)]

        if type(location) is discord.Server:
            path += [location.id, 'server.log']
        elif type(location) is discord.Channel:
            serverid = location.server.id
            entry.append('#' + location.name)
            path += [serverid, location.id + '.log']
        elif type(location) is discord.PrivateChannel:
            path += ['direct', location.id + '.log']
        else:
            return

        if subfolder:
            path.insert(-1, str(subfolder))

        text = text.replace('\n', '\\n')
        entry.append(text)

        fname = os.path.join(*path)
        handle = self.gethandle(fname, mode=mode)
        await handle.write(' '.join(entry) + '\n')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号