Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added database/__pycache__/database.cpython-313.pyc
Binary file not shown.
47 changes: 47 additions & 0 deletions database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
user_data = database['users']
channels_collection = database["channels"]
encoded_links_collection = database["links"]
admins_collection = database['admins']
banned_users_collection = database['banned_users']

async def add_user(user_id: int):
existing_user = await user_data.find_one({'_id': user_id})
Expand All @@ -32,10 +34,55 @@ async def del_user(user_id: int):
await user_data.delete_one({'_id': user_id})

##-------------------------------------------------------------------
# Admin Management Functions

async def add_admin(user_id: int):
"""Add a user to admin list"""
existing_admin = await admins_collection.find_one({'_id': user_id})
if existing_admin:
return False
await admins_collection.insert_one({'_id': user_id})
return True

async def remove_admin(user_id: int):
"""Remove a user from admin list"""
result = await admins_collection.delete_one({'_id': user_id})
return result.deleted_count > 0

async def is_admin(user_id: int):
"""Check if a user is an admin"""
return bool(await admins_collection.find_one({'_id': user_id}))

async def get_all_admins():
"""Get list of all admin user IDs"""
admins = await admins_collection.find().to_list(None)
return [admin['_id'] for admin in admins]

##-------------------------------------------------------------------
# Ban System Functions

async def ban_user(user_id: int):
"""Add a user to banned list"""
existing_ban = await banned_users_collection.find_one({'_id': user_id})
if existing_ban:
return False
await banned_users_collection.insert_one({'_id': user_id, 'banned_at': datetime.now()})
return True

async def unban_user(user_id: int):
"""Remove a user from banned list"""
result = await banned_users_collection.delete_one({'_id': user_id})
return result.deleted_count > 0

async def is_banned(user_id: int):
"""Check if a user is banned"""
return bool(await banned_users_collection.find_one({'_id': user_id}))

async def get_all_banned():
"""Get list of all banned user IDs"""
banned = await banned_users_collection.find().to_list(None)
return [user['_id'] for user in banned]

##-------------------------------------------------------------------

async def save_channel(channel_id: int):
Expand Down
Binary file added plugins/__pycache__/admin.cpython-313.pyc
Binary file not shown.
Binary file added plugins/__pycache__/ban.cpython-313.pyc
Binary file not shown.
Binary file added plugins/__pycache__/newpost.cpython-313.pyc
Binary file not shown.
Binary file added plugins/__pycache__/start.cpython-313.pyc
Binary file not shown.
65 changes: 65 additions & 0 deletions plugins/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from pyrogram import Client as Bot, filters
from pyrogram.types import Message
from config import OWNER_ID
from database.database import add_admin, remove_admin, is_admin, get_all_admins

##----------------------------------------------------------------------------------------------------
# Admin Management Commands - Only OWNER can manage admins
##----------------------------------------------------------------------------------------------------

@Bot.on_message(filters.command('addadmin') & filters.private & filters.user(OWNER_ID))
async def add_admin_cmd(client: Bot, message: Message):
"""Add a user to admin list - Owner only"""
try:
user_id = int(message.command[1])
except (IndexError, ValueError):
return await message.reply("❌ Invalid format. Use: /addadmin <user_id>")

# Check if user is already owner
if user_id == OWNER_ID:
return await message.reply("⚠️ Owner ko admin banane ki zarurat nahi hai!")

# Try to add admin
success = await add_admin(user_id)
if success:
await message.reply(f"✅ User {user_id} ko admin bana diya gaya!")
else:
await message.reply(f"⚠️ User {user_id} pehle se hi admin hai!")

##----------------------------------------------------------------------------------------------------

@Bot.on_message(filters.command('deladmin') & filters.private & filters.user(OWNER_ID))
async def del_admin_cmd(client: Bot, message: Message):
"""Remove a user from admin list - Owner only"""
try:
user_id = int(message.command[1])
except (IndexError, ValueError):
return await message.reply("❌ Invalid format. Use: /deladmin <user_id>")

# Check if trying to remove owner
if user_id == OWNER_ID:
return await message.reply("⚠️ Owner ko admin se remove nahi kar sakte!")

# Try to remove admin
success = await remove_admin(user_id)
if success:
await message.reply(f"✅ User {user_id} ko admin se hata diya gaya!")
else:
await message.reply(f"⚠️ User {user_id} admin nahi hai!")

##----------------------------------------------------------------------------------------------------

@Bot.on_message(filters.command('admins') & filters.private & filters.user(OWNER_ID))
async def list_admins_cmd(client: Bot, message: Message):
"""List all admins - Owner only"""
admins = await get_all_admins()

if not admins:
return await message.reply("📋 Koi admin nahi hai.\n\n👑 Owner: {}\n\nUse /addadmin <user_id> to add admins.".format(OWNER_ID))

admin_list = "\n".join([f"• <code>{admin_id}</code>" for admin_id in admins])

response = f"<b>📋 Admin List:</b>\n\n{admin_list}\n\n<b>👑 Owner:</b> <code>{OWNER_ID}</code>\n\n<b>Total Admins:</b> {len(admins)}"
await message.reply(response)

##----------------------------------------------------------------------------------------------------
91 changes: 91 additions & 0 deletions plugins/ban.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
from pyrogram import Client as Bot, filters
from pyrogram.types import Message
from config import OWNER_ID
from database.database import ban_user, unban_user, is_banned, get_all_banned, is_admin

##----------------------------------------------------------------------------------------------------
# Ban System Commands - Owner and Admins can ban users
##----------------------------------------------------------------------------------------------------

async def is_owner_or_admin(user_id: int) -> bool:
"""Check if user is owner or admin"""
if user_id == OWNER_ID:
return True
return await is_admin(user_id)

##----------------------------------------------------------------------------------------------------

@Bot.on_message(filters.command('ban') & filters.private)
async def ban_user_cmd(client: Bot, message: Message):
"""Ban a user - Owner and Admins only"""
user_id = message.from_user.id

# Check permission
if not await is_owner_or_admin(user_id):
return await message.reply("⚠️ Sirf owner aur admins hi ban kar sakte hain!")

try:
target_user_id = int(message.command[1])
except (IndexError, ValueError):
return await message.reply("❌ Invalid format. Use: /ban <user_id>")

# Can't ban owner
if target_user_id == OWNER_ID:
return await message.reply("⚠️ Owner ko ban nahi kar sakte!")

# Can't ban admins (unless you're the owner)
if user_id != OWNER_ID and await is_admin(target_user_id):
return await message.reply("⚠️ Admins ko ban karne ke liye aap owner hone chahiye!")

# Try to ban user
success = await ban_user(target_user_id)
if success:
await message.reply(f"✅ User {target_user_id} ko ban kar diya gaya!\n\nAb ye user bot ka istemal nahi kar sakta.")
else:
await message.reply(f"⚠️ User {target_user_id} pehle se hi banned hai!")

##----------------------------------------------------------------------------------------------------

@Bot.on_message(filters.command('unban') & filters.private)
async def unban_user_cmd(client: Bot, message: Message):
"""Unban a user - Owner and Admins only"""
user_id = message.from_user.id

# Check permission
if not await is_owner_or_admin(user_id):
return await message.reply("⚠️ Sirf owner aur admins hi unban kar sakte hain!")

try:
target_user_id = int(message.command[1])
except (IndexError, ValueError):
return await message.reply("❌ Invalid format. Use: /unban <user_id>")

# Try to unban user
success = await unban_user(target_user_id)
if success:
await message.reply(f"✅ User {target_user_id} ko unban kar diya gaya!\n\nAb ye user bot ka istemal kar sakta hai.")
else:
await message.reply(f"⚠️ User {target_user_id} banned nahi hai!")

##----------------------------------------------------------------------------------------------------

@Bot.on_message(filters.command('banlist') & filters.private)
async def list_banned_cmd(client: Bot, message: Message):
"""List all banned users - Owner and Admins only"""
user_id = message.from_user.id

# Check permission
if not await is_owner_or_admin(user_id):
return await message.reply("⚠️ Sirf owner aur admins hi banlist dekh sakte hain!")

banned = await get_all_banned()

if not banned:
return await message.reply("📋 Koi bhi user banned nahi hai!")

banned_list = "\n".join([f"• <code>{banned_id}</code>" for banned_id in banned])

response = f"<b>🚫 Banned Users List:</b>\n\n{banned_list}\n\n<b>Total Banned:</b> {len(banned)}"
await message.reply(response)

##----------------------------------------------------------------------------------------------------
Loading