2023-05-03 19:53:01 +03:00
|
|
|
|
import discord
|
|
|
|
|
from discord.ext import commands
|
|
|
|
|
from discord.utils import get
|
|
|
|
|
|
2023-05-15 17:29:09 +03:00
|
|
|
|
from utils.checks import is_white
|
2023-05-03 19:53:01 +03:00
|
|
|
|
import asyncio
|
2023-05-15 17:29:09 +03:00
|
|
|
|
from utils.emojis import check_mark
|
2023-05-03 19:53:01 +03:00
|
|
|
|
|
|
|
|
|
from bot import db
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class privateChannels(commands.Cog, name="Приватные комнаты"):
|
|
|
|
|
"""Работа с приватными комнатами"""
|
|
|
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
|
self.bot = bot
|
|
|
|
|
|
|
|
|
|
@commands.Cog.listener()
|
|
|
|
|
async def on_voice_state_update(self, member, before, after):
|
2023-05-16 16:34:50 +03:00
|
|
|
|
if (
|
|
|
|
|
before.channel and
|
|
|
|
|
(await db.private_channels.find_one({'id': before.channel.id})) and
|
|
|
|
|
not self.bot.get_channel(before.channel.id)
|
|
|
|
|
):
|
|
|
|
|
await db.private_channels.delete_one({'id': before.channel.id})
|
2023-05-03 19:53:01 +03:00
|
|
|
|
|
|
|
|
|
if (
|
2023-05-16 16:34:50 +03:00
|
|
|
|
before.channel and
|
2023-05-16 20:30:59 +03:00
|
|
|
|
not before.channel.members and
|
2023-05-16 16:34:50 +03:00
|
|
|
|
not (await db.private_channels.find_one({'id': before.channel.id})) and
|
|
|
|
|
(await db.private_channels.find_one({'category_id': before.channel.category_id}))
|
2023-05-03 19:53:01 +03:00
|
|
|
|
):
|
|
|
|
|
await before.channel.delete()
|
|
|
|
|
|
2023-05-16 16:34:50 +03:00
|
|
|
|
if after.channel and (await db.private_channels.find_one({"id": after.channel.id})):
|
2023-05-03 19:53:01 +03:00
|
|
|
|
new_private = await after.channel.category.create_voice_channel(name=member.display_name)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
await member.edit(voice_channel=new_private)
|
|
|
|
|
except discord.errors.HTTPException:
|
|
|
|
|
await new_private.delete()
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
await new_private.set_permissions(member, manage_channels=True, move_members=True, manage_permissions=True)
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
2023-05-20 21:18:55 +03:00
|
|
|
|
voice = member.guild.me.voice
|
2023-05-03 19:53:01 +03:00
|
|
|
|
|
2023-05-20 21:18:55 +03:00
|
|
|
|
if voice and tuple(voice.channel.members) == (member.guild.me,):
|
2023-05-16 20:30:59 +03:00
|
|
|
|
await member.guild.voice_client.disconnect()
|
2023-05-03 19:53:01 +03:00
|
|
|
|
|
|
|
|
|
@commands.command(brief="Присваивает комнату главной",
|
|
|
|
|
help="Идея приватных комнат состоит в том, что при входе в ГК создается пприватная комната. "
|
|
|
|
|
"Тот самый ГК и является главной комнатой. Эта команда присваивает ГК, в котором вы "
|
|
|
|
|
"находитесь в главный")
|
|
|
|
|
@commands.check(is_white)
|
|
|
|
|
async def set_private(self, ctx):
|
2023-05-16 20:30:59 +03:00
|
|
|
|
if (await db.private_channels.find_one({'id': ctx.author.voice.channel.id})):
|
2023-05-03 19:53:01 +03:00
|
|
|
|
await ctx.message.delete()
|
|
|
|
|
message = await ctx.send('Канал уже добавлен')
|
|
|
|
|
else:
|
2023-05-16 20:30:59 +03:00
|
|
|
|
await db.private_channels.insert_one({"id": ctx.author.voice.channel.id, 'category_id': ctx.author.voice.channel.category.id})
|
2023-05-03 19:53:01 +03:00
|
|
|
|
await ctx.message.add_reaction(check_mark)
|
|
|
|
|
message = ctx.message
|
|
|
|
|
|
|
|
|
|
await asyncio.sleep(3)
|
|
|
|
|
await message.delete()
|
|
|
|
|
|
|
|
|
|
@commands.command(brief="Делает комнату не приватной")
|
|
|
|
|
@commands.check(is_white)
|
|
|
|
|
async def unset_private(self, ctx):
|
|
|
|
|
if ctx.author.voice is not None:
|
|
|
|
|
message = await ctx.send("Требуется выйти из ГК")
|
|
|
|
|
await self.bot.wait_for("voice_state_update", check=lambda member, _, after: \
|
|
|
|
|
member == ctx.message.author and after.channel is None)
|
|
|
|
|
await message.edit(content="Зайдите в ГК")
|
|
|
|
|
await self.bot.wait_for("voice_state_update", check=lambda member, _, after: \
|
|
|
|
|
member == ctx.message.author and after.channel is not None)
|
|
|
|
|
else:
|
|
|
|
|
message = await ctx.send("Зайдите в ГК")
|
|
|
|
|
await self.bot.wait_for("voice_state_update", check=lambda member, _, after: \
|
|
|
|
|
member == ctx.message.author and after.channel is not None)
|
2023-05-16 16:34:50 +03:00
|
|
|
|
if (await db.private_channels.find_one({'id': ctx.author.voice.channel.id})):
|
|
|
|
|
await db.private_channels.delete_one({"id": ctx.author.voice.channel.id})
|
2023-05-03 19:53:01 +03:00
|
|
|
|
await ctx.message.add_reaction(check_mark)
|
|
|
|
|
else:
|
|
|
|
|
await message.edit(content='Этот канал не является приватным')
|
|
|
|
|
|
|
|
|
|
await asyncio.sleep(3)
|
|
|
|
|
await ctx.message.delete()
|
|
|
|
|
await message.delete()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def setup(bot):
|
|
|
|
|
await bot.add_cog(privateChannels(bot))
|