Channel will terminate when the last user quit
This commit is contained in:
parent
91eecb4b0b
commit
3fe67e18b0
@ -9,6 +9,7 @@ from discord import (
|
||||
utils,
|
||||
)
|
||||
from discord.ext import commands
|
||||
from discord.abc import GuildChannel
|
||||
|
||||
from functions import (
|
||||
appendLog,
|
||||
@ -32,6 +33,11 @@ class CogChannel(commands.Cog):
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_guild_channel_delete(self, channel: GuildChannel):
|
||||
if isUserVoice(channel):
|
||||
await removeUserVoice(channel)
|
||||
|
||||
@Cog.listener()
|
||||
async def on_voice_state_update(
|
||||
self, member: Member, before: VoiceState, after: VoiceState
|
||||
@ -44,14 +50,15 @@ class CogChannel(commands.Cog):
|
||||
# If user left vc
|
||||
if before.channel is not None and len(before.channel.members) == 0:
|
||||
if isUserVoice(vc_from):
|
||||
if isVoiceOfUser(vc_from, member):
|
||||
await removeUserVoice(vc_from)
|
||||
else:
|
||||
if not isVoiceOfUser(vc_from, member):
|
||||
if loadJson("config.json")["enable_nomic"]:
|
||||
await changeNomicPerms("deny", vc_from, member)
|
||||
await removeUserVoice(vc_from)
|
||||
|
||||
# If user joined vc
|
||||
if after.channel is not None and after.channel.id == guildConfGet(member.guild, "channel"):
|
||||
if after.channel is not None and after.channel.id == guildConfGet(
|
||||
member.guild, "channel"
|
||||
):
|
||||
if isUserVoice(vc_to):
|
||||
if loadJson("config.json")["enable_nomic"]:
|
||||
await changeNomicPerms("allow", vc_to, member)
|
||||
|
36
functions.py
36
functions.py
@ -253,31 +253,45 @@ async def removeUserVoice(vc: VoiceChannel) -> None:
|
||||
nomic_channel = utils.get(vc.guild.channels, id=vc_conf["nomic"])
|
||||
|
||||
remove(vc_file)
|
||||
|
||||
await needed_channel.delete()
|
||||
if debug:
|
||||
appendLog(
|
||||
f"Removed voice channel '{needed_channel}' ({str(needed_channel.id)}) of user with id {str(vc_conf['ownerid'])}",
|
||||
guild=vc.guild,
|
||||
)
|
||||
else:
|
||||
|
||||
if needed_channel is None:
|
||||
appendLog(
|
||||
f"Removed voice channel '{needed_channel}' of user with id {str(vc_conf['ownerid'])}",
|
||||
guild=vc.guild,
|
||||
)
|
||||
else:
|
||||
await needed_channel.delete()
|
||||
|
||||
if loadJson("config.json")["enable_nomic"]:
|
||||
await nomic_channel.delete()
|
||||
if debug:
|
||||
appendLog(
|
||||
f"Removed nomic channel {nomic_channel} ({str(nomic_channel.id)}) of channel with id {str(needed_channel.id)}",
|
||||
f"Removed voice channel '{needed_channel}' ({str(needed_channel.id)}) of user with id {str(vc_conf['ownerid'])}",
|
||||
guild=vc.guild,
|
||||
)
|
||||
else:
|
||||
appendLog(
|
||||
f"Removed voice channel '{needed_channel}' of user with id {str(vc_conf['ownerid'])}",
|
||||
guild=vc.guild,
|
||||
)
|
||||
|
||||
if loadJson("config.json")["enable_nomic"]:
|
||||
if nomic_channel is None:
|
||||
appendLog(
|
||||
f"Removed nomic channel '{nomic_channel}' of channel with id {str(needed_channel.id)}",
|
||||
guild=vc.guild,
|
||||
)
|
||||
else:
|
||||
await nomic_channel.delete()
|
||||
|
||||
if debug:
|
||||
appendLog(
|
||||
f"Removed nomic channel '{nomic_channel}' ({str(nomic_channel.id)}) of channel with id {str(needed_channel.id)}",
|
||||
guild=vc.guild,
|
||||
)
|
||||
else:
|
||||
appendLog(
|
||||
f"Removed nomic channel '{nomic_channel}' of channel with id {str(needed_channel.id)}",
|
||||
guild=vc.guild,
|
||||
)
|
||||
else:
|
||||
return
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user