Skip to content
This repository has been archived by the owner on Nov 30, 2022. It is now read-only.

Delete discussion embed when entry is deleted #301

Merged
merged 6 commits into from
Jun 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 37 additions & 1 deletion pgbot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ def format_entries_message(msg: discord.Message, entry_type: str):
"""
Formats an entries message to be reposted in discussion channel
"""
title = f"New {entry_type.lower()} in #{common.ZERO_SPACE}{common.entry_channels[entry_type].name}"
if entry_type != "":
title = f"New {entry_type.lower()} in #{common.ZERO_SPACE}{common.entry_channels[entry_type].name}"
else:
title=""

attachments = ""
if msg.attachments:
Expand Down Expand Up @@ -175,6 +178,22 @@ async def message_delete(msg: discord.Message):
del common.cmd_logs[log]
return

if common.GENERIC:
return

if msg.channel in common.entry_channels.values():
history = common.entries_discussion_channel.history(
around=msg.created_at,
limit=5
)
message: discord.Message
async for message in history:
embed: discord.embeds.Embed = message.embeds[0]
link = embed.fields[1].value
if int(link.split("/")[6][:-1]) == msg.id:
await message.delete()
break


async def message_edit(old: discord.Message, new: discord.Message):
"""
Expand All @@ -186,6 +205,23 @@ async def message_edit(old: discord.Message, new: discord.Message):
await commands.handle(new, common.cmd_logs[new.id])
except discord.HTTPException:
pass
if new.channel in common.entry_channels.values():
history = common.entries_discussion_channel.history(
around=old.created_at,
limit=5
)
message: discord.Message
async for message in history:
message_embed: discord.embeds.Embed = message.embeds[0]
link = message_embed.fields[1].value
if int(link.split("/")[6][:-1]) == new.id:
title, fields = format_entries_message(new, "")
await embed_utils.edit_2(
message,
embed=message_embed,
fields=fields
)
break


async def handle_message(msg: discord.Message):
Expand Down