diff --git a/.version b/.version index b5021469..75a22a26 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -3.0.2 +3.0.3 diff --git a/CHANGELOG.md b/CHANGELOG.md index 57201e9d..97646b87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Reaction Light - Changelog +### 3.0.3 +- Allow (once again) new lines via modals ([#101](https://github.com/eibex/reaction-light/issues/101) closed by [#103](https://github.com/eibex/reaction-light/pull/103) by [eibex](https://github.com/eibex)) +- Bump disnake requirement to v2.4.0 (necessary to update disnake manually) + + ### 3.0.2 - Fix `/bot version` - Bump disnake requirement to v2.3.2 (necessary to update disnake manually) diff --git a/README.md b/README.md index d86d7c1d..08b0b11e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Reaction Light - Discord Role Bot [![Reaction Light Discord Server](https://img.shields.io/discord/914952998109716531?color=5865f2&logo=discord&logoColor=ffffff)](https://discord.gg/cqxZQkhhHm) -[![Reaction Light 3.0.2](https://img.shields.io/badge/Reaction%20Light-3.0.2-yellow.svg)](https://github.com/eibex/reaction-light/blob/master/CHANGELOG.md) +[![Reaction Light 3.0.3](https://img.shields.io/badge/Reaction%20Light-3.0.3-yellow.svg)](https://github.com/eibex/reaction-light/blob/master/CHANGELOG.md) [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](#) -[![disnake 2.3.2+](https://img.shields.io/badge/disnake-2.3.2+-blue.svg)](#) +[![disnake 2.4.0+](https://img.shields.io/badge/disnake-2.4.0+-blue.svg)](#) ![Reaction Light Embed Example](https://i.imgur.com/f4b9Qye.png) diff --git a/cogs/message.py b/cogs/message.py index 3d132bb5..4f5baed8 100644 --- a/cogs/message.py +++ b/cogs/message.py @@ -340,28 +340,24 @@ async def edit_selector( self, inter, channel: disnake.TextChannel = commands.Param(description=response.get("message-edit-option-channel")), - number: int = commands.Param(description=response.get("message-edit-option-number")), - message: str = commands.Param(description=response.get("message-edit-option-message"), default="none"), - title: str = commands.Param(description=response.get("message-edit-option-title"), default="none"), - description: str = commands.Param(description=response.get("message-edit-option-description"), default="none"), + number: int = commands.Param(description=response.get("message-edit-option-number")) ): if not self.bot.isadmin(inter.author, inter.guild.id): await inter.send(response.get("not-admin")) return - await inter.response.defer() all_messages = await self.formatted_channel_list(channel) if number == 0: if len(all_messages) == 1: - await inter.edit_original_message(content=response.get("edit-reactionrole-one").format(channel_name=channel.name)) + await inter.send(content=response.get("edit-reactionrole-one").format(channel_name=channel.name)) elif len(all_messages) > 1: - await inter.edit_original_message( + await inter.send( content=response.get("edit-reactionrole-instructions").format( num_messages=len(all_messages), channel_name=channel.name, message_list="\n".join(all_messages) ) ) else: - await inter.edit_original_message(content=response.get("no-reactionrole-messages")) + await inter.send(content=response.get("no-reactionrole-messages")) else: try: # Tries to edit the reaction-role message @@ -371,9 +367,6 @@ async def edit_selector( except DatabaseError as error: await self.bot.report(response.get("db-error-fetching-messages").format(message_ids=error), inter.guild.id) return - message = message if message.lower() != "none" else None - title = title if title.lower() != "none" else None - description = description if description.lower() != "none" else None counter = 1 if all_messages: message_to_edit_id = None @@ -394,40 +387,79 @@ async def edit_selector( await inter.send(response.get("select-valid-reactionrole")) return await old_msg.edit(suppress=False) - selector_msg_new_body = message + + 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"), + required=False, + custom_id="message", + style=disnake.TextInputStyle.paragraph + ), + disnake.ui.TextInput( + label=response.get("message-edit-option-title"), + required=False, + custom_id="title", + style=disnake.TextInputStyle.paragraph + ), + disnake.ui.TextInput( + label=response.get("message-edit-option-description"), + required=False, + custom_id="description", + style=disnake.TextInputStyle.paragraph + ), + ] + ) + + try: + selector_modal_inter: disnake.ModalInteraction = await self.bot.wait_for("modal_submit", + check=lambda i: i.custom_id == "edit_reactionrole" and i.author.id == inter.author.id, + timeout=300, + ) + except asyncio.TimeoutError: + # The user didn't submit the modal in the specified period of time. + # This is done since Discord doesn't dispatch any event for when a modal is closed/dismissed. + return + + await selector_modal_inter.response.defer() selector_embed = disnake.Embed() + selector_msg_new_body = None + for custom_id, value in selector_modal_inter.text_values.items(): + if custom_id == "title" and value: + selector_embed.title = value + selector_embed.colour = self.bot.config.botcolour + selector_embed.set_footer(text=f"{self.bot.config.botname}", icon_url=self.bot.config.logo) - if title: - selector_embed.title = title - selector_embed.colour = self.bot.config.botcolour - selector_embed.set_footer(text=f"{self.bot.config.botname}", icon_url=self.bot.config.logo) + elif custom_id == "description" and value: + selector_embed.description = value + selector_embed.colour = self.bot.config.botcolour + selector_embed.set_footer(text=f"{self.bot.config.botname}", icon_url=self.bot.config.logo) - if description: - selector_embed.description = description - selector_embed.colour = self.bot.config.botcolour - selector_embed.set_footer(text=f"{self.bot.config.botname}", icon_url=self.bot.config.logo) + elif custom_id == "message" and value: + selector_msg_new_body = value try: - if selector_embed.title or selector_embed.description: await old_msg.edit(content=selector_msg_new_body, embed=selector_embed) else: await old_msg.edit(content=selector_msg_new_body, embed=None) - await inter.edit_original_message(content=response.get("message-edited")) + await selector_modal_inter.edit_original_message(content=response.get("message-edited")) except disnake.Forbidden: - await inter.edit_original_message(content=response.get("other-author-error")) + await selector_modal_inter.edit_original_message(content=response.get("other-author-error")) return except disnake.HTTPException as e: if e.code == 50006: - await inter.edit_original_message(content=response.get("empty-message-error")) + await selector_modal_inter.edit_original_message(content=response.get("empty-message-error")) else: guild_id = inter.guild.id await self.bot.report(str(e), guild_id) except IndexError: - await inter.edit_original_message(content=response.get("invalid-target-channel")) + await inter.send(content=response.get("invalid-target-channel")) except disnake.Forbidden: - await inter.edit_original_message(content=response.get("edit-permission-error")) + await inter.send(content=response.get("edit-permission-error")) @message_group.sub_command(name="reaction", description=response.get("brief-message-reaction")) async def edit_reaction( diff --git a/files/i18n/en-gb.json b/files/i18n/en-gb.json index 4d6ad81c..4c65759c 100644 --- a/files/i18n/en-gb.json +++ b/files/i18n/en-gb.json @@ -134,9 +134,10 @@ "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 message (enter 'none' to skip)", - "message-edit-option-title": "The title of the reaction-role message (enter 'none' to skip)", - "message-edit-option-description": "The description of the reaction-role message (enter 'none' to skip)", + "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)", + "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", "message-reaction-option-number": "The number of the message in the channel (enter 0 for explanation)", diff --git a/requirements.txt b/requirements.txt index 0404d800..b6e01ad0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -disnake>=2.3.2 +disnake>=2.4.0