| import os |
| import telebot |
| from telebot import types |
| import time |
|
|
| BOT_TOKEN = "8019494761:AAF18VXTr7hg3-lK3qTnRtPOicybhe5pssk" |
| ADMIN_ID = 8109723300 |
|
|
| bot = telebot.TeleBot(BOT_TOKEN) |
| blocked_users = set() |
| spam_tracker = {} |
| forwarded = {} |
|
|
| @bot.message_handler(commands=['start']) |
| def start(message): |
| if message.chat.id == ADMIN_ID: |
| bot.reply_to(message, "β
Admin mode FULL ON\nSpam detect + Block/Unblock + Multiple replies ON!") |
| else: |
| bot.reply_to(message, "π© Koi bhi message bhejo!") |
|
|
| @bot.message_handler(commands=['blocked']) |
| def show_blocked(message): |
| if message.chat.id != ADMIN_ID: |
| return |
| if not blocked_users: |
| bot.reply_to(message, "Koi blocked user nahi hai.") |
| else: |
| text = "π« Blocked Users:\n" + "\n".join([str(uid) for uid in blocked_users]) |
| bot.reply_to(message, text) |
|
|
| @bot.message_handler(commands=['unblock']) |
| def unblock(message): |
| if message.chat.id != ADMIN_ID: |
| return |
| try: |
| uid = int(message.text.split()[1]) |
| if uid in blocked_users: |
| blocked_users.remove(uid) |
| bot.reply_to(message, f"β
User {uid} unblocked!") |
| else: |
| bot.reply_to(message, "Ye user already unblocked hai.") |
| except: |
| bot.reply_to(message, "Use: /unblock 123456789") |
|
|
| @bot.message_handler(func=lambda m: True, content_types=['text','photo','video','document','audio','voice','sticker','animation','video_note']) |
| def handle_all(message): |
| user_id = message.from_user.id |
| if user_id in blocked_users: |
| return |
|
|
| |
| now = time.time() |
| if user_id not in spam_tracker: |
| spam_tracker[user_id] = [] |
| spam_tracker[user_id].append(now) |
| |
| spam_tracker[user_id] = [t for t in spam_tracker[user_id] if now - t <= 3] |
| |
| show_block = len(spam_tracker[user_id]) >= 5 |
|
|
| if user_id == ADMIN_ID: |
| |
| if message.reply_to_message and message.reply_to_message.message_id in forwarded: |
| target = forwarded[message.reply_to_message.message_id] |
| try: |
| bot.copy_message(target, ADMIN_ID, message.message_id) |
| bot.reply_to(message, "β
Reply bhej diya!") |
| except: |
| bot.reply_to(message, "β User ne bot block kiya.") |
| else: |
| bot.reply_to(message, "π Kisi buyer ke message ko reply karke jawab do.") |
| else: |
| |
| name = message.from_user.first_name or "Unknown" |
| username = "@" + (message.from_user.username or "NoUsername") |
| info = f"π **Buyer Info**\nName: {name}\nUsername: {username}\nID: {user_id}\n\n" |
|
|
| markup = types.InlineKeyboardMarkup() |
| if show_block: |
| markup.add(types.InlineKeyboardButton("π« Block this Buyer", callback_data=f"block_{user_id}")) |
|
|
| if message.content_type == 'text': |
| sent = bot.send_message(ADMIN_ID, info + message.text, reply_markup=markup, parse_mode="Markdown") |
| else: |
| sent = bot.copy_message(ADMIN_ID, message.chat.id, message.message_id, |
| caption=info + (message.caption or ""), reply_markup=markup) |
|
|
| forwarded[sent.message_id] = user_id |
| bot.reply_to(message, "β
Message admin tak pahunch gaya!") |
|
|
| @bot.callback_query_handler(func=lambda call: True) |
| def handle_block(call): |
| if call.data.startswith("block_"): |
| uid = int(call.data.split("_")[1]) |
| blocked_users.add(uid) |
| bot.answer_callback_query(call.id, f"User {uid} blocked β
") |
| bot.send_message(ADMIN_ID, f"π« Buyer {uid} permanently blocked!") |
|
|
| print("π€ Advanced Anti-Spam Bot ON β
\n5 msg in 3 sec = Block button | /unblock ID | /blocked list") |
| bot.infinity_polling() |