From 08ca10d86f4fefca656634901e81bf215c6646a9 Mon Sep 17 00:00:00 2001 From: samsunghappytree123 Date: Sat, 4 Jun 2022 19:22:41 +0900 Subject: [PATCH] =?UTF-8?q?feat(cogs.meme):=20=EC=8B=A0=EA=B3=A0=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=A0=9C=EC=9E=91=20=EC=A4=91=20=EC=9E=84?= =?UTF-8?q?=EC=8B=9C=20=EC=97=85=EB=A1=9C=EB=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 인터렉션 및 코드가 스파게티일 수 있습니다. --- cogs/meme.py | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 104 insertions(+), 2 deletions(-) diff --git a/cogs/meme.py b/cogs/meme.py index e63588d..649973d 100644 --- a/cogs/meme.py +++ b/cogs/meme.py @@ -4,6 +4,7 @@ import asyncio, aiofiles import re import os +import json from discord.ext import commands, pages from discord.commands import slash_command, Option, permissions, SlashCommandGroup from utils.embed import * @@ -35,17 +36,118 @@ async def account_check(self): async def on_interaction(self, interaction: discord.Interaction): if interaction.is_component(): if interaction.data["custom_id"].startswith("report-"): + with open("utils/report_label.json", encoding="UTF8") as f: + data = json.load(f) + + options = [] + + for i in data.keys(): + options.append(discord.SelectOption(value=i, label=data[i]["label"], description=data[i]["description"])) + view = discord.ui.View() + view.add_item( + discord.ui.Select( + placeholder="신고 사유를 선택해주세요.", + min_values=1, + max_values=len(data.keys()), + options=options, + custom_id="reportlabel", + ) + ) try: - await interaction.response.send_message( + m = await interaction.response.send_message( f"안녕하세요, {interaction.user.mention}님.\n해당 밈(``ID : {interaction.data['custom_id'].replace('report-', '')}``)에 대한 신고 사유를 선택해주세요.", + view=view, ephemeral=True, ) except: - await interaction.followup.send( + m = await interaction.followup.send( f"안녕하세요, {interaction.user.mention}님.\n해당 밈(``ID : {interaction.data['custom_id'].replace('report-', '')}``)에 대한 신고 사유를 선택해주세요.", + view=view, ephemeral=True, ) + + + def check(inter): + return inter.user.id == interaction.user.id + #return inter.user.id == interaction.user.id and inter.response.id == m.id + + try: + interaction_check = await self.bot.wait_for( + "interaction", check=check, timeout=60.0 + ) + except asyncio.TimeoutError: + embed = discord.Embed( + title=f"<:jbllogo:929615468233363457> 시간 초과", + description="시간이 초과되었습니다.", + color=0x5865F2, + ) + try: + return await m.edit_original_message( + content=None, + embed=embed, + view=None, + ) + except: + return await m.edit( + content=None, + embed=embed, + view=None, + ) + + reason_list = [] + for value in (interaction_check.data["values"]): + reason_list.append(f"``{data[value]['label']}``") + reasons = ", ".join(reason_list) + + view = discord.ui.View() + view.add_item(discord.ui.Button( + label="신고 내용 작성하기", + emoji="📝", + style=discord.ButtonStyle.blurple, + custom_id=f"reportform-{interaction.user.id}", + )) + try: + await m.edit_original_message(content=f"안녕하세요, {interaction.user.mention}님.\n해당 밈(``ID : {interaction.data['custom_id'].replace('report-', '')}``)에 대한 신고 사유가 선택되었습니다.\n\n> 사유 : {reasons}\n\n**``신고 내용 작성하기`` 버튼을 눌러 내용을 작성해주세요.**", view=view) + except: + await m.edit(content=f"안녕하세요, {interaction.user.mention}님.\n해당 밈(``ID : {interaction.data['custom_id'].replace('report-', '')}``)에 대한 신고 사유가 선택되었습니다.\n\n> 사유 : {reasons}\n\n**``신고 내용 작성하기`` 버튼을 눌러 내용을 작성해주세요.**", view=view) + + try: + interaction_check = await self.bot.wait_for( + "interaction", check=check, timeout=600.0 + ) + except asyncio.TimeoutError: + embed = discord.Embed( + title=f"<:jbllogo:929615468233363457> 시간 초과", + description="시간이 초과되었습니다.", + color=0x5865F2, + ) + try: + return await m.edit_original_message( + content=None, + embed=embed, + view=None, + ) + except: + return await m.edit( + content=None, + embed=embed, + view=None, + ) + + if interaction.data["custom_id"].startswith("reportform-"): + modal = discord.ui.Modal(title="신고 내용 작성하기", custom_id="reportform") + modal.add_item( + discord.ui.InputText( + label="신고 사유", + placeholder="왜 이 짤을 신고하시게 되었나요? 자세하게 설명해주시면 처리 속도가 더 향상된답니다!", + style=discord.InputTextStyle.long, + max_length=1024, + custom_id="description", + required=True, + ) + ) + await interaction.response.send_modal(modal) if interaction.data["custom_id"].startswith("rerandom-"): if (