Exemplo n.º 1
0
async def user_stats(args: List[str], player: 'Player', _):
    mode = GameModes(0)
    if len(args) < 1:
        nickname = player.name
    else:
        nickname = args[0]

    if len(args) > 1 and args[1].isdigit():
        mode = GameModes(int(args[1]))

    if mode > 3:
        return "GameMode is incorrect"

    token = Context.players.get_token(name=nickname.lower())
    if not token:
        return 'Player not online'

    mode_str = GameModes.resolve_to_str(mode)
    stats = token.stats[mode]

    acc = "{0:.2f}%".format(stats.accuracy)
    return (f"User: {nickname}\n"
            f"ID: {token.id}\n"
            "---------------------\n"
            f"Stats for {mode_str} #{stats.leaderboard_rank}\n"
            f"Ranked score: {new_utils.humanize(stats.ranked_score)}\n"
            f"Accuracy: {acc}\n"
            f"Play count: {new_utils.humanize(stats.total_plays)}\n"
            f"Total score: {new_utils.humanize(stats.total_score)}\n"
            f"PP count: {new_utils.humanize(stats.pp)}")
Exemplo n.º 2
0
    async def update_stats(self, selected_mode: GameModes = None) -> bool:
        for mode in GameModes if not selected_mode else [selected_mode]:
            res = await Context.mysql.fetch(
                'select total_score_{0} as total_score, ranked_score_{0} as ranked_score, '
                'pp_{0} as pp, playcount_{0} as total_plays, avg_accuracy_{0} as accuracy, playtime_{0} as playtime '
                'from users_stats where id = %s'.format(
                    GameModes.resolve_to_str(mode)), [self.id])

            if not res:
                logger.elog(
                    f"[Player/{self.name}] Can't parse stats for {GameModes.resolve_to_str(mode)}"
                )
                return False

            res['leaderboard_rank'] = 0

            self.stats[mode].update(**res)
        return True