text: # Ultroid - UserBot
  # Copyright (C) 2020 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 Koala @manusiarakitann
  # Recode by @mrismanaziz
  # FROM Man-Userbot <https://github.com/mrismanaziz/Man-Userbot>
  # t.me/SharingUserbot & t.me/Lunatic0de
  
  import asyncio
  
  from requests import get
  from telethon.errors.rpcerrorlist import FloodWaitError
  
  from userbot import CMD_HANDLER as cmd
  from userbot import CMD_HELP, DEVS
  from userbot.utils import edit_delete, edit_or_reply, man_cmd
  
  GCAST_BLACKLIST = get(
      "https://raw.githubusercontent.com/mrismanaziz/Reforestation/master/blacklistgcast.json"
  ).json()
  
  
  @man_cmd(pattern="gcast(?: |$)(.*)")
  async def gcast(event):
      xx = event.pattern_match.group(1)
      if xx:
          msg = xx
      elif event.is_reply:
          msg = await event.get_reply_message()
      else:
          return await edit_delete(event, "**Berikan Sebuah Pesan atau Reply**")
      kk = await edit_or_reply(event, "`Globally Broadcasting Msg...`")
      er = 0
      done = 0
      async for x in event.client.iter_dialogs():
          if x.is_group:
              chat = x.id
              if chat not in GCAST_BLACKLIST:
                  try:
                      await event.client.send_message(chat, msg)
                      await asyncio.sleep(0.1)
                      done += 1
                  except FloodWaitError as anj:
                      await asyncio.sleep(int(anj.seconds))
                  except BaseException:
                      er += 1
      await kk.edit(
          f"**Berhasil Mengirim Pesan Ke** `{done}` **Grup, Gagal Mengirim Pesan Ke** `{er}` **Grup**"
      )
  
  
  @man_cmd(pattern="gucast(?: |$)(.*)")
  async def gucast(event):
      xx = event.pattern_match.group(1)
      if xx:
          msg = xx
      elif event.is_reply:
          msg = await event.get_reply_message()
      else:
          return await edit_delete(event, "**Berikan Sebuah Pesan atau Reply**")
      kk = await edit_or_reply(event, "`Globally Broadcasting Msg...`")
      er = 0
      done = 0
      async for x in event.client.iter_dialogs():
          if x.is_user and not x.entity.bot:
              chat = x.id
              if chat not in DEVS:
                  try:
                      await event.client.send_message(chat, msg)
                      await asyncio.sleep(0.1)
                      done += 1
                  except FloodWaitError as anj:
                      await asyncio.sleep(int(anj.seconds))
                  except BaseException:
                      er += 1
      await kk.edit(
          f"**Berhasil Mengirim Pesan Ke** `{done}` **chat, Gagal Mengirim Pesan Ke** `{er}` **chat**"
      )
  
  
  CMD_HELP.update(
      {
          "gcast": f"**Plugin : **`gcast`\
          \n\n  •  **Syntax :** `{cmd}gcast` <text/reply media>\
          \n  •  **Function : **Mengirim Global Broadcast pesan ke Seluruh Grup yang kamu masuk. (Bisa Mengirim Media/Sticker)\
      "
      }
  )
  
  
  CMD_HELP.update(
      {
          "gucast": f"**Plugin : **`gucast`\
          \n\n  •  **Syntax :** `{cmd}gucast` <text/reply media>\
          \n  •  **Function : **Mengirim Global Broadcast pesan ke Seluruh Private Massage / PC yang masuk. (Bisa Mengirim Media/Sticker)\
      "
      }
  )
  