Fix minor issue from merge

This commit is contained in:
Zeva Rose 2023-09-13 21:07:43 -06:00
parent 6c73e0df48
commit bcba51ed97

View file

@ -137,68 +137,65 @@ class PinboardCog(Extension):
message: str, message: str,
channel: GuildText = None, channel: GuildText = None,
) -> None: ) -> None:
try: if not channel:
if not channel: channel = ctx.channel
channel = ctx.channel pinboards = await Pinboard.find(Pinboard.guild == ctx.guild.id).to_list()
pinboards = await Pinboard.find(Pinboard.guild == ctx.guild.id).to_list() if not pinboards:
if not pinboards: await ctx.send("No pinboards exist.", ephemeral=True)
await ctx.send("No pinboards exist.", ephemeral=True) return
await ctx.defer()
if not isinstance(message, Message):
if message.startswith("https://"):
message = message.split("/")[-1]
message = await channel.fetch_message(int(message))
if not message:
await ctx.send("Message not found", ephemeral=True)
return return
await ctx.defer() channel_list = []
to_delete: list[Pinboard] = []
if not isinstance(message, Message): channel_to_pinboard = {}
if message.startswith("https://"):
message = message.split("/")[-1]
message = await channel.fetch_message(int(message))
if not message: for pinboard in pinboards:
await ctx.send("Message not found", ephemeral=True) c = await ctx.guild.fetch_channel(pinboard.channel)
return if c and isinstance(c, GuildText):
channel_list.append(c)
channel_to_pinboard[c.id] = pinboard
else:
self.logger.warning(
f"Pinboard {pinboard.channel} no longer valid in {ctx.guild.name}"
)
to_delete.append(pinboard)
channel_list = [] for pinboard in to_delete:
to_delete: list[Pinboard] = [] try:
await pinboard.delete()
except Exception:
self.logger.debug("Ignoring deletion error")
channel_to_pinboard = {} select_channels = []
for idx, x in enumerate(channel_list):
if x:
select_channels.append(StringSelectOption(label=x.name, value=str(idx)))
for pinboard in pinboards: select_channels = [
c = await ctx.guild.fetch_channel(pinboard.channel) StringSelectOption(label=x.name, value=str(idx))
if c and isinstance(c, GuildText): for idx, x in enumerate(channel_list)
channel_list.append(c) ]
channel_to_pinboard[c.id] = pinboard
else:
self.logger.warning(
f"Pinboard {pinboard.channel} no longer valid in {ctx.guild.name}"
)
to_delete.append(pinboard)
for pinboard in to_delete: select = StringSelectMenu(
try: *select_channels,
await pinboard.delete() min_values=1,
except Exception: max_values=1,
self.logger.debug("Ignoring deletion error") )
select_channels = [] components = [ActionRow(select)]
for idx, x in enumerate(channel_list):
if x:
select_channels.append(
StringSelectOption(label=x.name, value=str(idx))
)
select_channels = [ msg = await ctx.send(content="Choose a pinboard", components=components)
StringSelectOption(label=x.name, value=str(idx))
for idx, x in enumerate(channel_list)
]
select = StringSelectMenu(
*select_channels,
min_values=1,
max_values=1,
)
components = [ActionRow(select)]
msg = await ctx.send(content="Choose a pinboard", components=components)
com_ctx = await self.bot.wait_for_component( com_ctx = await self.bot.wait_for_component(
messages=msg, messages=msg,
@ -208,68 +205,68 @@ class PinboardCog(Extension):
starboard = channel_list[int(com_ctx.ctx.values[0])] starboard = channel_list[int(com_ctx.ctx.values[0])]
exists = await Pin.find_one( exists = await Pin.find_one(
Pin.message == int(message.id), Pin.message == int(message.id),
Pin.channel == int(channel.id), Pin.channel == int(channel.id),
Pin.guild == int(ctx.guild.id), Pin.guild == int(ctx.guild.id),
Pin.pinboard == int(pinboard.id), Pin.pinboard == int(pinboard.id),
)
if exists:
await ctx.send(
f"Message already sent to Pinboard {pinboard.mention}",
ephemeral=True,
) )
return
if exists: count = await Pin.find(
await ctx.send( Pin.guild == ctx.guild.id, Pin.pinboard == pinboard.id
f"Message already sent to Pinboard {pinboard.mention}", ).count()
ephemeral=True, content = message.content
)
return
count = await Pin.find( attachments = message.attachments
Pin.guild == ctx.guild.id, Pin.pinboard == pinboard.id image_urls = []
).count() if attachments:
content = message.content for attachment in attachments:
if attachment.content_type in supported_images:
image_urls.append(attachment.url)
if not content and len(image_urls) > 0:
content = "\u200b"
attachments = message.attachments embed = build_embed(
image_urls = [] title=f"[#{count}] Click Here to view context",
if attachments: description=content,
for attachment in attachments: fields=[],
if attachment.content_type in supported_images: url=message.jump_url,
image_urls.append(attachment.url) timestamp=message.created_at,
if not content and len(image_urls) > 0: )
content = "\u200b" embed.set_author(
name=message.author.display_name,
url=message.jump_url,
icon_url=message.author.avatar.url,
)
embed.set_footer(text=ctx.guild.name + " | " + channel.name)
if len(image_urls) > 0:
embed.set_images(*image_urls)
star_components = Button(
style=ButtonStyle.DANGER,
emoji="🗑️",
custom_id=f"delete|{ctx.author.id}",
)
pin = await pinboard.send(embeds=embed, components=star_components)
embed = build_embed( await Pin(
title=f"[#{count}] Click Here to view context", index=count,
description=content, message=int(message.id),
fields=[], channel=int(channel.id),
url=message.jump_url, guild=int(ctx.guild.id),
timestamp=message.created_at, pinboard=channel_to_pinboard[pinboard.id],
) admin=int(ctx.author.id),
embed.set_author( pin=int(pin.id),
name=message.author.display_name, active=True,
url=message.jump_url, ).save()
icon_url=message.author.avatar.url,
)
embed.set_footer(text=ctx.guild.name + " | " + channel.name)
if len(image_urls) > 0:
embed.set_images(*image_urls)
star_components = Button(
style=ButtonStyle.DANGER,
emoji="🗑️",
custom_id=f"delete|{ctx.author.id}",
)
pin = await pinboard.send(embeds=embed, components=star_components)
await Pin( components[0].components[0].disabled = True
index=count,
message=int(message.id),
channel=int(channel.id),
guild=int(ctx.guild.id),
pinboard=channel_to_pinboard[pinboard.id],
admin=int(ctx.author.id),
pin=int(pin.id),
active=True,
).save()
components[0].components[0].disabled = True
await com_ctx.ctx.edit_origin( await com_ctx.ctx.edit_origin(
content=f"Message saved to Pinboard.\nSee it in {starboard.mention}", content=f"Message saved to Pinboard.\nSee it in {starboard.mention}",