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

Move mutes to new cog, add role-based and temporary mutes #3634

Merged
merged 105 commits into from
Oct 26, 2020
Merged
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
105 commits
Select commit Hold shift + click to select a range
3131b53
revert the revert the revert git is hard...
TrustyJAID Mar 10, 2020
11be71a
and remove old mutes
TrustyJAID Mar 10, 2020
35af119
make voicemutes less yelly
TrustyJAID Apr 8, 2020
997e1b2
fix error when no args present in mute commands
TrustyJAID May 3, 2020
80e038f
update docstrings
TrustyJAID May 3, 2020
49fda23
address review
TrustyJAID May 3, 2020
bb3fa22
black
TrustyJAID May 3, 2020
d15e940
oops
TrustyJAID May 3, 2020
9c8582c
fix voicemutes
TrustyJAID May 3, 2020
7216a28
remove mutes.py file
TrustyJAID May 24, 2020
97427c9
Remove _voice_perm_check from mod since it's now in mutes cog
TrustyJAID Aug 21, 2020
56da871
remove naive datetimes
TrustyJAID Aug 22, 2020
773ada2
change alias for channelunmute
TrustyJAID Aug 22, 2020
79e3cb0
add `[p]activemutes` to show current mutes in the server and time rem…
TrustyJAID Aug 22, 2020
6991ff4
improve resolution of unmute time
TrustyJAID Aug 31, 2020
7438cf9
black
TrustyJAID Aug 31, 2020
ef96ea8
Show indefinite mutes in activemutes and only show the current server…
TrustyJAID Sep 1, 2020
ffdd31d
replace message.created_at with timezone aware timezone
TrustyJAID Sep 1, 2020
0cab70f
remove "server" from activemutes to clean up look since channelmutes …
TrustyJAID Sep 4, 2020
238b5cc
better cache management, add tracking for manual muted role removal i…
TrustyJAID Sep 7, 2020
b786c4b
Fix keyerror in mutes command when unsuccessful mutes
TrustyJAID Sep 8, 2020
33949e2
add typing indicator and improve config settings
TrustyJAID Sep 9, 2020
9bfa5ec
flake8 issue
TrustyJAID Sep 9, 2020
dea04ed
add one time message when attempting to mute without a role set, cons…
TrustyJAID Sep 10, 2020
fefd134
Don't clear the whole guilds settings when a mute is finished. Optimi…
TrustyJAID Sep 12, 2020
e4d36b4
Utilize usage to make converter make more sense
TrustyJAID Sep 13, 2020
b09632a
remove decorator permission checks and fix doc strings
TrustyJAID Sep 13, 2020
a259475
handle role changes better
TrustyJAID Sep 13, 2020
faa6f3e
More sanely handle channel mutes return and improve failed mutes dial…
TrustyJAID Sep 15, 2020
2112776
Handle re-mute on leave properly
TrustyJAID Sep 15, 2020
59fa1ab
fix unbound error in overwrites mute
TrustyJAID Sep 16, 2020
3200303
revert the revert the revert git is hard...
TrustyJAID Mar 10, 2020
4cdcdcb
and remove old mutes
TrustyJAID Mar 10, 2020
e1dbd54
make voicemutes less yelly
TrustyJAID Apr 8, 2020
f0aba92
fix error when no args present in mute commands
TrustyJAID May 3, 2020
48dae60
update docstrings
TrustyJAID May 3, 2020
bb01487
address review
TrustyJAID May 3, 2020
6bef730
black
TrustyJAID May 3, 2020
c5d89f8
oops
TrustyJAID May 3, 2020
6c78406
fix voicemutes
TrustyJAID May 3, 2020
f654e78
Remove _voice_perm_check from mod since it's now in mutes cog
TrustyJAID Aug 21, 2020
807ddb5
remove naive datetimes
TrustyJAID Aug 22, 2020
50dfda2
change alias for channelunmute
TrustyJAID Aug 22, 2020
5e0e4b4
add `[p]activemutes` to show current mutes in the server and time rem…
TrustyJAID Aug 22, 2020
3697150
improve resolution of unmute time
TrustyJAID Aug 31, 2020
94f5651
black
TrustyJAID Aug 31, 2020
86a3222
Show indefinite mutes in activemutes and only show the current server…
TrustyJAID Sep 1, 2020
ef1325e
replace message.created_at with timezone aware timezone
TrustyJAID Sep 1, 2020
7ab1e3c
remove "server" from activemutes to clean up look since channelmutes …
TrustyJAID Sep 4, 2020
ecf92be
better cache management, add tracking for manual muted role removal i…
TrustyJAID Sep 7, 2020
c0d1a34
Fix keyerror in mutes command when unsuccessful mutes
TrustyJAID Sep 8, 2020
9edd0f6
add typing indicator and improve config settings
TrustyJAID Sep 9, 2020
8aed8e5
flake8 issue
TrustyJAID Sep 9, 2020
ad7478a
add one time message when attempting to mute without a role set, cons…
TrustyJAID Sep 10, 2020
cd036ac
Don't clear the whole guilds settings when a mute is finished. Optimi…
TrustyJAID Sep 12, 2020
347035d
Utilize usage to make converter make more sense
TrustyJAID Sep 13, 2020
a74d324
remove decorator permission checks and fix doc strings
TrustyJAID Sep 13, 2020
bb215b1
handle role changes better
TrustyJAID Sep 13, 2020
1dbf3c0
More sanely handle channel mutes return and improve failed mutes dial…
TrustyJAID Sep 15, 2020
89f8a5d
Handle re-mute on leave properly
TrustyJAID Sep 15, 2020
bb8ae07
fix unbound error in overwrites mute
TrustyJAID Sep 16, 2020
80d77cc
remove mutes.pt
TrustyJAID Oct 4, 2020
4b42e1e
Merge remote-tracking branch 'origin/mutes-rewrite' into mutes-rewrite
TrustyJAID Oct 4, 2020
e6d2a1b
remove reliance on mods is_allowed_by_hierarchy since we don't have a…
TrustyJAID Oct 4, 2020
044aeff
black
TrustyJAID Oct 4, 2020
eda8659
fix hierarchy check
TrustyJAID Oct 4, 2020
cf776b1
wtf
TrustyJAID Oct 9, 2020
83dba8a
Cache mute roles for large bots
TrustyJAID Oct 14, 2020
67bd678
fix lint
TrustyJAID Oct 14, 2020
a8fce00
fix this error
TrustyJAID Oct 16, 2020
b0d48ab
Address review 1
TrustyJAID Oct 19, 2020
10d30db
lint
TrustyJAID Oct 19, 2020
e56dab6
fix string i18n issue
TrustyJAID Oct 19, 2020
4ced346
remove unused typing.Coroutine import and fix i18n again
TrustyJAID Oct 19, 2020
e965d3e
missed this docstring
TrustyJAID Oct 19, 2020
28fd0d0
Put voiceban and voiceunban back in mod where it's more appropriate
TrustyJAID Oct 20, 2020
37cfec1
Address review 2 electric boogaloo
TrustyJAID Oct 20, 2020
ab94c46
Make voicemutes use same methods as channel mute
TrustyJAID Oct 21, 2020
d84100b
black
TrustyJAID Oct 21, 2020
1d7d041
handle humanize_list doesn't accept generators
TrustyJAID Oct 21, 2020
a2a7ecc
update voicemutes docstrings
TrustyJAID Oct 21, 2020
a34a66c
make voiceperm check consistent with rest of error handling
TrustyJAID Oct 21, 2020
55ef274
bleh
TrustyJAID Oct 21, 2020
f269521
fix modlog case spam when overrides are in place
TrustyJAID Oct 22, 2020
e3c67de
Merge remote-tracking branch 'upstream/V3/develop' into mutes-rewrite
Drapersniper Oct 23, 2020
b518270
<a:pandaexplode:639975629793787922>
TrustyJAID Oct 24, 2020
ad6e0b0
bleck
TrustyJAID Oct 24, 2020
c17c49f
use total_seconds() instead of a dict, sorry everyone already using t…
TrustyJAID Oct 24, 2020
b9310df
<:excited:474074780887285776> This should be everything
TrustyJAID Oct 25, 2020
6e9f2a2
black
TrustyJAID Oct 25, 2020
a1a2906
fix the things
TrustyJAID Oct 25, 2020
bc7cb3f
bleh
TrustyJAID Oct 25, 2020
0d22cdb
more cleanup
TrustyJAID Oct 25, 2020
20a59d2
lmao hang on
TrustyJAID Oct 25, 2020
b017478
fix voice mutes thingy
TrustyJAID Oct 25, 2020
f1b1581
Title Case Permissions
TrustyJAID Oct 25, 2020
34fd102
oh I see
TrustyJAID Oct 26, 2020
0e608e3
I'm running out of funny one-liners for commit messages
TrustyJAID Oct 26, 2020
3189595
oof
TrustyJAID Oct 26, 2020
8a69d12
ugh
TrustyJAID Oct 26, 2020
ae3b7d4
let's try this
TrustyJAID Oct 26, 2020
f603f55
voicemutes manage_permissions
TrustyJAID Oct 26, 2020
3b0b6d2
Cleanup mutes if they expire when member is not present
TrustyJAID Oct 26, 2020
d42a34f
black
TrustyJAID Oct 26, 2020
01fbb3d
linters go brr
TrustyJAID Oct 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/redbot/cogs/audio/** @aikaterna @Drapersniper
/redbot/cogs/downloader/* @jack1142
/redbot/cogs/streams/* @palmtree5
/redbot/cogs/mutes/* @TrustyJAID

# Trivia Lists
/redbot/cogs/trivia/data/lists/whosthatpokemon*.yaml @aikaterna
Expand Down
132 changes: 131 additions & 1 deletion redbot/cogs/mod/kickban.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
from redbot.core import commands, i18n, checks, modlog
from redbot.core.commands import UserInputOptional
from redbot.core.utils import AsyncIter
from redbot.core.utils.chat_formatting import pagify, humanize_number, bold, humanize_list
from redbot.core.utils.chat_formatting import (
pagify,
humanize_number,
bold,
humanize_list,
format_perms_list,
)
from redbot.core.utils.mod import get_audit_reason
from .abc import MixinMeta
from .converters import RawUserIds
Expand Down Expand Up @@ -60,6 +66,48 @@ async def get_invite_for_reinvite(ctx: commands.Context, max_age: int = 86400):
except discord.HTTPException:
return

@staticmethod
async def _voice_perm_check(
ctx: commands.Context, user_voice_state: Optional[discord.VoiceState], **perms: bool
) -> bool:
"""Check if the bot and user have sufficient permissions for voicebans.

This also verifies that the user's voice state and connected
channel are not ``None``.

Returns
-------
bool
``True`` if the permissions are sufficient and the user has
a valid voice state.

"""
if user_voice_state is None or user_voice_state.channel is None:
await ctx.send(_("That user is not in a voice channel."))
return False
voice_channel: discord.VoiceChannel = user_voice_state.channel
required_perms = discord.Permissions()
required_perms.update(**perms)
if not voice_channel.permissions_for(ctx.me) >= required_perms:
await ctx.send(
_("I require the {perms} permission(s) in that user's channel to do that.").format(
perms=format_perms_list(required_perms)
)
)
return False
if (
ctx.permission_state is commands.PermState.NORMAL
and not voice_channel.permissions_for(ctx.author) >= required_perms
):
await ctx.send(
_(
"You must have the {perms} permission(s) in that user's channel to use this "
"command."
).format(perms=format_perms_list(required_perms))
)
return False
return True

async def ban_user(
self,
user: Union[discord.Member, discord.User, discord.Object],
Expand Down Expand Up @@ -678,6 +726,88 @@ async def voicekick(
channel=case_channel,
)

@commands.command()
@commands.guild_only()
@checks.admin_or_permissions(mute_members=True, deafen_members=True)
async def voiceunban(self, ctx: commands.Context, user: discord.Member, *, reason: str = None):
"""Unban a user from speaking and listening in the server's voice channels."""
user_voice_state = user.voice
if (
await self._voice_perm_check(
ctx, user_voice_state, deafen_members=True, mute_members=True
)
is False
):
return
needs_unmute = True if user_voice_state.mute else False
needs_undeafen = True if user_voice_state.deaf else False
audit_reason = get_audit_reason(ctx.author, reason)
if needs_unmute and needs_undeafen:
await user.edit(mute=False, deafen=False, reason=audit_reason)
elif needs_unmute:
await user.edit(mute=False, reason=audit_reason)
elif needs_undeafen:
await user.edit(deafen=False, reason=audit_reason)
else:
await ctx.send(_("That user isn't muted or deafened by the server."))
return

guild = ctx.guild
author = ctx.author
await modlog.create_case(
self.bot,
guild,
ctx.message.created_at.replace(tzinfo=timezone.utc),
"voiceunban",
user,
author,
reason,
until=None,
channel=None,
)
await ctx.send(_("User is now allowed to speak and listen in voice channels."))

@commands.command()
@commands.guild_only()
@checks.admin_or_permissions(mute_members=True, deafen_members=True)
async def voiceban(self, ctx: commands.Context, user: discord.Member, *, reason: str = None):
"""Ban a user from speaking and listening in the server's voice channels."""
user_voice_state: discord.VoiceState = user.voice
if (
await self._voice_perm_check(
ctx, user_voice_state, deafen_members=True, mute_members=True
)
is False
):
return
needs_mute = True if user_voice_state.mute is False else False
needs_deafen = True if user_voice_state.deaf is False else False
audit_reason = get_audit_reason(ctx.author, reason)
author = ctx.author
guild = ctx.guild
if needs_mute and needs_deafen:
await user.edit(mute=True, deafen=True, reason=audit_reason)
elif needs_mute:
await user.edit(mute=True, reason=audit_reason)
elif needs_deafen:
await user.edit(deafen=True, reason=audit_reason)
else:
await ctx.send(_("That user is already muted and deafened server-wide."))
return

await modlog.create_case(
self.bot,
guild,
ctx.message.created_at.replace(tzinfo=timezone.utc),
"voiceban",
user,
author,
reason,
until=None,
channel=None,
)
await ctx.send(_("User has been banned from speaking or listening in voice channels."))

@commands.command()
@commands.guild_only()
@commands.bot_has_permissions(ban_members=True)
Expand Down
2 changes: 0 additions & 2 deletions redbot/cogs/mod/mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from redbot.core.utils._internal_utils import send_to_owners_with_prefix_replaced
from .events import Events
from .kickban import KickBanMixin
from .mutes import MuteMixin
from .names import ModInfo
from .slowmode import Slowmode
from .settings import ModSettings
Expand All @@ -38,7 +37,6 @@ class Mod(
ModSettings,
Events,
KickBanMixin,
MuteMixin,
ModInfo,
Slowmode,
commands.Cog,
Expand Down