حذف سفت و سخت تبلیغات

This commit is contained in:
2026-07-07 20:59:53 +03:30
parent 43e9d9a41d
commit e7de63c4bd
+45 -6
View File
@@ -27,7 +27,19 @@ bot = telebot.TeleBot(BOT_TOKEN, parse_mode=None)
if PLATFORM == "bale":
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 = {}
@@ -107,6 +119,29 @@ def guard(message):
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 ──────────────────────────────────────
@bot.message_handler(commands=["start"])
def start(message):
@@ -145,9 +180,11 @@ def welcome(message):
def handle_msg(message):
chat_id = message.chat.id
user_id = message.from_user.id
if not is_bot_admin(chat_id):
return
# بررسی سکوت
group = str(chat_id)
if group in muted_users and user_id in muted_users[group]:
try:
@@ -156,15 +193,17 @@ def handle_msg(message):
pass
return
text = message.text.lower() if message.text else ""
if any(re.search(p, text) for p in LINKS):
# بررسی تبلیغات
if is_promotional(message):
try:
bot.delete_message(chat_id, message.message_id)
bot.send_message(chat_id,
bot.send_message(
chat_id,
f"⚠️ پیام تبلیغاتی از {message.from_user.first_name} حذف شد"
)
except Exception:
pass
logger.info(f"🚫 تبلیغ حذف شد از {user_id} در گروه {chat_id}")
except Exception as e:
logger.error(f"❌ خطا در حذف تبلیغ: {e}")
# ── Kick ───────────────────────────────────────