mirror of
https://github.com/hencaric/SCNewsBot.git
synced 2026-08-17 06:56:03 +01:00
fix editing description
This commit is contained in:
@@ -47,13 +47,24 @@ async def get_follow_up_message(
|
|||||||
|
|
||||||
def is_announcement(announcement: discord.Message, /) -> bool:
|
def is_announcement(announcement: discord.Message, /) -> bool:
|
||||||
return (
|
return (
|
||||||
announcement.author == announcement.guild.me
|
announcement
|
||||||
|
and announcement.author == announcement.guild.me
|
||||||
and len(announcement.embeds) == 1
|
and len(announcement.embeds) == 1
|
||||||
and not announcement.content
|
and not announcement.content
|
||||||
and not announcement.components
|
and not announcement.components
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def is_video_message(announcement: discord.Message, /) -> bool:
|
||||||
|
return (
|
||||||
|
announcement
|
||||||
|
and announcement.author == announcement.guild.me
|
||||||
|
and len(announcement.embeds) == 1
|
||||||
|
and not announcement.mentions
|
||||||
|
and announcement.content
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def reformat_description(description: str) -> str:
|
def reformat_description(description: str) -> str:
|
||||||
split_description = description.split("\n")
|
split_description = description.split("\n")
|
||||||
|
|
||||||
@@ -126,7 +137,7 @@ class AnnouncementCog(commands.Cog, name="Announcements"):
|
|||||||
video_message = await get_follow_up_message(message, limit=-1)
|
video_message = await get_follow_up_message(message, limit=-1)
|
||||||
ping_message = await get_follow_up_message(message, limit=1)
|
ping_message = await get_follow_up_message(message, limit=1)
|
||||||
|
|
||||||
if video_message:
|
if is_video_message(video_message):
|
||||||
await video_message.delete()
|
await video_message.delete()
|
||||||
if ping_message:
|
if ping_message:
|
||||||
await ping_message.delete()
|
await ping_message.delete()
|
||||||
@@ -277,20 +288,27 @@ class Announcement:
|
|||||||
if len(split_message) == 2:
|
if len(split_message) == 2:
|
||||||
ping_preview = split_message[1]
|
ping_preview = split_message[1]
|
||||||
|
|
||||||
url = None
|
url = ""
|
||||||
description = embed.description
|
description = embed.description
|
||||||
video_message = await get_follow_up_message(message, limit=-1)
|
video_message = await get_follow_up_message(message, limit=-1)
|
||||||
|
|
||||||
|
if not is_video_message(video_message):
|
||||||
|
video_message = None
|
||||||
|
|
||||||
if embed.description is not None:
|
if embed.description is not None:
|
||||||
if len(embed.description.split("\n\n")) > 0:
|
content = embed.description
|
||||||
url = embed.description.split("\n\n")[0]
|
|
||||||
description = "\n\n".join(description.split("\n\n")[1:])
|
if "\n\n" in embed.description:
|
||||||
|
url = embed.description.split("\n\n")[0] + "\n\n"
|
||||||
|
content = embed.description.split("\n\n")[1:]
|
||||||
|
|
||||||
|
description = url + "\n".join(content)
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
title=embed.title,
|
title=embed.title,
|
||||||
url=url,
|
url=url or None,
|
||||||
description=description,
|
description=description,
|
||||||
video_url=video_message.content,
|
video_url=video_message.content if video_message else None,
|
||||||
image_url=embed.image.url,
|
image_url=embed.image.url,
|
||||||
channel=message.channel,
|
channel=message.channel,
|
||||||
ping=ping,
|
ping=ping,
|
||||||
@@ -407,8 +425,11 @@ class AnnouncementBuilderView(discord.ui.View):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
await interaction.response.send_message(
|
await interaction.response.send_message(
|
||||||
"Cancelled posting/editing this announcement."
|
"Cancelled editing this announcement."
|
||||||
|
if self.announcement_builder.edit
|
||||||
|
else "Cancelled posting this announcement."
|
||||||
)
|
)
|
||||||
|
|
||||||
@discord.ui.button(custom_id="anonymous", label="Anonymous?", row=2)
|
@discord.ui.button(custom_id="anonymous", label="Anonymous?", row=2)
|
||||||
@@ -484,6 +505,8 @@ class AnnouncementBuilderView(discord.ui.View):
|
|||||||
video_message = await get_follow_up_message(
|
video_message = await get_follow_up_message(
|
||||||
self.announcement_builder.message, limit=-1
|
self.announcement_builder.message, limit=-1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if is_video_message(video_message):
|
||||||
await video_message.edit(
|
await video_message.edit(
|
||||||
content=self.announcement_builder.announcement.video_url
|
content=self.announcement_builder.announcement.video_url
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user