Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support attachments inside of embeds #109

Merged
merged 1 commit into from
Mar 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions cogs/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ async def edit_selector(
inter,
channel: disnake.TextChannel = commands.Param(description=response.get("message-edit-option-channel")),
number: int = commands.Param(description=response.get("message-edit-option-number")),
image: str = commands.Param(description=response.get("message-edit-option-image"), default=None),
thumbnail: str = commands.Param(description=response.get("message-edit-option-thumbnail"), default=None)
):
if not self.bot.isadmin(inter.author, inter.guild.id):
await inter.send(response.get("not-admin"))
Expand Down Expand Up @@ -393,24 +395,28 @@ async def edit_selector(
return
await old_msg.edit(suppress=False)

if (image and "https://" not in image) or (thumbnail and "https://" not in thumbnail):
await inter.send(response.get("invalid-attachment"))
return

await inter.response.send_modal(
title=response.get("modal-edit-title"),
custom_id=("edit_reactionrole"),
components=[
disnake.ui.TextInput(
label=response.get("message-edit-option-message"),
label=response.get("message-edit-modal-message"),
required=False,
custom_id="message",
style=disnake.TextInputStyle.paragraph,
),
disnake.ui.TextInput(
label=response.get("message-edit-option-title"),
label=response.get("message-edit-modal-title"),
required=False,
custom_id="title",
style=disnake.TextInputStyle.paragraph,
),
disnake.ui.TextInput(
label=response.get("message-edit-option-description"),
label=response.get("message-edit-modal-description"),
required=False,
custom_id="description",
style=disnake.TextInputStyle.paragraph,
Expand All @@ -432,6 +438,10 @@ async def edit_selector(
await selector_modal_inter.response.defer()
selector_embed = disnake.Embed()
selector_msg_new_body = None
if image:
selector_embed.set_image(url=image)
if thumbnail:
selector_embed.set_thumbnail(url=thumbnail)
for custom_id, value in selector_modal_inter.text_values.items():
if custom_id == "title" and value:
selector_embed.title = value
Expand Down
9 changes: 6 additions & 3 deletions i18n/en-gb.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"edit-reactionrole-nochannel": "You need to mention a channel.",
"edit-reactionrole-one": "There is only one reaction-role message in this channel. Use `1` in the `number` parameter.",
"edit-reactionrole-instructions": "There are **{num_messages}** reaction-role messages in this channel. Use the number of the message you want to edit in the `number` parameter. \nThe numbered list of the current reaction-role messages is:\n\n{message_list}",
"invalid-attachment": "The URL of the attachment is not valid. Ensure it is a correct URL starting with `https://`.",
"no-reactionrole-messages": "There are no reaction-role messages in that channel.",
"reactionrole-not-exists": "You selected a reaction-role message that does not exist.",
"select-valid-reactionrole": "Select a valid reaction-role message number (i.e. the number to the left of the reaction-role message content in the list above).",
Expand Down Expand Up @@ -134,9 +135,11 @@
"brief-update": "Updates the bot",
"message-edit-option-channel": "The channel in which the message you want to edit is located",
"message-edit-option-number": "The number of the message in the channel (enter 0 for explanation)",
"message-edit-option-message": "The message of the reaction-role (optional)",
"message-edit-option-title": "The title of the embed (optional)",
"message-edit-option-description": "The description of the embed (optional)",
"message-edit-option-image": "The URL of the image to attach to the embed (optional)",
"message-edit-option-thumbnail": "The URL of the thumbnail to attach to the embed (optional)",
"message-edit-modal-message": "The message of the reaction-role (optional)",
"message-edit-modal-title": "The title of the embed (optional)",
"message-edit-modal-description": "The description of the embed (optional)",
"modal-edit-title": "Message Editing",
"message-reaction-option-channel": "The channel in which the message you want to add/remove the reaction is located",
"message-reaction-option-action": "Use 'add' or 'remove' to add/remove a reaction to an existing message",
Expand Down