From ae1d32b485e6672bd6a676e3ffb56511e111fe5e Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Sun, 11 Jul 2021 16:27:34 -0600 Subject: [PATCH] Change lock/lockdown to affect voice channels, closes #41, closes #42 --- jarvis/cogs/admin.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/jarvis/cogs/admin.py b/jarvis/cogs/admin.py index 782c275..ee4a1e2 100644 --- a/jarvis/cogs/admin.py +++ b/jarvis/cogs/admin.py @@ -1,8 +1,9 @@ import re from datetime import datetime, timedelta +from typing import Union import pymongo -from discord import Member, Role, TextChannel, User +from discord import Member, Role, TextChannel, User, VoiceChannel from discord.ext import commands from discord.utils import find, get from discord_slash import SlashContext, cog_ext @@ -556,24 +557,30 @@ class AdminCog(commands.Cog): async def _lock_channel( self, - channel: TextChannel, + channel: Union[TextChannel, VoiceChannel], role: Role, admin: User, reason: str, allow_send=False, ): overrides = channel.overwrites_for(role) - overrides.send_messages = allow_send + if isinstance(channel, TextChannel): + overrides.send_messages = allow_send + elif isinstance(channel, VoiceChannel): + overrides.speak = allow_send await channel.set_permissions(role, overwrite=overrides, reason=reason) async def _unlock_channel( self, - channel: TextChannel, + channel: Union[TextChannel, VoiceChannel], role: Role, admin: User, ): overrides = channel.overwrites_for(role) - overrides.send_messages = None + if isinstance(channel, TextChannel): + overrides.send_messages = None + elif isinstance(channel, VoiceChannel): + overrides.speak = None await channel.set_permissions(role, overwrite=overrides) @cog_ext.cog_slash( @@ -607,7 +614,7 @@ class AdminCog(commands.Cog): ctx: SlashContext, reason: str, duration: int = 10, - channel: TextChannel = None, + channel: Union[TextChannel, VoiceChannel] = None, ): await ctx.defer() if not channel: @@ -647,7 +654,7 @@ class AdminCog(commands.Cog): async def _unlock( self, ctx: SlashContext, - channel: TextChannel = None, + channel: Union[TextChannel, VoiceChannel] = None, ): await ctx.defer() if not channel: