Change lock/lockdown to affect voice channels, closes #41, closes #42

This commit is contained in:
Zeva Rose 2021-07-11 16:27:34 -06:00
parent 3ca194e638
commit ae1d32b485

View file

@ -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: