text: from requests import get
  from re import findall
  import os
  import glob
  from rubika.client import Bot
  import requests
  from rubika.tools import Tools
  from rubika.encryption import encryption
  from gtts import gTTS
  from mutagen.mp3 import MP3
  import time
  import random
  import urllib
  import io
  
  print ("welcome, Created By Ali HL\n")
  
  print ("Please subscribe to the channel to receive updates! : for telegram : @ASY0405\n")
  
  bot = Bot(input("Please enter your Auth:"))
  target=input("Please Enter Your Guid (Group): ")
  
  print ("\nThe robot was successfully activated.")
  
  def hasAds(msg):
  	links = ["http://","https://",".ir",".com",".org",".net",".me"]
  	for i in links:
  		if i in msg:
  			return True
  			
  def hasInsult(msg):
  	swData = [False,None]
  	for i in open("dontReadMe.txt").read().split("\n"):
  		if i in msg:
  			swData = [True, i]
  			break
  		else: continue
  	return swData
  	
  # static variable
  answered, sleeped, retries = [], False, {}
  
  alerts, blacklist = [] , []
  
  def alert(guid,user,link=False):
  	alerts.append(guid)
  	coun = int(alerts.count(guid))
  
  	haslink = ""
  	if link : haslink = "گزاشتن لینک در گروه ممنوع میباشد .\n"
  
  	if coun == 1:
  		bot.sendMessage(target, "💢 اخطار [ @"+user+" ] \n"+haslink+" شما (1/2) اخطار دریافت کرده اید .")
  
  	elif coun == 2:
  		blacklist.append(guid)
  		bot.sendMessage(target, "🚫 کاربر [ @"+user+" ] \n (2/2) اخطار دریافت کرد ، .")
  		bot.banGroupMember(target, guid)
  
  
  while True:
  	# time.sleep(15)
  	try:
  		admins = [i["member_guid"] for i in bot.getGroupAdmins(target)["data"]["in_chat_members"]]
  		min_id = bot.getGroupInfo(target)["data"]["chat"]["last_message_id"]
  
  		while True:
  			try:
  				messages = bot.getMessages(target,min_id)
  				break
  			except:
  				continue
  
  		for msg in messages:
  			try:
  				if msg["type"]=="Text" and not msg.get("message_id") in answered:
  					if not sleeped:
  						if hasAds(msg.get("text")) and not msg.get("author_object_guid") in admins :
  							guid = msg.get("author_object_guid")
  							user = bot.getUserInfo(guid)["data"]["user"]["username"]
  							bot.deleteMessages(target, [msg.get("message_id")])
  							alert(guid,user,True)
  								
  						elif msg.get("text") == "!restart" or msg.get("text") == "/restart" and msg.get("author_object_guid") in admins :
  							try:
  								sleeped = True
  								bot.sendMessage(target, "در حال راه اندازی مجدد...", message_id=msg.get("message_id"))
  								sleeped = False
  								bot.sendMessage(target, "ربا‌ت با موفقیت مجددا راه اندازی شد!", message_id=msg.get("message_id"))
  							except:
  								print("err Restart bot")
  								
  						elif msg.get("text").startswith("حذف") and msg.get("author_object_guid") in admins :
  							try:
  								number = int(msg.get("text").split(" ")[1])
  								answered.reverse()
  								bot.deleteMessages(target, answered[0:number])
  
  								bot.sendMessage(target, "✅ "+ str(number) +" پیام اخیر با موفقیت حذف شد", message_id=msg.get("message_id"))
  								answered.reverse()
  
  							except IndexError:
  								bot.deleteMessages(target, [msg.get("reply_to_message_id")])
  								bot.sendMessage(target, "✅ پیام با موفقیت حذف شد", message_id=msg.get("message_id"))
  							except:
  								bot.sendMessage(target, "❌ لطفا دستور را به درستی وارد کنید", message_id=msg.get("message_id"))
  
  						elif msg.get("text").startswith("اخراج") and msg.get("author_object_guid") in admins :
  							try:
  								guid = bot.getInfoByUsername(msg.get("text").split(" ")[1][1:])["data"]["chat"]["abs_object"]["object_guid"]
  								if not guid in admins :
  									bot.banGroupMember(target, guid)
  									# bot.sendMessage(target, "✅ کاربر با موفقیت از گروه اخراج شد", message_id=msg.get("message_id"))
  								else :
  									bot.sendMessage(target, "❌ کاربر ادمین میباشد", message_id=msg.get("message_id"))
  									
  							except IndexError:
  								bot.banGroupMember(target, bot.getMessagesInfo(target, [msg.get("reply_to_message_id")])[0]["author_object_guid"])
  								# bot.sendMessage(target, "✅ کاربر با موفقیت از گروه اخراج شد", message_id=msg.get("message_id"))
  							except:
  								bot.sendMessage(target, "❌ دستور اشتباه", message_id=msg.get("message_id"))
  								
  						elif msg.get("text").startswith("زمان"):
  							try:
  								response = get("https://api.codebazan.ir/time-date/?td=all").text
  								bot.sendMessage(target, response,message_id=msg.get("message_id"))
  							except:
  								print("err answer time")
  						
  						elif msg.get("text") == "!date":
  							try:
  								bot.sendMessage(target, f"Date: {time.localtime().tm_year} / {time.localtime().tm_mon} / {time.localtime().tm_mday}", message_id=msg.get("message_id"))
  							except:
  								print("err date")
  								
  						elif "forwarded_from" in msg.keys() and bot.getMessagesInfo(target, [msg.get("message_id")])[0]["forwarded_from"]["type_from"] == "Channel" and not msg.get("author_object_guid") in admins :
  							try:
  								print("Yek ahmagh forwared Zad")
  								bot.deleteMessages(target, [str(msg.get("message_id"))])
  								print("tabligh forearedi pak shod")
  							except:
  								print("err delete forwared")
  						
  						elif msg.get("text") == "قوانین":
  							try:
  								rules = open("rules.txt","r",encoding='utf-8').read()
  								bot.sendMessage(target, str(rules), message_id=msg.get("message_id"))
  							except:
  								print("err ghanon")
  							
  						elif msg.get("text").startswith("آپدیت قوانین") and msg.get("author_object_guid") in admins:
  							try:
  								rules = open("rules.txt","w",encoding='utf-8').write(str(msg.get("text").strip("آپدیت قوانین")))
  								bot.sendMessage(target, "✅  قوانین بروزرسانی شد", message_id=msg.get("message_id"))
  								# rules.close()
  							except:
  								bot.sendMessage(target, "❌ لطفا دستور را به درستی وارد کنید", message_id=msg.get("message_id"))
  
  						elif msg.get("text").startswith("اخطار") and msg.get("author_object_guid") in admins:
  							try:
  								user = msg.get("text").split(" ")[1][1:]
  								guid = bot.getInfoByUsername(user)["data"]["chat"]["abs_object"]["object_guid"]
  								if not guid in admins :
  									alert(guid,user)
  									
  								else :
  									bot.sendMessage(target, "❌ کاربر ادمین میباشد", message_id=msg.get("message_id"))
  									
  							except IndexError:
  								guid = bot.getMessagesInfo(target, [msg.get("reply_to_message_id")])[0]["author_object_guid"]
  								user = bot.getUserInfo(guid)["data"]["user"]["username"]
  								if not guid in admins:
  									alert(guid,user)
  								else:
  									bot.sendMessage(target, "❌ کاربر ادمین میباشد", message_id=msg.get("message_id"))
  							except:
  								bot.sendMessage(target, "❌ لطفا دستور را به درستی وارد کنید", message_id=msg.get("message_id"))
  
  				else:
  					if "forwarded_from" in msg.keys() and bot.getMessagesInfo(target, [msg.get("message_id")])[0]["forwarded_from"]["type_from"] == "Channel" and not msg.get("author_object_guid") in admins :
  						bot.deleteMessages(target, [msg.get("message_id")])
  						guid = msg.get("author_object_guid")
  						user = bot.getUserInfo(guid)["data"]["user"]["username"]
  						bot.deleteMessages(target, [msg.get("message_id")])
  						alert(guid,user,True)
  					
  					continue
  			except:
  				continue
  
  			answered.append(msg.get("message_id"))
  			print("[" + msg.get("message_id")+ "] >>> " + msg.get("text") + "\n")
  
  	except KeyboardInterrupt:
  		exit()
  
  	except Exception as e:
  		if type(e) in list(retries.keys()):
  			if retries[type(e)] < 3:
  				retries[type(e)] += 1
  				continue
  			else:
  				retries.pop(type(e))
  		else:
  			retries[type(e)] = 1
  			continue
  