text: # Copyright (C) 2021 TeamUltroid
  #
  # This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
  # PLease read the GNU Affero General Public License in
  # <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
  #
  # Ported by @Sokapgblg
  
  from telethon.tl.functions.channels import GetFullChannelRequest as getchat
  from telethon.tl.functions.phone import CreateGroupCallRequest as startvc
  from telethon.tl.functions.phone import DiscardGroupCallRequest as stopvc
  from telethon.tl.functions.phone import GetGroupCallRequest as getvc
  from telethon.tl.functions.phone import InviteToGroupCallRequest as invitetovc
  
  from userbot import ALIVE_NAME, CMD_HELP
  from userbot.events import register
  
  
  async def get_call(event):
      mm = await event.client(getchat(event.chat_id))
      xx = await event.client(getvc(mm.full_chat.call))
      return xx.call
  
  
  def user_list(l, n):
      for i in range(0, len(l), n):
          yield l[i : i + n]
  
  
  @register(outgoing=True, groups_only=True, pattern=r"^\.startvc$")
  async def start_voice(c):
      chat = await c.get_chat()
      admin = chat.admin_rights
      creator = chat.creator
  
      if not admin and not creator:
          await c.edit(f"**Maaf {ALIVE_NAME} Bukan Admin 👮**")
          return
      try:
          await c.client(startvc(c.chat_id))
          await c.edit("`Voice Chat Started...`")
      except Exception as ex:
          await c.edit(f"**ERROR:** `{ex}`")
  
  
  @register(outgoing=True, groups_only=True, pattern=r"^\.stopvc$")
  async def stop_voice(c):
      chat = await c.get_chat()
      admin = chat.admin_rights
      creator = chat.creator
  
      if not admin and not creator:
          await c.edit(f"**Maaf {ALIVE_NAME} Bukan Admin 👮**")
          return
      try:
          await c.client(stopvc(await get_call(c)))
          await c.edit("`Voice Chat Stopped...`")
      except Exception as ex:
          await c.edit(f"**ERROR:** `{ex}`")
  
  
  @register(outgoing=True, groups_only=True, pattern=r"^\.vcinvite")
  async def _(c):
      await c.edit("`Inviting Members to Voice Chat...`")
      users = []
      z = 0
      async for x in c.client.iter_participants(c.chat_id):
          if not x.bot:
              users.append(x.id)
      botman = list(user_list(users, 6))
      for p in botman:
          try:
              await c.client(invitetovc(call=await get_call(c), users=p))
              z += 6
          except BaseException:
              pass
      await c.edit(f"`{z}` **Orang Berhasil diundang ke VCG**")
  
  
  CMD_HELP.update(
      {
          "vcg": "**Plugin : **`vcg`\
          \n\n  •  **Syntax :** `.startvc`\
          \n  •  **Function : **Untuk Memulai voice chat group\
          \n\n  •  **Syntax :** `.stopvc`\
          \n  •  **Function : **Untuk Memberhentikan voice chat group\
          \n\n  •  **Syntax :** `.vcinvite`\
          \n  •  **Function : **Mengundang Member group ke voice chat group\
      "
      }
  )
  