Untitled

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

set_error_log_channel(1203433141205733376)

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

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

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 = int(id_field_value)
    delete_message(interaction.channel_id, 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é cloturés !"  

    else:
        voter = cont["voter_db"]
        media = cont["img_db"]

        if status != "vote":
            timer = int(server_var('contest_time')) + 345572
            vote_time = f"<t:{timer}:R>"
            content = f"❌ Les votes seront ouverts {vote_time} !"

        elif user.id in voter:
            content = "❌ Tu as déjà voter pour ce média ou essaye de voter pour toi-même !"

        else:
            content = "✅ Tu as bien voté pour ce média"

            voter.append(user.id)
            numb_votes = int(cont["vote_db"]) + 1
            await db.update_one(
                {"uid_db": target.id},
                {"$set": {"vote_db": numb_votes, "voter_db": voter}}
            )
            vote = "<a:Heart:1235313701800775850>  " * numb_votes + 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 = "❌ Ce Weekly Medias est terminé !"
    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 != int(target.id):
                member = get_member(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 = (
                "\n".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", emoji="🗑️")

            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