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
Move mutes to new cog, add role-based and temporary mutes #3634
Move mutes to new cog, add role-based and temporary mutes #3634
Conversation
227561e
to
ae6ccf1
Compare
566875d
to
f00be9f
Compare
Couple small things i found when testing
https://media.kstj.us/DarkorangeImaginativeDunlin.png though i can confirm it adds the person to each channel and revokes perms properly,
though it does remove the overrides properly it just throws an ugly error, i also get a similar traceback when trying it with role mutes too, though the key error changes their ID versus the guild id as it was before
traceback just for consistency
If any of this doesn't make sense let me know and i can explain further |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the reasoning behind abandoning the work done on V3/feature/mutes
, but there are issues with this code here which were actually considered in that branch even in an unfinished state
redbot/cogs/mutes/mutes.py
Outdated
if member.id in self._channel_mutes[channel.id]: | ||
del self._channel_mutes[channel.id][member.id] | ||
mute_role = await self.config.guild(guild).mute_role() | ||
if not mute_role: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't a safe way to determine if someone was muted, data about mutes should be stored upon muting, it also only works if they were role muted instead of overwrites being applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was intentional when I started on this as I did not want to support permission based muting be applied when a user left and rejoined encouraging people use the role based model instead if they wanted to prevent people leaving and rejoining to avoid a mute.
async def on_member_join(self, member: discord.Member): | ||
guild = member.guild | ||
mute_role = await self.config.guild(guild).mute_role() | ||
if not mute_role: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also prevents re-applying channel permission based mutes.
return False, _(mute_unmute_issues["hierarchy_problem"]) | ||
|
||
old_overs = {k: getattr(overwrites, k) for k in new_overs} | ||
overwrites.update(**new_overs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Storing the old overwrites is an error that could change other permissions upon unmute, this should only store the difference in permissions caused by the mute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only stores the old overwrites for specific permissions on that user. overwrites
above is the channel perms for that user only and the state they were in before they were muted. This was straight from the old mutes in mod.
It would be great if this would expose some kind of an API that'd allow 3rd party cogs to apply timed / permanent mutes as well. I have a cog that currently has to do this manually, via creating it's own |
@DevilXD that was outside the scope of this PR. I wanted to get the new features in people's hands and get them stable before things are re-arranged as an API which also moves a lot of this outside of a cog and into something core always has available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just a code review, I still have to test any of this.
I marked any instances of datetime usage (I'm sure I missed some) so that someone who better understood #4017 can more easily take a look at them.
Most part of this looks fine to me
I can't imagine a lot of situations where a time delta would be used inside a reason field that isn't meant to be the time itself. It's more lax this way so that users can start with the time or end with it and not have to really think "which goes first again?" when they're trying to just get the mute done. If it's a problem you can specify time as well with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- It seems that you only did the reason grouping for the notification channel, but not for any of the mute commands which is what my previous review comment was presenting.
- Would it possible to check these before trying the channel mutes so that it only shows once for the whole user?
- I consider this a nit, but now that we send information when the user is already muted in the channel, it looks a bit weird for the server unmute (and mute too I guess):
And I really like the idea of being more user friendly here, and I think it's really cool that you can start or end with the time. I was just wondering, if allowing to put it in the middle was also intended here or if it's just a bit unfortunate side effect. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once all changes that were requested so far (including the review comments in this review) are done, this should be in a mergeable state. I know it's easier said than done though, but I just wanted to let you know that I won't add anything else to my reviews than I already have (unless some new issues get introduced of course). And if you will need any help, feel free to ask :)
Now onto this review, aside from code comments, there's one thing that hasn't been included in them as it wasn't referring to one specific code part:
- Channel overrides not being reapplied on guild join should be documented in some help docstrings and probably also sent instructions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aside from the code comments, it looks like there's still one thing that wasn't addressed and/or answered to (quote rephrased to better explain what I meant):
- "Multi" channel unmutes in modlog don't mention the channel(s) they refer to. Maybe it should be at least put somewhere in the reason since we can't set multiple channels on a modlog entry?
This might be the last review before approval - I still need to do some testing with the newly introduced changes so there is a chance I'll find some bug, but if I don't, it will be time for approval.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Channel mutes are only saved to cache, they don't persist on bot restart (applies to both overrides-based
[p]mute
and to[p]channelmute
and[p]voicemute
commands) - Case for
[p]vocemute
doesn't contain the duration/until fields - It seems that Administrator check is done before channel mutes and is shown nicely, but hierarchy check is done during channel mutes and lists all channels it failed for:
What can also be seen on the screenshot below is that there's a nice empty line betweenAlmostSlime
andJackenmen
that improves readability, but such an empty line doesn't exist betweenJackenmen
andKslibLivxud
.
Besides what I mentioned, I think we could do one more thing improving readability - make the different reasons form a list by preceding each reason with-
:
- not very critical, but the check for manage roles permission could additionally be checked before proceeding to loop through users so that this doesn't happen:
- the error for missing Manage Permissions in the channel is inaccurate (it's talking about role hierarchy that doesn't apply to channel permissions at all + the bot doesn't need the Manage Roles permission but rather the Manage Permissions permission in that specific channel):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's that time! LGTM, let's ship it! 😏
Thanks for all the work on this @TrustyJAID and thanks for all the help with testing to our contributors ❤️
Type
Description of the changes
This moves mutes outside of the mod cog into its own separate cog.
[p]mute
defaults to serverwide muting and[p]mutechannel
mutes in the current channel