Untitled

mail@pastecode.io avatar
unknown
python
a month ago
3.5 kB
1
Indexable
Never
#! like | informations | delete

set_error_log_channel(1236079568859824169)

db = SlashMongo("Weekly")
cont = await db.find_one({"msgid_db": str(interaction.message.id)})
target = get_member(int(cont["uid_db"])) if cont else None

status = server_var('contest_status')
weekly_theme = server_var('contest_theme')
member = "**révélé à la fin du weekly**"

if custom_id == "delete":

    defer_response(action="update")

    content = "✅ Media supprimé"
    the_embed = interaction.message.embeds[0]
    id_field_value = the_embed.fields[2].value.strip("`")
    msgid = str(id_field_value)

    delete_message(interaction.channel_id, int(msgid))

    await db.update_one(
        {"msgid_db": msgid},
        {"$unset": {
            "img_db": "",
            "vote_db": "",
            "voter_db": "",
            "msgid_db": "",
            "edit_count_db": "",
            "theme_db": ""
        }}
    )

    return respond_interaction(
        interaction, content=content, embed=None, component=None
    )

defer_response(interaction)

if custom_id == "like":
    if not cont:
        content = "❌ Les votes pour ce Weekly Medias ont déjà été clôturés !"
    elif status != "vote":
        content = "❌ Les votes ne sont pas encore ouverts !"
    elif str(user.id) in cont["voter_db"]:
        content = "❌ Tu as déjà voté pour ce média ou essaye de voter pour toi-même !"
    else:
        content = "✅ Tu as bien voté pour ce média"
        numb_votes = int(cont["vote_db"]) + 1

        await db.update_one(
            {"uid_db": str(target.id)},
            {
                "$inc": {"vote_db": 1},
                "$addToSet": {"voter_db": str(user.id)}
            }
        )

        vote = f"🩷 " * min(numb_votes, 8) + f"({numb_votes})"
        edit_message(
            interaction.channel_id, interaction.message.id,
            embed=load_embed("clvcg6roq048tpj01u9hv4nmu")
        )

    return respond_interaction(interaction, content=content)

elif custom_id == "informations":
    if not cont:
        content = "❌ Les infos pour ce Media sont effacées !"
    else:
        vote = cont["vote_db"]
        voter = cont["voter_db"]
        msgid = cont["msgid_db"]
        theme = cont["theme_db"]
        media = cont["img_db"]
        edit = cont["edit_count_db"]

        is_staff = has_role(user, 1152006537783562293)
        voter_list = []

        def make_desc(member_id, index):
            if member_id != str(target.id):
                member = get_member(int(member_id))
                if member:
                    voter_list.append(member.display_name if is_staff else member.mention)

        loop(voter, make_desc)

        if is_staff:
            vote = f"Aucun vote pour le moment." if vote == 0 else f"{vote}"
            voter = (
                ", ".join(f"[{voter}]" for voter in voter_list)
                if voter_list
                else "Aucun voteur pour le moment."
            )

            b = ComponentBuilder()
            b.add_button("Supprime ce média", "danger", custom_id="delete")

            return respond_interaction(
                interaction, embed=load_embed("clvgrrd5t05wnpj0109pokjbs"),
                component=b
            )
        else:
            content = (
                "### Liste des voteurs:\n" + "\n".join(f"- {voter}" for voter in voter_list)
                if voter_list
                else "Aucun voteur pour le moment, reviens plus tard!"
            )

    return respond_interaction(interaction, content=content)
Leave a Comment