utility.py 文件源码

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

项目:Lapzbot_Beta 作者: lap00zza 项目源码 文件源码
def info(ctx, message):
    """
    Displays Lapzbot information

    :param ctx:
    :param message:
    :return:
    """
    # TODO: this command needs to be fixed later
    servs = len(ctx.servers)
    ch = list(ctx.get_all_channels())
    channels = len(ch)
    mem = list(ctx.get_all_members())
    members = len(mem)

    current = datetime.datetime.now()
    diff = current - ctx.startup_timestamp
    days = diff.days
    seconds = diff.seconds
    m, s = divmod(seconds, 60)
    h, m = divmod(m, 60)
    # total_c = ctx.usage_track_admin['admin'] + ctx.usage_track['user']
    # total_m = ctx.usage_track_admin['total_msg']

    # r_min = (days * 24 * 60) + (h * 60) + m
    # msg_rate = float(total_c / r_min)
    # total_msg_rate = float(total_m / r_min)
    try:
        proc = psutil.Process(pid=os.getpid())
        rss = float(proc.memory_info().rss) / 1000000
        rss_per = float(proc.memory_percent())
        cpu_per = float(proc.cpu_percent(interval=0.2))
        sys_str = "RAM: {0:.2f} MB | CPU Usage: {1:.2f}% (*calculated for `2 ms` interval*)" \
            .format(rss, rss_per, cpu_per)
    except (psutil.NoSuchProcess, psutil.ZombieProcess, psutil.AccessDenied):
        sys_str = ""

    # ret_str = "`Connected to '{0}' Servers with '{1}' Channels and '{2}' Members`" \
    #           "\nCurrent uptime is {3} Days, {4} Hours, {5} Minutes, {6} Seconds" \
    #           "\n**{7}** commands were __used__ till now (**~{8:.2f}** per min)" \
    #           "\n**{9}** messages were __sent__ till now (**~{10:.2f}** per min)" \
    #           "\n**{11}** messages were __seen__ till now (**~{12:.2f}** per min)" \
    #           "\n{13}" \
    #     .format(str(servs), str(channels), str(members), str(days), str(h),
    #             str(m), str(s), str(total_c), msg_rate, ctx.lapzbot_sent_message,
    #             float(ctx.lapzbot_sent_message / r_min), str(total_m), total_msg_rate, sys_str)

    ret_str = "`Connected to '{0}' Servers with '{1}' Channels and '{2}' Members`" \
              "\nCurrent uptime is {3} Days, {4} Hours, {5} Minutes, {6} Seconds" \
              "\n{7}\n**SHARD: {8} / 2**" \
        .format(str(servs), str(channels), str(members), str(days), str(h),
                str(m), str(s), sys_str, ctx.current_shard)

    await ctx.send_message(message.channel, ret_str)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号