Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import requests
- import json
- import telebot
- import random
- from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
- from telebot import types
- from datetime import datetime
- import re
- API_TOKEN = 'YOUR_BOTU'
- bot = telebot.TeleBot(API_TOKEN)
- banned_users = set()
- admins = set([5541407305]) # ضع معرف الأدمن هنا
- users = {}
- broadcast_list = []
- mandatory_channels = set() # مجموعة تحتوي على قنوات الاشتراك الإجباري
- def botusername():
- user = bot.get_me().username
- if user.startswith('@'):
- user = user[1:]
- return user
- try:
- bu = botusername()
- except Exception as e:
- print('error in botusername', e)
- @bot.message_handler(commands=['start'])
- def start(message):
- try:
- if message.chat.type == 'private':
- if message.from_user.id in banned_users:
- bot.send_message(message.chat.id, "أنت محظور من استخدام هذا البوت❎.")
- return
- if message.from_user.id not in users:
- users[message.from_user.id] = {"username": message.from_user.username, "joined": datetime.now()}
- broadcast_list.append(message.from_user.id)
- if mandatory_channels and not check_mandatory_subscription(message.from_user.id):
- return
- if message.from_user.id in admins:
- bot.send_message(message.chat.id, "مرحبًا بك في لوحة التحكم", reply_markup=get_admin_menu())
- else:
- C4_ = types.InlineKeyboardMarkup()
- C4_.row_width = 2
- AIM = types.InlineKeyboardButton(text="ضيفني لـ قناتك ", url=f"https://t.me/{bu}?startchannel")
- X = types.InlineKeyboardButton(text="المالك", url=f"https://t.me/HN_0K")
- HLTV = types.InlineKeyboardButton(text="ضيفني لـ مجموعتك", url=f"https://t.me/{bu}?startgroup")
- C4_.add(AIM, X, HLTV)
- name_of_C4 = f"{message.from_user.first_name}"
- text = f'''•مرحبا عزيزي {name_of_C4}, أنا بوت تفاعل برموز تعبيرية متعددة يمكنك إضافتي إلى مجموعة أو قناة للتفاعل•'''
- bot.send_message(message.chat.id, text, reply_markup=C4_, parse_mode='Markdown')
- except Exception as e:
- print('error in start', e)
- @bot.channel_post_handler()
- def react_to_channel_message(message):
- print('channel_post_handler')
- try:
- reactions = ["👍", "❤️", "🔥", "🥰", "👏", "😁", "❤️🔥", "🤯", " 😘", "🤤", "😎", "🥹", "🗿", "😐" "🫡", "👀", "👨🏼💻", "😭", "🤩", "💯", "🌚", "👾", "🐳" "🥲" "💔" "" "😂" "👻" "⚡" "🤣" "🤔" "😇" "😴" "😨" "😱" "🤗" "🙏🏼" "👌🏼" "🎉" "⚡" "🕊️" "🙈" "😈" "💋" "👨🏼💻" "🤷🏼♂️" "🐳" "🤡" "🥴" "🥱" "🍓" "🏆" "😐" "🤨" "🤬" "🤓" "💘" "🎅🏼" "🆒"]
- emoji = random.choice(reactions)
- send_message_react({
- 'chat_id': message.chat.id,
- 'message_id': message.message_id,
- 'reaction': [{'type': "emoji", "emoji": emoji}]
- })
- except Exception as e:
- print('error in react_to_channel_message', e)
- @bot.message_handler(func=lambda message: True)
- def react_to_message(message):
- print('message_handler')
- try:
- reactions = ["👍", "❤️", "🔥", "🥰", "👏", "😁", "❤️🔥", "🤯", " 😘", "🤤", "😎", "🥹", "🗿", "😐" "🫡", "👀", "👨🏼💻", "😭", "🤩", "💯", "🌚", "👾", "🐳" "🥲" "💔" "" "😂" "👻" "⚡" "🤣" "🤔" "😇" "😴" "😨" "😱" "🤗" "🙏🏼" "👌🏼" "🎉" "⚡" "🕊️" "🙈" "😈" "💋" "👨🏼💻" "🤷🏼♂️" "🐳" "🤡" "🥴" "🥱" "🍓" "🏆" "😐" "🤨" "🤬" "🤓" "💘" "🎅🏼" "🆒"]
- emoji = random.choice(reactions)
- send_message_react({
- 'chat_id': message.chat.id,
- 'message_id': message.message_id,
- 'reaction': [{'type': "emoji", "emoji": emoji}]
- })
- except Exception as e:
- print('error in react_to_message', e)
- def send_message_react(datas={}):
- try:
- url = "https://api.telegram.org/bot" + API_TOKEN + "/" + 'setMessageReaction'
- response = requests.post(url, json=datas)
- if response.status_code != 200:
- return "Error: " + response.text
- else:
- return response.json()
- except Exception as e:
- print('error in send_message_react', e)
- # لوحة التحكم للأدمن
- def get_statistics():
- total_users = len(users)
- last_users = list(users.keys())[-10:]
- last_users_str = "\n".join([f"@{users[user_id]['username']}" for user_id in last_users if users[user_id]['username']])
- total_admins = len(admins)
- admins_str = "\n".join([f"{i+1}- @{bot.get_chat(admin).username}" for i, admin in enumerate(admins)])
- total_banned = len(banned_users)
- banned_users_str = "\n".join([f"{i+1}- @{bot.get_chat(banned).username}" for i, banned in enumerate(banned_users)])
- total_channels = len(mandatory_channels)
- channels_str = "\n".join([f"{i+1}- @{bot.get_chat(channel).username}" for i, channel in enumerate(mandatory_channels)])
- stats_message = (
- f"👥 عدد المستخدمين: {total_users}\n\n"
- f"📋 آخر 10 مستخدمين:\n{last_users_str if last_users_str else 'لا يوجد'}\n\n"
- f"🔧 عدد الأدمنية: {total_admins}\n{admins_str if admins_str else 'لا يوجد'}\n\n"
- f"🚫 عدد المحظورين: {total_banned}\n{banned_users_str if banned_users_str else 'لا يوجد'}\n\n"
- f"📡 عدد قنوات الاشتراك الإجباري: {total_channels}\n{channels_str if channels_str else 'لا يوجد'}"
- )
- return stats_message
- def broadcast_message(message):
- for user_id in broadcast_list:
- try:
- bot.send_message(user_id, message)
- except:
- pass
- def get_admin_menu():
- markup = types.InlineKeyboardMarkup()
- markup.add(types.InlineKeyboardButton("👥 إدارة المستخدمين", callback_data="manage_users"))
- markup.add(types.InlineKeyboardButton("📊 الإحصائيات", callback_data="statistics"))
- markup.add(types.InlineKeyboardButton("📢 الإذاعة", callback_data="broadcast"))
- markup.add(types.InlineKeyboardButton("📎 إعداد قناة الاشتراك الإجباري", callback_data="set_channel_options"))
- return markup
- def get_manage_users_menu():
- markup = types.InlineKeyboardMarkup()
- markup.add(types.InlineKeyboardButton("➕ رفع أدمن", callback_data="add_admin"))
- markup.add(types.InlineKeyboardButton("➖ إزالة أدمن", callback_data="remove_admin"))
- markup.add(types.InlineKeyboardButton("🚫 حظر مستخدم", callback_data="ban_user"))
- markup.add(types.InlineKeyboardButton("🔓 فك حظر مستخدم", callback_data="unban_user"))
- markup.add(types.InlineKeyboardButton("📋 عرض الأدمنية", callback_data="show_admins"))
- markup.add(types.InlineKeyboardButton("📋 عرض المستخدمين المحظورين", callback_data="show_banned_users"))
- return markup
- def get_mandatory_subscription_menu():
- markup = types.InlineKeyboardMarkup()
- markup.add(types.InlineKeyboardButton("➕ إضافة قناة اشتراك إجباري", callback_data="add_channel"))
- markup.add(types.InlineKeyboardButton("➖ حذف قناة من الاشتراك الإجباري", callback_data="remove_channel"))
- markup.add(types.InlineKeyboardButton("📋 عرض قنوات الاشتراك الإجباري", callback_data="show_channels"))
- return markup
- def get_channel_name(channel_username):
- try:
- channel_info = bot.get_chat(channel_username)
- return channel_info.title # إعادة اسم القناة
- except telebot.apihelper.ApiException as e:
- print(f"Error fetching channel name: {e}")
- return None
- # دالة للتحقق من الاشتراك الإجباري
- def check_mandatory_subscription(user_id):
- for channel in mandatory_channels:
- try:
- status = bot.get_chat_member(channel, user_id).status
- if status in ['left', 'kicked']:
- # الحصول على اسم القناة باستخدام الدالة
- channel_name = get_channel_name(channel)
- if channel_name is None:
- bot.send_message(user_id, "حدث خطأ في جلب معلومات القناة. يرجى المحاولة لاحقًا.")
- return False
- # إنشاء زر ينقل المستخدم إلى القناة
- markup = InlineKeyboardMarkup()
- channel_button = InlineKeyboardButton(f"{channel_name}", url=f"https://t.me/{channel.replace('@', '')}")
- markup.add(channel_button)
- # رسالة الاشتراك
- bot.send_message(user_id, f'''يجب ان تشترك في القناة
- اشترك ثم ارسل /start''', reply_markup=markup)
- return False
- except telebot.apihelper.ApiException as e:
- print(f"Error checking subscription: {e}")
- bot.send_message(user_id, "حدث خطأ يرجى المحاولة لاحقًا وشكرًا 🤍.")
- return False
- return True
- @bot.callback_query_handler(func=lambda call: True)
- def callback_query(call):
- user_id = call.from_user.id
- if user_id in banned_users:
- bot.send_message(user_id, "أنت محظور من استخدام هذا البوت❎.")
- return
- if call.data == "manage_users":
- if user_id in admins:
- bot.send_message(user_id, "إدارة المستخدمين", reply_markup=get_manage_users_menu())
- elif call.data == "ban_user":
- if user_id in admins:
- msg = bot.send_message(user_id, "أرسل معرف المستخدم لحظره🌠:")
- bot.register_next_step_handler(msg, ban_user)
- elif call.data == "unban_user":
- if user_id in admins:
- msg = bot.send_message(user_id, "أرسل معرف المستخدم لفك الحظر عنه🤍:")
- bot.register_next_step_handler(msg, unban_user)
- elif call.data == "unban_user":
- if user_id in admins:
- msg = bot.send_message(user_id, "أرسل معرف المستخدم لفك الحظر عنه🤍:")
- bot.register_next_step_handler(msg, unban_user)
- elif call.data == "add_admin":
- if user_id in admins:
- msg = bot.send_message(user_id, "أرسل معرف أو ID المستخدم لإضافته كأدمن⚡:")
- bot.register_next_step_handler(msg, add_admin)
- elif call.data == "remove_admin":
- if user_id in admins:
- msg = bot.send_message(user_id, "أرسل معرف أو ID المستخدم لحذفه من الأدمن🙂:")
- bot.register_next_step_handler(msg, remove_admin)
- elif call.data == "statistics":
- if user_id in admins:
- stats = get_statistics()
- bot.send_message(user_id, stats)
- elif call.data == "broadcast":
- if user_id in admins:
- msg = bot.send_message(user_id, "أرسل الرسالة التي تريد إرسالها لجميع المستخدمين✅:")
- bot.register_next_step_handler(msg, send_broadcast)
- elif call.data == "set_channel_options":
- if user_id in admins:
- bot.send_message(user_id, "خيارات قناة الاشتراك الإجباري🤍", reply_markup=get_mandatory_subscription_menu())
- elif call.data == "add_channel":
- if user_id in admins:
- msg = bot.send_message(user_id, "أرسل معرف أو رابط القناة لإضافتها كقناة اشتراك إجباري🚸:")
- bot.register_next_step_handler(msg, add_mandatory_channel)
- elif call.data == "remove_channel":
- if user_id in admins:
- msg = bot.send_message(user_id, "أرسل معرف أو رابط القناة التي تريد حذفها من الاشتراك الإجباري🤍:")
- bot.register_next_step_handler(msg, remove_mandatory_channel)
- elif call.data == "show_channels":
- if user_id in admins:
- show_mandatory_channels(user_id)
- elif call.data == "show_admins":
- if user_id in admins:
- show_admins(user_id)
- elif call.data == "show_banned_users":
- if user_id in admins:
- show_banned_users(user_id)
- def extract_channel_id(text):
- if text.startswith('@'):
- return text
- elif 't.me/' in text:
- match = re.search(r"t\.me/(.+)", text)
- if match:
- return '@' + match.group(1)
- return None
- def add_mandatory_channel(message):
- channel_id = extract_channel_id(message.text)
- if channel_id:
- try:
- channel_info = bot.get_chat(channel_id)
- member_status = bot.get_chat_member(channel_id, bot.get_me().id).status
- if member_status in ['administrator', 'creator']:
- mandatory_channels.add(channel_id)
- bot.send_message(message.chat.id, f"تم إضافة القناة {channel_id} إلى الاشتراك الإجباري ✅")
- else:
- bot.send_message(message.chat.id, "البوت ليس أدمن في القناة ❎")
- except telebot.apihelper.ApiException as e:
- if 'chat not found' in str(e):
- bot.send_message(message.chat.id, "عذرًا، القناة التي أرسلتها غير موجودة ❎")
- else:
- bot.send_message(message.chat.id, "حدث خطأ أو البوت ليس أدمن في القناة 🤍.")
- else:
- bot.send_message(message.chat.id, "يرجى إدخال معرف أو رابط قناة صالح.")
- def remove_mandatory_channel(message):
- channel_id = extract_channel_id(message.text)
- if channel_id and channel_id in mandatory_channels:
- mandatory_channels.remove(channel_id)
- bot.send_message(message.chat.id, f"تم حذف القناة {channel_id} من الاشتراك الإجباري ✅")
- else:
- bot.send_message(message.chat.id, "القناة غير موجودة في قائمة الاشتراك الإجباري 🚸")
- def show_mandatory_channels(user_id):
- if mandatory_channels:
- channels_list = "\n".join(mandatory_channels)
- bot.send_message(user_id, f"القنوات المضافة للاشتراك الإجباري:\n{channels_list}")
- else:
- bot.send_message(user_id, "لا توجد قنوات مضافة للاشتراك الإجباري.")
- def show_admins(user_id):
- if admins:
- admins_list = "\n".join([str(admin) for admin in admins])
- bot.send_message(user_id, f"الأدمنية في النظام:\n{admins_list}")
- else:
- bot.send_message(user_id, "لا يوجد أدمنية في النظام.")
- def show_banned_users(user_id):
- if banned_users:
- banned_list = "\n".join([str(user) for user in banned_users])
- bot.send_message(user_id, f"المستخدمين المحظورين:\n{banned_list}")
- else:
- bot.send_message(user_id, "لا يوجد مستخدمين محظورين.")
- def ban_user(message):
- try:
- user_id_to_ban = int(message.text)
- if user_id_to_ban not in banned_users:
- banned_users.add(user_id_to_ban)
- bot.send_message(message.chat.id, f"تم حظر المستخدم: {user_id_to_ban}")
- else:
- bot.send_message(message.chat.id, "المستخدم محظور بالفعل.")
- except ValueError:
- bot.send_message(message.chat.id, "يرجى إدخال معرف مستخدم صالح.")
- def unban_user(message):
- try:
- user_id_to_unban = int(message.text)
- if user_id_to_unban in banned_users:
- banned_users.discard(user_id_to_unban)
- bot.send_message(message.chat.id, f"تم فك الحظر عن المستخدم: {user_id_to_unban}")
- else:
- bot.send_message(message.chat.id, "المستخدم ليس محظوراً.")
- except ValueError:
- bot.send_message(message.chat.id, "يرجى إدخال معرف مستخدم صالح.")
- def add_admin(message):
- try:
- new_admin = message.text
- if new_admin.startswith('@'):
- new_admin_id = bot.get_chat(new_admin).id
- else:
- new_admin_id = int(new_admin)
- if new_admin_id not in admins:
- admins.add(new_admin_id)
- bot.send_message(message.chat.id, f"تمت إضافة الأدمن: {new_admin_id}")
- else:
- bot.send_message(message.chat.id, "المستخدم هو بالفعل أدمن.")
- except (ValueError, telebot.apihelper.ApiException):
- bot.send_message(message.chat.id, "يرجى إدخال معرف أو ID صالح.")
- def remove_admin(message):
- try:
- admin_to_remove = message.text
- if admin_to_remove.startswith('@'):
- admin_id_to_remove = bot.get_chat(admin_to_remove).id
- else:
- admin_id_to_remove = int(admin_to_remove)
- if admin_id_to_remove in admins:
- admins.discard(admin_id_to_remove)
- bot.send_message(message.chat.id, f"تم حذف الأدمن: {admin_id_to_remove}")
- else:
- bot.send_message(message.chat.id, "المستخدم ليس أدمن.")
- except (ValueError, telebot.apihelper.ApiException):
- bot.send_message(message.chat.id, "يرجى إدخال معرف أو ID صالح.")
- def send_broadcast(message):
- broadcast_message(message.text)
- bot.send_message(message.chat.id, "تم إرسال الرسالة بنجاح!")
- print('running...')
- #مكتبه لازم تكون موجوده 👇🏻
- import time
- # الكود مال حل مشكله قطعله البوت 🌚 👇🏻
- while True:
- try:
- bot.polling(none_stop=True)
- except Exception as e:
- print(f"حدث خطأ")
- #المده 15 ثانيه عوفها احسن مده هاي لاتغير بيها 🌚
- time.sleep(15)
- # وبس بوتك راح يشتغل
Advertisement
Add Comment
Please, Sign In to add comment