Untitled

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

set_error_log_channel(1203433141205733376)

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é ici à 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 !"

    else:
        voter = cont["voter_db"]

        if status != "vote":
            content = "❌ Les votes ne sont pas encore ouverts !"

        else:
            if str(user.id) in voter:
                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"
                voter.append(str(user.id))
                numb_votes = int(cont["vote_db"]) + 1
                await db.update_one(
                    {"uid_db": str(target.id)},
                    {"$set": {"vote_db": numb_votes, "voter_db": voter}}
                )
                vote = f"🩷 " * min(numb_votes, 8) + f"({numb_votes})"

                edit_message(
                    interaction.channel_id, interaction.message.id,
                    embed=load_embed("clo0iwuz202v7p001n23cw9vp")
                )

    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, 1015242521695223958)
        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("clvh31ajh0623pj01fc8vukns"),
                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