حذف سفت و سخت تبلیغات
This commit is contained in:
@@ -27,7 +27,19 @@ bot = telebot.TeleBot(BOT_TOKEN, parse_mode=None)
|
|||||||
if PLATFORM == "bale":
|
if PLATFORM == "bale":
|
||||||
telebot.apihelper.API_URL = "https://tapi.bale.ai/bot{0}/{1}"
|
telebot.apihelper.API_URL = "https://tapi.bale.ai/bot{0}/{1}"
|
||||||
|
|
||||||
LINKS = [r"t\.me/", r"telegram\.me/", r"ble\.ir/"]
|
LINKS = [
|
||||||
|
r'https?://[^\s]+|www\.[^\s]+|[a-zA-Z0-9-]+\.[a-zA-Z]{2,}(?:/\S*)?'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
GROUP_ID_PATTERNS = [
|
||||||
|
r"@[a-zA-Z0-9_]{5,}", # @username با حداقل ۵ کاراکتر
|
||||||
|
r"id:\s*\d{5,}", # id: 123456789
|
||||||
|
r"آیدی:\s*\d{5,}", # آیدی: 123456789
|
||||||
|
r"شناسه:\s*\d{5,}", # شناسه: 123456789
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
muted_users = {}
|
muted_users = {}
|
||||||
|
|
||||||
|
|
||||||
@@ -107,6 +119,29 @@ def guard(message):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def is_promotional(message):
|
||||||
|
text = message.text.lower() if message.text else ""
|
||||||
|
|
||||||
|
# ۱. بررسی لینکها
|
||||||
|
if any(re.search(p, text) for p in LINKS):
|
||||||
|
return True
|
||||||
|
|
||||||
|
# ۲. بررسی آیدی گروه
|
||||||
|
if any(re.search(p, text) for p in GROUP_ID_PATTERNS):
|
||||||
|
return True
|
||||||
|
|
||||||
|
# ۳. بررسی پیام فورواردی
|
||||||
|
if message.forward_from or message.forward_from_chat:
|
||||||
|
return True
|
||||||
|
|
||||||
|
# ۴. بررسی فوروارد از کانال (با لینک)
|
||||||
|
if message.forward_from_chat and message.forward_from_chat.username:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ── Start ──────────────────────────────────────
|
# ── Start ──────────────────────────────────────
|
||||||
@bot.message_handler(commands=["start"])
|
@bot.message_handler(commands=["start"])
|
||||||
def start(message):
|
def start(message):
|
||||||
@@ -145,9 +180,11 @@ def welcome(message):
|
|||||||
def handle_msg(message):
|
def handle_msg(message):
|
||||||
chat_id = message.chat.id
|
chat_id = message.chat.id
|
||||||
user_id = message.from_user.id
|
user_id = message.from_user.id
|
||||||
|
|
||||||
if not is_bot_admin(chat_id):
|
if not is_bot_admin(chat_id):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# بررسی سکوت
|
||||||
group = str(chat_id)
|
group = str(chat_id)
|
||||||
if group in muted_users and user_id in muted_users[group]:
|
if group in muted_users and user_id in muted_users[group]:
|
||||||
try:
|
try:
|
||||||
@@ -156,15 +193,17 @@ def handle_msg(message):
|
|||||||
pass
|
pass
|
||||||
return
|
return
|
||||||
|
|
||||||
text = message.text.lower() if message.text else ""
|
# بررسی تبلیغات
|
||||||
if any(re.search(p, text) for p in LINKS):
|
if is_promotional(message):
|
||||||
try:
|
try:
|
||||||
bot.delete_message(chat_id, message.message_id)
|
bot.delete_message(chat_id, message.message_id)
|
||||||
bot.send_message(chat_id,
|
bot.send_message(
|
||||||
|
chat_id,
|
||||||
f"⚠️ پیام تبلیغاتی از {message.from_user.first_name} حذف شد"
|
f"⚠️ پیام تبلیغاتی از {message.from_user.first_name} حذف شد"
|
||||||
)
|
)
|
||||||
except Exception:
|
logger.info(f"🚫 تبلیغ حذف شد از {user_id} در گروه {chat_id}")
|
||||||
pass
|
except Exception as e:
|
||||||
|
logger.error(f"❌ خطا در حذف تبلیغ: {e}")
|
||||||
|
|
||||||
|
|
||||||
# ── Kick ───────────────────────────────────────
|
# ── Kick ───────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user