From de25e6a0b61c87c57f2c696c8c3a84fb21ef4ed6 Mon Sep 17 00:00:00 2001 From: TrustyJAID Date: Sun, 31 Mar 2024 16:19:01 -0600 Subject: [PATCH] Improve issue list display by grouping by unique users and include the channel mention on issues with channel overwrite mutes --- redbot/cogs/mutes/mutes.py | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/redbot/cogs/mutes/mutes.py b/redbot/cogs/mutes/mutes.py index 72bb570d846..a296d3103e2 100644 --- a/redbot/cogs/mutes/mutes.py +++ b/redbot/cogs/mutes/mutes.py @@ -1278,13 +1278,23 @@ async def mute( if issue_list: await self.handle_issues(ctx, issue_list) - def parse_issues(self, issue: Union[MuteResponse, ChannelMuteResponse]) -> str: - reason_msg = issue.reason + "\n" if issue.reason else None - error_msg = _("{member} could not be (un)muted for the following reasons:\n").format( - member=issue.user - ) - if reason_msg: - error_msg += reason_msg + def parse_issues(self, issues: List[Union[MuteResponse, ChannelMuteResponse]]) -> str: + users = set(issue.user for issue in issues) + error_msg = "" + + for user in users: + error_msg += _("{member} could not be (un)muted for the following reasons:\n").format( + member=f"`{user}`" + ) + # I would like to replace this with a user mention but send_interactive + # does not support supressing mentions at this time. So in order to keep + # this formatting consistent the username is excaped in a code block. + for issue in issues: + if issue.user.id != user.id: + continue + if issue.reason: + error_msg += f"- {issue.reason}\n" + return error_msg async def handle_issues( @@ -1327,7 +1337,7 @@ async def handle_issues( if can_react: with contextlib.suppress(discord.Forbidden): await query.clear_reactions() - issue = "\n".join(self.parse_issues(issue) for issue in issue_list) + issue = self.parse_issues(issue_list) resp = pagify(issue) await ctx.send_interactive(resp) @@ -1934,7 +1944,7 @@ async def channel_unmute_user( if channel.id in self._channel_mutes and user.id in self._channel_mutes[channel.id]: current_mute = self._channel_mutes[channel.id].pop(user.id) else: - ret.reason = _(MUTE_UNMUTE_ISSUES["already_unmuted"]) + ret.reason = f"{channel.mention} " + _(MUTE_UNMUTE_ISSUES["already_unmuted"]) return ret if not current_mute["voice_mute"] and voice_mute: @@ -1944,7 +1954,7 @@ async def channel_unmute_user( return ret if not channel.permissions_for(guild.me).manage_permissions: - ret.reason = _(MUTE_UNMUTE_ISSUES["permissions_issue_channel"]) + ret.reason = f"{channel.mention} " + _(MUTE_UNMUTE_ISSUES["permissions_issue_channel"]) return ret try: @@ -1973,7 +1983,7 @@ async def channel_unmute_user( # catch all discord errors because the result will be the same # we successfully muted by this point but can't move the user ret.success = True - ret.reason = _(MUTE_UNMUTE_ISSUES["voice_mute_permission"]) + ret.reason = f"{channel.mention} " + _(MUTE_UNMUTE_ISSUES["voice_mute_permission"]) return ret ret.success = True return ret