text: import html
  import json
  import os
  from typing import Optional
  
  from PikachuRobot import (DEV_USERS, OWNER_ID, DRAGONS, SUPPORT_CHAT, DEMONS,
                            TIGERS, WOLVES, dispatcher)
  from PikachuRobot.modules.helper_funcs.chat_status import (dev_plus, sudo_plus,
                                                             whitelist_plus)
  from PikachuRobot.modules.helper_funcs.extraction import extract_user
  from PikachuRobot.modules.log_channel import gloggable
  from telegram import ParseMode, TelegramError, Update
  from telegram.ext import CallbackContext, CommandHandler, run_async
  from telegram.utils.helpers import mention_html
  
  ELEVATED_USERS_FILE = os.path.join(os.getcwd(),
                                     'PikachuRobot/elevated_users.json')
  
  
  def check_user_id(user_id: int, context: CallbackContext) -> Optional[str]:
      bot = context.bot
      if not user_id:
          reply = "That...is a chat! baka ka omae?"
  
      elif user_id == bot.id:
          reply = "This does not work that way."
  
      else:
          reply = None
      return reply
  
  
  # This can serve as a deeplink example.
  #disasters =
  # """ Text here """
  
  # do not async, not a handler
  #def send_disasters(update):
  #    update.effective_message.reply_text(
  #        disasters, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True)
  
  ### Deep link example ends
  
  #FtSasaki adding add to pro developer cmd :D
  
  @run_async
  @dev_plus
  @gloggable
  def addpiro(update: Update, context: CallbackContext) -> str:
      message = update.effective_message
      user = update.effective_user
      chat = update.effective_chat
      bot, args = context.bot, context.args
      user_id = extract_user(message, args)
      user_member = bot.getChat(user_id)
      rt = ""
  
      reply = check_user_id(user_id, bot)
      if reply:
          message.reply_text(reply)
          return ""
  
      with open(ELEVATED_USERS_FILE, 'r') as infile:
          data = json.load(infile)
          
      if int(user_id) in DEV_USERS:
        message.reply_text("This member is already a Pro Developer")
          
      if user_id in DRAGONS:
          rt += "Requested AU to promote a Dragon Disaster to Pro Developer."
          data['sudos'].remove(user_id)
          DRAGONS.remove(user_id)
  
      if user_id in DEMONS:
          rt += "Requested AU to promote a Demon Disaster to Pro Developer."
          data['supports'].remove(user_id)
          DEMONS.remove(user_id)
  
      if user_id in WOLVES:
          rt += "Requested AU to promote a Wolf Disaster to Pro Developer."
          data['whitelists'].remove(user_id)
          WOLVES.remove(user_id)
  
      data['devs'].append(user_id)
      DEV_USERS.append(user_id)
  
      with open(ELEVATED_USERS_FILE, 'w') as outfile:
          json.dump(data, outfile, indent=4)
  
      update.effective_message.reply_text(
          rt + "\nSuccessfully set Disaster level of {} to Pro Developer!".format(
              user_member.first_name))
  
      log_message = (
          f"#ProDeveloper\n"
          f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
          f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}"
      )
  
      if chat.type != 'private':
          log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message
  
      return log_message
  
    
  @run_async
  @dev_plus
  @gloggable
  def addsudo(update: Update, context: CallbackContext) -> str:
      message = update.effective_message
      user = update.effective_user
      chat = update.effective_chat
      bot, args = context.bot, context.args
      user_id = extract_user(message, args)
      user_member = bot.getChat(user_id)
      rt = ""
  
      reply = check_user_id(user_id, bot)
      if reply:
          message.reply_text(reply)
          return ""
  
      with open(ELEVATED_USERS_FILE, 'r') as infile:
          data = json.load(infile)
  
      if user_id in DRAGONS:
          message.reply_text("This member is already a Dragon Disaster")
          return ""
  
      if user_id in DEMONS:
          rt += "Requested AU to promote a Demon Disaster to Dragon."
          data['supports'].remove(user_id)
          DEMONS.remove(user_id)
  
      if user_id in WOLVES:
          rt += "Requested AU to promote a Wolf Disaster to Dragon."
          data['whitelists'].remove(user_id)
          WOLVES.remove(user_id)
  
      data['sudos'].append(user_id)
      DRAGONS.append(user_id)
  
      with open(ELEVATED_USERS_FILE, 'w') as outfile:
          json.dump(data, outfile, indent=4)
  
      update.effective_message.reply_text(
          rt + "\nSuccessfully set Disaster level of {} to Dragon!".format(
              user_member.first_name))
  
      log_message = (
          f"#SUDO\n"
          f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
          f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}"
      )
  
      if chat.type != 'private':
          log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message
  
      return log_message
  
  
  @run_async
  @sudo_plus
  @gloggable
  def addsupport(
      update: Update,
      context: CallbackContext,
  ) -> str:
      message = update.effective_message
      user = update.effective_user
      chat = update.effective_chat
      bot, args = context.bot, context.args
      user_id = extract_user(message, args)
      user_member = bot.getChat(user_id)
      rt = ""
  
      reply = check_user_id(user_id, bot)
      if reply:
          message.reply_text(reply)
          return ""
  
      with open(ELEVATED_USERS_FILE, 'r') as infile:
          data = json.load(infile)
  
      if user_id in DRAGONS:
          rt += "Requested AU to demote this Dragon to Demon"
          data['sudos'].remove(user_id)
          DRAGONS.remove(user_id)
  
      if user_id in DEMONS:
          message.reply_text("This user is already a Demon Disaster.")
          return ""
  
      if user_id in WOLVES:
          rt += "Requested AU to promote this Wolf Disaster to Demon"
          data['whitelists'].remove(user_id)
          WOLVES.remove(user_id)
  
      data['supports'].append(user_id)
      DEMONS.append(user_id)
  
      with open(ELEVATED_USERS_FILE, 'w') as outfile:
          json.dump(data, outfile, indent=4)
  
      update.effective_message.reply_text(
          rt + f"\n{user_member.first_name} was added as a Demon Disaster!")
  
      log_message = (
          f"#SUPPORT\n"
          f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
          f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}"
      )
  
      if chat.type != 'private':
          log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message
  
      return log_message
  
  
  @run_async
  @sudo_plus
  @gloggable
  def addwhitelist(update: Update, context: CallbackContext) -> str:
      message = update.effective_message
      user = update.effective_user
      chat = update.effective_chat
      bot, args = context.bot, context.args
      user_id = extract_user(message, args)
      user_member = bot.getChat(user_id)
      rt = ""
  
      reply = check_user_id(user_id, bot)
      if reply:
          message.reply_text(reply)
          return ""
  
      with open(ELEVATED_USERS_FILE, 'r') as infile:
          data = json.load(infile)
  
      if user_id in DRAGONS:
          rt += "This member is a Dragon Disaster, Demoting to Wolf."
          data['sudos'].remove(user_id)
          DRAGONS.remove(user_id)
  
      if user_id in DEMONS:
          rt += "This user is already a Demon Disaster, Demoting to Wolf."
          data['supports'].remove(user_id)
          DEMONS.remove(user_id)
  
      if user_id in WOLVES:
          message.reply_text("This user is already a Wolf Disaster.")
          return ""
  
      data['whitelists'].append(user_id)
      WOLVES.append(user_id)
  
      with open(ELEVATED_USERS_FILE, 'w') as outfile:
          json.dump(data, outfile, indent=4)
  
      update.effective_message.reply_text(
          rt +
          f"\nSuccessfully promoted {user_member.first_name} to a Wolf Disaster!")
  
      log_message = (
          f"#WHITELIST\n"
          f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))} \n"
          f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}"
      )
  
      if chat.type != 'private':
          log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message
  
      return log_message
  
  
  @run_async
  @sudo_plus
  @gloggable
  def addtiger(update: Update, context: CallbackContext) -> str:
      message = update.effective_message
      user = update.effective_user
      chat = update.effective_chat
      bot, args = context.bot, context.args
      user_id = extract_user(message, args)
      user_member = bot.getChat(user_id)
      rt = ""
  
      reply = check_user_id(user_id, bot)
      if reply:
          message.reply_text(reply)
          return ""
  
      with open(ELEVATED_USERS_FILE, 'r') as infile:
          data = json.load(infile)
  
      if user_id in DRAGONS:
          rt += "This member is a Dragon Disaster, Demoting to Tiger."
          data['sudos'].remove(user_id)
          DRAGONS.remove(user_id)
  
      if user_id in DEMONS:
          rt += "This user is already a Demon Disaster, Demoting to Tiger."
          data['supports'].remove(user_id)
          DEMONS.remove(user_id)
  
      if user_id in WOLVES:
          rt += "This user is already a Wolf Disaster, Demoting to Tiger."
          data['whitelists'].remove(user_id)
          WOLVES.remove(user_id)
  
      if user_id in TIGERS:
          message.reply_text("This user is already a Tiger.")
          return ""
  
      data['tigers'].append(user_id)
      TIGERS.append(user_id)
  
      with open(ELEVATED_USERS_FILE, 'w') as outfile:
          json.dump(data, outfile, indent=4)
  
      update.effective_message.reply_text(
          rt +
          f"\nSuccessfully promoted {user_member.first_name} to a Tiger Disaster!"
      )
  
      log_message = (
          f"#TIGER\n"
          f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))} \n"
          f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}"
      )
  
      if chat.type != 'private':
          log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message
  
      return log_message
  
  
  @run_async
  @dev_plus
  @gloggable
  def rmpiro(update: Update, context: CallbackContext) -> str:
      message = update.effective_message
      user = update.effective_user
      chat = update.effective_chat
      bot, args = context.bot, context.args
      user_id = extract_user(message, args)
      user_member = bot.getChat(user_id)
  
      reply = check_user_id(user_id, bot)
      if reply:
          message.reply_text(reply)
          return ""
  
      with open(ELEVATED_USERS_FILE, 'r') as infile:
          data = json.load(infile)
  
      if user_id in DEV_USERS:
          message.reply_text("Requested AU to demote this user to Civilian")
          DEV_USERS.remove(user_id)
          data['devs'].remove(user_id)
  
          with open(ELEVATED_USERS_FILE, 'w') as outfile:
              json.dump(data, outfile, indent=4)
  
          log_message = (
              f"#UNDEV\n"
              f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
              f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}"
          )
  
          if chat.type != 'private':
              log_message = "<b>{}:</b>\n".format(html.escape(
                  chat.title)) + log_message
  
          return log_message
  
      else:
          message.reply_text("This user is not a Pro Developer Disaster!")
          return ""
        
        
  @run_async
  @dev_plus
  @gloggable
  def removesudo(update: Update, context: CallbackContext) -> str:
      message = update.effective_message
      user = update.effective_user
      chat = update.effective_chat
      bot, args = context.bot, context.args
      user_id = extract_user(message, args)
      user_member = bot.getChat(user_id)
  
      reply = check_user_id(user_id, bot)
      if reply:
          message.reply_text(reply)
          return ""
  
      with open(ELEVATED_USERS_FILE, 'r') as infile:
          data = json.load(infile)
  
      if user_id in DRAGONS:
          message.reply_text("Requested AU to demote this user to Civilian")
          DRAGONS.remove(user_id)
          data['sudos'].remove(user_id)
  
          with open(ELEVATED_USERS_FILE, 'w') as outfile:
              json.dump(data, outfile, indent=4)
  
          log_message = (
              f"#UNSUDO\n"
              f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
              f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}"
          )
  
          if chat.type != 'private':
              log_message = "<b>{}:</b>\n".format(html.escape(
                  chat.title)) + log_message
  
          return log_message
  
      else:
          message.reply_text("This user is not a Dragon Disaster!")
          return ""
  
  
  @run_async
  @sudo_plus
  @gloggable
  def removesupport(update: Update, context: CallbackContext) -> str:
      message = update.effective_message
      user = update.effective_user
      chat = update.effective_chat
      bot, args = context.bot, context.args
      user_id = extract_user(message, args)
      user_member = bot.getChat(user_id)
  
      reply = check_user_id(user_id, bot)
      if reply:
          message.reply_text(reply)
          return ""
  
      with open(ELEVATED_USERS_FILE, 'r') as infile:
          data = json.load(infile)
  
      if user_id in DEMONS:
          message.reply_text("Requested AU to demote this user to Civilian")
          DEMONS.remove(user_id)
          data['supports'].remove(user_id)
  
          with open(ELEVATED_USERS_FILE, 'w') as outfile:
              json.dump(data, outfile, indent=4)
  
          log_message = (
              f"#UNSUPPORT\n"
              f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
              f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}"
          )
  
          if chat.type != 'private':
              log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message
  
          return log_message
  
      else:
          message.reply_text("This user is not a Demon level Disaster!")
          return ""
  
  
  @run_async
  @sudo_plus
  @gloggable
  def removewhitelist(update: Update, context: CallbackContext) -> str:
      message = update.effective_message
      user = update.effective_user
      chat = update.effective_chat
      bot, args = context.bot, context.args
      user_id = extract_user(message, args)
      user_member = bot.getChat(user_id)
  
      reply = check_user_id(user_id, bot)
      if reply:
          message.reply_text(reply)
          return ""
  
      with open(ELEVATED_USERS_FILE, 'r') as infile:
          data = json.load(infile)
  
      if user_id in WOLVES:
          message.reply_text("Demoting to normal user")
          WOLVES.remove(user_id)
          data['whitelists'].remove(user_id)
  
          with open(ELEVATED_USERS_FILE, 'w') as outfile:
              json.dump(data, outfile, indent=4)
  
          log_message = (
              f"#UNWHITELIST\n"
              f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
              f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}"
          )
  
          if chat.type != 'private':
              log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message
  
          return log_message
      else:
          message.reply_text("This user is not a Wolf Disaster!")
          return ""
  
  
  @run_async
  @sudo_plus
  @gloggable
  def removetiger(update: Update, context: CallbackContext) -> str:
      message = update.effective_message
      user = update.effective_user
      chat = update.effective_chat
      bot, args = context.bot, context.args
      user_id = extract_user(message, args)
      user_member = bot.getChat(user_id)
  
      reply = check_user_id(user_id, bot)
      if reply:
          message.reply_text(reply)
          return ""
  
      with open(ELEVATED_USERS_FILE, 'r') as infile:
          data = json.load(infile)
  
      if user_id in TIGERS:
          message.reply_text("Demoting to normal user")
          TIGERS.remove(user_id)
          data['tigers'].remove(user_id)
  
          with open(ELEVATED_USERS_FILE, 'w') as outfile:
              json.dump(data, outfile, indent=4)
  
          log_message = (
              f"#UNTIGER\n"
              f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
              f"<b>User:</b> {mention_html(user_member.id, html.escape(user_member.first_name))}"
          )
  
          if chat.type != 'private':
              log_message = f"<b>{html.escape(chat.title)}:</b>\n" + log_message
  
          return log_message
      else:
          message.reply_text("This user is not a Tiger Disaster!")
          return ""
  
  
  @run_async
  @whitelist_plus
  def whitelistlist(update: Update, context: CallbackContext):
      reply = "<b>Known Wolf Disasters 🐺:</b>\n"
      bot = context.bot
      for each_user in WOLVES:
          user_id = int(each_user)
          try:
              user = bot.get_chat(user_id)
  
              reply += f"• {mention_html(user_id, html.escape(user.first_name))}\n"
          except TelegramError:
              pass
      update.effective_message.reply_text(reply, parse_mode=ParseMode.HTML)
  
  
  @run_async
  @whitelist_plus
  def tigerlist(update: Update, context: CallbackContext):
      reply = "<b>Known Tiger Disasters 🐯:</b>\n"
      bot = context.bot
      for each_user in TIGERS:
          user_id = int(each_user)
          try:
              user = bot.get_chat(user_id)
              reply += f"• {mention_html(user_id, html.escape(user.first_name))}\n"
          except TelegramError:
              pass
      update.effective_message.reply_text(reply, parse_mode=ParseMode.HTML)
  
  
  @run_async
  @whitelist_plus
  def supportlist(update: Update, context: CallbackContext):
      bot = context.bot
      reply = "<b>Known Demon Disasters 👹:</b>\n"
      for each_user in DEMONS:
          user_id = int(each_user)
          try:
              user = bot.get_chat(user_id)
              reply += f"• {mention_html(user_id, html.escape(user.first_name))}\n"
          except TelegramError:
              pass
      update.effective_message.reply_text(reply, parse_mode=ParseMode.HTML)
  
  
  @run_async
  @whitelist_plus
  def sudolist(update: Update, context: CallbackContext):
      bot = context.bot
      true_sudo = list(set(DRAGONS) - set(DEV_USERS))
      reply = "<b>Known Dragon Disasters 🐉:</b>\n"
      for each_user in true_sudo:
          user_id = int(each_user)
          try:
              user = bot.get_chat(user_id)
              reply += f"• {mention_html(user_id, html.escape(user.first_name))}\n"
          except TelegramError:
              pass
      update.effective_message.reply_text(reply, parse_mode=ParseMode.HTML)
  
  
  @run_async
  @whitelist_plus
  def devlist(update: Update, context: CallbackContext):
      bot = context.bot
      true_dev = list(set(DEV_USERS) - {OWNER_ID})
      reply = "<b>Anteiku Union Members ⚡️:</b>\n"
      for each_user in true_dev:
          user_id = int(each_user)
          try:
              user = bot.get_chat(user_id)
              reply += f"• {mention_html(user_id, html.escape(user.first_name))}\n"
          except TelegramError:
              pass
      update.effective_message.reply_text(reply, parse_mode=ParseMode.HTML)
  
  
  
  
  
  DEV_HANDLER = CommandHandler(("addpiro", "addsudo"), addpiro)
  SUDO_HANDLER = CommandHandler(("addsudo", "adddragon"), addsudo)
  SUPPORT_HANDLER = CommandHandler(("addsupport", "adddemon"), addsupport)
  TIGER_HANDLER = CommandHandler(("addtiger"), addtiger)
  WHITELIST_HANDLER = CommandHandler(("addwhitelist", "addwolf"), addwhitelist)
  
  RMPIRO_HANDLER = CommandHandler(("rmpiro", "removesudo"), rmpiro)
  UNSUDO_HANDLER = CommandHandler(("removesudo", "removedragon"), removesudo)
  UNSUPPORT_HANDLER = CommandHandler(("removesupport", "removedemon"),
                                     removesupport)
  UNTIGER_HANDLER = CommandHandler(("removetiger"), removetiger)
  UNWHITELIST_HANDLER = CommandHandler(("removewhitelist", "removewolf"),
                                       removewhitelist)
  
  WHITELISTLIST_HANDLER = CommandHandler(["whitelistlist", "wolves"],
                                         whitelistlist)
  TIGERLIST_HANDLER = CommandHandler(["tigers"], tigerlist)
  SUPPORTLIST_HANDLER = CommandHandler(["supportlist", "demons"], supportlist)
  SUDOLIST_HANDLER = CommandHandler(["sudolist", "dragons"], sudolist)
  DEVLIST_HANDLER = CommandHandler(["devlist", "heroes"], devlist)
  
  dispatcher.add_handler(DEV_HANDLER)
  dispatcher.add_handler(SUDO_HANDLER)
  dispatcher.add_handler(SUPPORT_HANDLER)
  dispatcher.add_handler(TIGER_HANDLER)
  dispatcher.add_handler(WHITELIST_HANDLER)
  
  dispatcher.add_handler(RMPIRO_HANDLER)
  dispatcher.add_handler(UNSUDO_HANDLER)
  dispatcher.add_handler(UNSUPPORT_HANDLER)
  dispatcher.add_handler(UNTIGER_HANDLER)
  dispatcher.add_handler(UNWHITELIST_HANDLER)
  
  dispatcher.add_handler(WHITELISTLIST_HANDLER)
  dispatcher.add_handler(TIGERLIST_HANDLER)
  dispatcher.add_handler(SUPPORTLIST_HANDLER)
  dispatcher.add_handler(SUDOLIST_HANDLER)
  dispatcher.add_handler(DEVLIST_HANDLER)
  
  __handlers__ = [
      DEV_HANDLER, SUDO_HANDLER, SUPPORT_HANDLER, TIGER_HANDLER, WHITELIST_HANDLER,
      RMPIRO_HANDLER, UNSUDO_HANDLER, UNSUPPORT_HANDLER, UNTIGER_HANDLER, UNWHITELIST_HANDLER,
      WHITELISTLIST_HANDLER, TIGERLIST_HANDLER, SUPPORTLIST_HANDLER,
      SUDOLIST_HANDLER, DEVLIST_HANDLER
  ]
  