Fix minor issue from merge
This commit is contained in:
parent
6c73e0df48
commit
bcba51ed97
1 changed files with 105 additions and 108 deletions
|
@ -137,68 +137,65 @@ class PinboardCog(Extension):
|
|||
message: str,
|
||||
channel: GuildText = None,
|
||||
) -> None:
|
||||
try:
|
||||
if not channel:
|
||||
channel = ctx.channel
|
||||
pinboards = await Pinboard.find(Pinboard.guild == ctx.guild.id).to_list()
|
||||
if not pinboards:
|
||||
await ctx.send("No pinboards exist.", ephemeral=True)
|
||||
if not channel:
|
||||
channel = ctx.channel
|
||||
pinboards = await Pinboard.find(Pinboard.guild == ctx.guild.id).to_list()
|
||||
if not pinboards:
|
||||
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
|
||||
|
||||
await ctx.defer()
|
||||
channel_list = []
|
||||
to_delete: list[Pinboard] = []
|
||||
|
||||
if not isinstance(message, Message):
|
||||
if message.startswith("https://"):
|
||||
message = message.split("/")[-1]
|
||||
message = await channel.fetch_message(int(message))
|
||||
channel_to_pinboard = {}
|
||||
|
||||
if not message:
|
||||
await ctx.send("Message not found", ephemeral=True)
|
||||
return
|
||||
for pinboard in pinboards:
|
||||
c = await ctx.guild.fetch_channel(pinboard.channel)
|
||||
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 = []
|
||||
to_delete: list[Pinboard] = []
|
||||
for pinboard in to_delete:
|
||||
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:
|
||||
c = await ctx.guild.fetch_channel(pinboard.channel)
|
||||
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)
|
||||
select_channels = [
|
||||
StringSelectOption(label=x.name, value=str(idx))
|
||||
for idx, x in enumerate(channel_list)
|
||||
]
|
||||
|
||||
for pinboard in to_delete:
|
||||
try:
|
||||
await pinboard.delete()
|
||||
except Exception:
|
||||
self.logger.debug("Ignoring deletion error")
|
||||
select = StringSelectMenu(
|
||||
*select_channels,
|
||||
min_values=1,
|
||||
max_values=1,
|
||||
)
|
||||
|
||||
select_channels = []
|
||||
for idx, x in enumerate(channel_list):
|
||||
if x:
|
||||
select_channels.append(
|
||||
StringSelectOption(label=x.name, value=str(idx))
|
||||
)
|
||||
components = [ActionRow(select)]
|
||||
|
||||
select_channels = [
|
||||
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)
|
||||
msg = await ctx.send(content="Choose a pinboard", components=components)
|
||||
|
||||
com_ctx = await self.bot.wait_for_component(
|
||||
messages=msg,
|
||||
|
@ -208,68 +205,68 @@ class PinboardCog(Extension):
|
|||
|
||||
starboard = channel_list[int(com_ctx.ctx.values[0])]
|
||||
|
||||
exists = await Pin.find_one(
|
||||
Pin.message == int(message.id),
|
||||
Pin.channel == int(channel.id),
|
||||
Pin.guild == int(ctx.guild.id),
|
||||
Pin.pinboard == int(pinboard.id),
|
||||
exists = await Pin.find_one(
|
||||
Pin.message == int(message.id),
|
||||
Pin.channel == int(channel.id),
|
||||
Pin.guild == int(ctx.guild.id),
|
||||
Pin.pinboard == int(pinboard.id),
|
||||
)
|
||||
|
||||
if exists:
|
||||
await ctx.send(
|
||||
f"Message already sent to Pinboard {pinboard.mention}",
|
||||
ephemeral=True,
|
||||
)
|
||||
return
|
||||
|
||||
if exists:
|
||||
await ctx.send(
|
||||
f"Message already sent to Pinboard {pinboard.mention}",
|
||||
ephemeral=True,
|
||||
)
|
||||
return
|
||||
count = await Pin.find(
|
||||
Pin.guild == ctx.guild.id, Pin.pinboard == pinboard.id
|
||||
).count()
|
||||
content = message.content
|
||||
|
||||
count = await Pin.find(
|
||||
Pin.guild == ctx.guild.id, Pin.pinboard == pinboard.id
|
||||
).count()
|
||||
content = message.content
|
||||
attachments = message.attachments
|
||||
image_urls = []
|
||||
if attachments:
|
||||
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
|
||||
image_urls = []
|
||||
if attachments:
|
||||
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"
|
||||
embed = build_embed(
|
||||
title=f"[#{count}] Click Here to view context",
|
||||
description=content,
|
||||
fields=[],
|
||||
url=message.jump_url,
|
||||
timestamp=message.created_at,
|
||||
)
|
||||
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(
|
||||
title=f"[#{count}] Click Here to view context",
|
||||
description=content,
|
||||
fields=[],
|
||||
url=message.jump_url,
|
||||
timestamp=message.created_at,
|
||||
)
|
||||
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)
|
||||
await Pin(
|
||||
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()
|
||||
|
||||
await Pin(
|
||||
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
|
||||
components[0].components[0].disabled = True
|
||||
|
||||
await com_ctx.ctx.edit_origin(
|
||||
content=f"Message saved to Pinboard.\nSee it in {starboard.mention}",
|
||||
|
|
Loading…
Add table
Reference in a new issue