Skip to content

Commit

Permalink
Improve issue list display by grouping by unique users and include th…
Browse files Browse the repository at this point in the history
…e channel mention on issues with channel overwrite mutes
  • Loading branch information
TrustyJAID committed Mar 31, 2024
1 parent f458505 commit de25e6a
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions redbot/cogs/mutes/mutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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

0 comments on commit de25e6a

Please sign in to comment.