added _interaction_finish_suggestion method
This commit is contained in:
parent
101e0ecb34
commit
e0e40ca99a
1 changed files with 86 additions and 0 deletions
|
@ -511,3 +511,89 @@ class Suggestions(commands.Cog):
|
||||||
True
|
True
|
||||||
)
|
)
|
||||||
await ctx.tick()
|
await ctx.tick()
|
||||||
|
|
||||||
|
async def _interaction_finish_suggestion(self, interaction: discord.Interaction, message: discord.Message, approve, reason = None):
|
||||||
|
embed = message.embeds
|
||||||
|
title = embed[0].title
|
||||||
|
if not title.startswith("Suggestion #"):
|
||||||
|
await interaction.response.send_message(content="This message is not a suggestion!", ephemeral=True)
|
||||||
|
return
|
||||||
|
numbers = re.findall(r'\d+', title)
|
||||||
|
suggestion_id = ''.join(numbers)
|
||||||
|
author = interaction.user
|
||||||
|
server = interaction.guild.id
|
||||||
|
old_channel = interaction.guild.get_channel(
|
||||||
|
await self.config.guild(interaction.guild).suggest_id()
|
||||||
|
)
|
||||||
|
if approve:
|
||||||
|
channel = interaction.guild.get_channel(
|
||||||
|
await self.config.guild(interaction.guild).approve_id()
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
channel = interaction.guild.get_channel(
|
||||||
|
await self.config.guild(interaction.guild).denied_id()
|
||||||
|
)
|
||||||
|
msg_id = await self.config.custom("SUGGESTION", server, suggestion_id).msg_id()
|
||||||
|
if (
|
||||||
|
msg_id != 0
|
||||||
|
and await self.config.custom("SUGGESTION", server, suggestion_id).finished()
|
||||||
|
):
|
||||||
|
return await interaction.response.send_message("This suggestion has been finished already.")
|
||||||
|
try:
|
||||||
|
old_msg = await old_channel.fetch_message(msg_id)
|
||||||
|
except discord.NotFound:
|
||||||
|
return await interaction.response.send_message("Uh oh, message with this ID doesn't exist.")
|
||||||
|
if not old_msg:
|
||||||
|
return await interaction.response.send_message("Uh oh, message with this ID doesn't exist.")
|
||||||
|
embed = old_msg.embeds[0]
|
||||||
|
content = old_msg.content
|
||||||
|
|
||||||
|
approved = "Approved" if approve else "Denied"
|
||||||
|
|
||||||
|
embed.title = f"Suggestion {approved} (#{suggestion_id})"
|
||||||
|
footer = [f"{approved} by {self.check_discrim(author)} • ({author.id})",
|
||||||
|
author.display_avatar.replace(format="png", size=512)]
|
||||||
|
embed.set_footer(
|
||||||
|
text=footer[0],
|
||||||
|
icon_url=footer[1]
|
||||||
|
)
|
||||||
|
embed.add_field(
|
||||||
|
name="Results", value=await self._get_results(await commands.Context.from_interaction(interaction), old_msg), inline=False
|
||||||
|
)
|
||||||
|
if reason:
|
||||||
|
embed.add_field(name="Reason", value=reason, inline=False)
|
||||||
|
await self.config.custom("SUGGESTION", server, suggestion_id).reason.set(
|
||||||
|
True
|
||||||
|
)
|
||||||
|
await self.config.custom("SUGGESTION", server, suggestion_id).rtext.set(
|
||||||
|
reason
|
||||||
|
)
|
||||||
|
|
||||||
|
if channel:
|
||||||
|
if not await self.config.guild(interaction.guild).same():
|
||||||
|
if await self.config.guild(interaction.guild).delete_suggestion():
|
||||||
|
await old_msg.delete()
|
||||||
|
nmsg = await channel.send(content=content, embed=embed)
|
||||||
|
await self.config.custom(
|
||||||
|
"SUGGESTION", server, suggestion_id
|
||||||
|
).msg_id.set(nmsg.id)
|
||||||
|
else:
|
||||||
|
await old_msg.edit(content=content, embed=embed)
|
||||||
|
else:
|
||||||
|
if not await self.config.guild(interaction.guild).same():
|
||||||
|
if await self.config.guild(interaction.guild).delete_suggestion():
|
||||||
|
await old_msg.delete()
|
||||||
|
await self.config.custom(
|
||||||
|
"SUGGESTION", server, suggestion_id
|
||||||
|
).msg_id.set(1)
|
||||||
|
else:
|
||||||
|
await old_msg.edit(content=content, embed=embed)
|
||||||
|
await self.config.custom("SUGGESTION", server, suggestion_id).finished.set(True)
|
||||||
|
if approve:
|
||||||
|
await self.config.custom("SUGGESTION", server, suggestion_id).approved.set(
|
||||||
|
True
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
await self.config.custom("SUGGESTION", server, suggestion_id).denied.set(
|
||||||
|
True
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue