stats.py 文件源码

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

项目:dogbot 作者: slice 项目源码 文件源码
def update_statistics(pg: asyncpg.connection.Connection, ctx: commands.Context):
    """
    Updates command statistics for a specific `discord.ext.commands.Context`.

    If no record was found for a command, it is created. Otherwise, the ``times_used`` and
    ``last_used`` fields are updated.
    """
    row = await get_statistics(pg, str(ctx.command))

    if row is None:
        # first time command is being used, insert it into the database
        insert = 'INSERT INTO command_statistics VALUES ($1, 1, $2)'
        await pg.execute(insert, str(ctx.command), datetime.datetime.utcnow())
        logger.info('First command usage for %s', ctx.command)
    else:
        # command was used before, increment time_used and update last_used
        update = ('UPDATE command_statistics SET times_used = times_used + 1, last_used = $2 '
                  'WHERE command_name = $1')
        await pg.execute(update, str(ctx.command), datetime.datetime.utcnow())
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号