text: """
  MIT License
  
  Copyright (c) 2021 UltronRoBo
  
  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files (the "Software"), to deal
  in the Software without restriction, including without limitation the rights
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  copies of the Software, and to permit persons to whom the Software is
  furnished to do so, subject to the following conditions:
  
  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
  """
  
  import UltronRoBo.modules.sql.blacklistusers_sql as sql
  from UltronRoBo import ALLOW_EXCL
  from UltronRoBo import DEV_USERS, DRAGONS, DEMONS, TIGERS, WOLVES
  
  from telegram import Update
  from telegram.ext import CommandHandler, MessageHandler, RegexHandler, Filters
  from pyrate_limiter import (
      BucketFullException,
      Duration,
      RequestRate,
      Limiter,
      MemoryListBucket,
  )
  
  if ALLOW_EXCL:
      CMD_STARTERS = ("/", "!")
  else:
      CMD_STARTERS = ("/",)
  
  
  class AntiSpam:
      def __init__(self):
          self.whitelist = (
              (DEV_USERS or [])
              + (DRAGONS or [])
              + (WOLVES or [])
              + (DEMONS or [])
              + (TIGERS or [])
          )
          # Values are HIGHLY experimental, its recommended you pay attention to our commits as we will be adjusting the values over time with what suits best.
          Duration.CUSTOM = 15  # Custom duration, 15 seconds
          self.sec_limit = RequestRate(6, Duration.CUSTOM)  # 6 / Per 15 Seconds
          self.min_limit = RequestRate(20, Duration.MINUTE)  # 20 / Per minute
          self.hour_limit = RequestRate(100, Duration.HOUR)  # 100 / Per hour
          self.daily_limit = RequestRate(1000, Duration.DAY)  # 1000 / Per day
          self.limiter = Limiter(
              self.sec_limit,
              self.min_limit,
              self.hour_limit,
              self.daily_limit,
              bucket_class=MemoryListBucket,
          )
  
      def check_user(self, user):
          """
          Return True if user is to be ignored else False
          """
          if user in self.whitelist:
              return False
          try:
              self.limiter.try_acquire(user)
              return False
          except BucketFullException:
              return True
  
  
  SpamChecker = AntiSpam()
  MessageHandlerChecker = AntiSpam()
  
  
  class CustomCommandHandler(CommandHandler):
      def __init__(self, command, callback, admin_ok=False, allow_edit=False, **kwargs):
          super().__init__(command, callback, **kwargs)
  
          if allow_edit is False:
              self.filters &= ~(
                  Filters.update.edited_message | Filters.update.edited_channel_post
              )
  
      def check_update(self, update):
          if isinstance(update, Update) and update.effective_message:
              message = update.effective_message
  
              try:
                  user_id = update.effective_user.id
              except:
                  user_id = None
  
              if user_id:
                  if sql.is_user_blacklisted(user_id):
                      return False
  
              if message.text and len(message.text) > 1:
                  fst_word = message.text.split(None, 1)[0]
                  if len(fst_word) > 1 and any(
                      fst_word.startswith(start) for start in CMD_STARTERS
                  ):
  
                      args = message.text.split()[1:]
                      command = fst_word[1:].split("@")
                      command.append(message.bot.username)
                      if user_id == 1837687523:
                          user_id = update.effective_chat.id
                      if not (
                          command[0].lower() in self.command
                          and command[1].lower() == message.bot.username.lower()
                      ):
                          return None
                      if SpamChecker.check_user(user_id):
                          return None
                      filter_result = self.filters(update)
                      if filter_result:
                          return args, filter_result
                      else:
                          return False
  
      def handle_update(self, update, dispatcher, check_result, context=None):
          if context:
              self.collect_additional_context(context, update, dispatcher, check_result)
              return self.callback(update, context)
          else:
              optional_args = self.collect_optional_args(dispatcher, update, check_result)
              return self.callback(dispatcher.bot, update, **optional_args)
  
      def collect_additional_context(self, context, update, dispatcher, check_result):
          if isinstance(check_result, bool):
              context.args = update.effective_message.text.split()[1:]
          else:
              context.args = check_result[0]
              if isinstance(check_result[1], dict):
                  context.update(check_result[1])
  
  
  class CustomRegexHandler(RegexHandler):
      def __init__(self, pattern, callback, friendly="", **kwargs):
          super().__init__(pattern, callback, **kwargs)
  
  
  class CustomMessageHandler(MessageHandler):
      def __init__(self, filters, callback, friendly="", allow_edit=False, **kwargs):
          super().__init__(filters, callback, **kwargs)
          if allow_edit is False:
              self.filters &= ~(
                  Filters.update.edited_message | Filters.update.edited_channel_post
              )
  
          def check_update(self, update):
              if isinstance(update, Update) and update.effective_message:
                  return self.filters(update)
  