Untitled

mail@pastecode.io avatar
unknown
python
a month ago
1.7 kB
1
Indexable
Never
#! rank

set_error_log_channel(1203433141205733376)

if custom_id == "rank":

    defer_response(interaction)

    db = SlashMongo("Weekly")
    data = await db.find({"wins_db": {"$gt": 0}}, sort=[("wins_db", -1)])

    desc2 = []
    emoji_positions = ["🥇", "🥈", "🥉"]
    current_wins = None
    current_group = {"wins": None, "members": []}

    def build_desc(part, index):
        global current_wins, current_group

        wins = int(part["wins_db"])

        uid_db = int(part["uid_db"])
        if member := get_member(uid_db):
            if current_wins is None or current_wins == wins:
                current_group["wins"] = wins
                current_group["members"].append(member.display_name)
                current_wins = wins
            else:
                if current_group["members"]:
                    emoji = emoji_positions[len(desc2)] if len(desc2) < len(emoji_positions) else ""
                    members_str = "\n- ".join(current_group["members"])
                    desc2.append(f"{emoji} `{current_group['wins']} victoires`\n - {members_str}\nâ €")

                current_group = {"wins": wins, "members": [member.display_name]}
                current_wins = wins

    loop(data, build_desc)

    if current_group["members"]:
        emoji = emoji_positions[len(desc2)] if len(desc2) < len(emoji_positions) else ""
        members_str = "\n- ".join(current_group["members"])
        desc2.append(f"{emoji} `{current_group['wins']} victoires`\n - {members_str}\nâ €")

    if not desc2:
        result = "Aucun membre trouvé."
    else:
        result = "\n".join(desc2)

    return respond_interaction(interaction, embed=load_embed("cly7a31b101mxqh01qx6dw7wb"))
Leave a Comment