|
|
|
|
|
|
|
|
|
from pyrogram import * |
|
from pyrogram.types import * |
|
from pyrogram.errors import * |
|
from akn.utils.logger import LOGS |
|
from akn.utils.database import db |
|
|
|
@Client.on_message(filters.new_chat_members, group=2) |
|
async def welcomecheck(client, message: Message): |
|
chat_id = message.chat.id |
|
if await db.get_alldlbot_is_blacklist_chat(client.me.id, chat_id): |
|
return await client.leave_chat(chat_id) |
|
return await client.send_message( |
|
chat_id, |
|
f"Thank you for using my bot: {client.me.first_name}" |
|
) |
|
|
|
@Client.on_message( |
|
~filters.scheduled |
|
& filters.command(["addblacklist"]) |
|
& ~filters.forwarded |
|
) |
|
async def blacklist_user(c, m): |
|
is_sudo = await db.get_alldlbot_sudouser(c.me.id, m.from_user.id) |
|
protect_own = await db.get_alldlbot_by_user_id(m.from_user.id) |
|
if not protect_own and not is_sudo: |
|
return await m.reply_text("You are not allowed here.") |
|
|
|
if m.chat.type.value != "supergroup": |
|
return await m.reply_text("You can only group public not private") |
|
await db.update_alldlbot_broadcast_in_group(c.me.id, m.chat.id, "add") |
|
user_id = None |
|
if not m.reply_to_message: |
|
if len(m.command) < 2: |
|
return await m.reply_text( |
|
"Reply to a user or pass a user_id to blacklist" |
|
) |
|
try: |
|
getuser = m.command[1] |
|
except Exception as e: |
|
return await m.reply_text(f"`{str(e)}`") |
|
else: |
|
getuser = m.reply_to_message.from_user.id |
|
try: |
|
user_id = (await c.get_users(getuser)).id |
|
await db.add_alldlbot_blacklist_user(c.me.id, user_id) |
|
await m.reply_text(f"Successfully blacklist `{user_id}` from bots.") |
|
except Exception as e: |
|
await m.reply_text(f"Error: {e}") |
|
|
|
@Client.on_message( |
|
~filters.scheduled |
|
& filters.command(["rmblacklist"]) |
|
& ~filters.forwarded |
|
) |
|
async def unblacklist_user(c, m): |
|
is_sudo = await db.get_alldlbot_sudouser(c.me.id, m.from_user.id) |
|
protect_own = await db.get_alldlbot_by_user_id(m.from_user.id) |
|
if not protect_own and not is_sudo: |
|
return await m.reply_text("You are not allowed here.") |
|
|
|
if m.chat.type.value != "supergroup": |
|
return await m.reply_text("You can only group public not private") |
|
await db.update_alldlbot_broadcast_in_group(c.me.id, m.chat.id, "add") |
|
user_id = None |
|
if not m.reply_to_message: |
|
if len(m.command) < 2: |
|
return await m.reply_text( |
|
"Reply to a user or pass a user_id to unblacklist." |
|
) |
|
try: |
|
getuser = m.command[1] |
|
except Exception as e: |
|
return await m.reply_text(f"`{str(e)}`") |
|
else: |
|
getuser = m.reply_to_message.from_user.id |
|
try: |
|
user_id = (await c.get_users(getuser)).id |
|
await db.add_alldlbot_unblacklist_user(c.me.id, user_id) |
|
await m.reply_text(f"Successfully removed blacklist `{user_id}` from bots.") |
|
except Exception as e: |
|
await m.reply_text(f"Error: {e}") |
|
|
|
@Client.on_message( |
|
~filters.scheduled |
|
& filters.command(["addsudo"]) |
|
& ~filters.forwarded |
|
) |
|
async def add_sudo_func(client, message: Message): |
|
if message.chat.type.value != "supergroup": |
|
return await message.reply_text("This command can only be used in supergroups.") |
|
is_sudo = await db.get_alldlbot_sudouser(client.me.id, message.from_user.id) |
|
protect_own = await db.get_alldlbot_by_user_id(message.from_user.id) |
|
if not protect_own and not is_sudo: |
|
return await message.reply_text("You are not allowed here.") |
|
if len(message.command) != 2: |
|
return await message.reply_text("**Usage:**\n/addsudo [USER_ID]") |
|
user_id = int(message.text.strip().split()[1]) |
|
if await db.get_alldlbot_sudouser(client.me.id, user_id): |
|
return await message.reply_text("User is already sudo.") |
|
if user_id == client.me.id: |
|
return await message.reply_text("You can't add yourself as sudo.") |
|
update_sudo = await db.update_alldlbot_sudouser(client.me.id, user_id, "add") |
|
if update_sudo: |
|
await message.reply_text("User has been successfully added to sudo list") |
|
else: |
|
await message.reply_text("Something wrong happened.") |
|
|
|
@Client.on_message( |
|
~filters.scheduled |
|
& filters.command(["delsudo"]) |
|
& ~filters.forwarded |
|
) |
|
async def delc_sudo_func(client, message: Message): |
|
if message.chat.type.value != "supergroup": |
|
return await message.reply_text("This command can only be used in supergroups.") |
|
is_sudo = await db.get_alldlbot_sudouser(client.me.id, message.from_user.id) |
|
protect_own = await db.get_alldlbot_by_user_id(message.from_user.id) |
|
if not protect_own and not is_sudo: |
|
return await message.reply_text("You are not allowed here.") |
|
if len(message.command) != 2: |
|
return await message.reply_text("**Usage:**\n/delsudo [USER_ID]") |
|
user_id = int(message.text.strip().split()[1]) |
|
if not await db.get_alldlbot_sudouser(client.me.id, user_id): |
|
return await message.reply_text("User is not sudo.") |
|
if user_id == client.me.id: |
|
return await message.reply_text("You can't remove yourself as sudo.") |
|
update_sudo = await db.update_alldlbot_sudouser(client.me.id, user_id, "remove") |
|
if update_sudo: |
|
await message.reply_text("User has been successfully removed from sudo list") |
|
else: |
|
await message.reply_text("Something wrong happened.") |
|
|
|
@Client.on_message( |
|
~filters.scheduled |
|
& filters.command(["blacklistchat"]) |
|
& ~filters.forwarded |
|
) |
|
async def blacklist_chat_func(client, message: Message): |
|
if message.chat.type.value != "supergroup": |
|
return await message.reply_text("This command can only be used in supergroups.") |
|
is_sudo = await db.get_alldlbot_sudouser(client.me.id, message.from_user.id) |
|
protect_own = await db.get_alldlbot_by_user_id(message.from_user.id) |
|
if not protect_own and not is_sudo: |
|
return await message.reply_text("You are not allowed here.") |
|
if len(message.command) != 2: |
|
return await message.reply_text("**Usage:**\n/blacklistchat [CHAT_ID]") |
|
chat_id = int(message.text.strip().split()[1]) |
|
if await db.get_alldlbot_is_blacklist_chat(client.me.id, chat_id): |
|
return await message.reply_text("Chat is already blacklisted.") |
|
blacklisted = await db.add_alldlbot_blacklist_chat(client.me.id, chat_id) |
|
if blacklisted: |
|
await message.reply_text("Chat has been successfully blacklisted") |
|
else: |
|
await message.reply_text("Something wrong happened.") |
|
try: |
|
await client.leave_chat(chat_id) |
|
except: |
|
pass |
|
|
|
@Client.on_message( |
|
~filters.scheduled |
|
& filters.command(["whitelistchat"]) |
|
& ~filters.forwarded |
|
) |
|
async def white_funciton(client, message: Message): |
|
if message.chat.type.value != "supergroup": |
|
return await message.reply_text("This command can only be used in supergroups.") |
|
is_sudo = await db.get_alldlbot_sudouser(client.me.id, message.from_user.id) |
|
protect_own = await db.get_alldlbot_by_user_id(message.from_user.id) |
|
if not protect_own and not is_sudo: |
|
return await message.reply_text("You are not allowed here.") |
|
if len(message.command) != 2: |
|
return await message.reply_text("**Usage:**\n/whitelistchat [CHAT_ID]") |
|
chat_id = int(message.text.strip().split()[1]) |
|
if not await db.get_alldlbot_is_blacklist_chat(client.me.id, chat_id): |
|
return await message.reply_text("Chat is already whitelisted") |
|
whitelisted = await db.alldlbot_whitelist_chat(client.me.id, chat_id) |
|
if whitelisted: |
|
return await message.reply_text("Chat has been successfully whitelisted") |
|
await message.reply_text("Something wrong happened.") |
|
|
|
@Client.on_message( |
|
~filters.scheduled |
|
& filters.command(["blacklistedchat"]) |
|
& ~filters.forwarded |
|
) |
|
async def all_chats(client, message: Message): |
|
if message.chat.type.value != "supergroup": |
|
return await message.reply_text("This command can only be used in supergroups.") |
|
is_sudo = await db.get_alldlbot_sudouser(client.me.id, message.from_user.id) |
|
protect_own = await db.get_alldlbot_by_user_id(message.from_user.id) |
|
if not protect_own and not is_sudo: |
|
return await message.reply_text("You are not allowed here.") |
|
text = "**Blacklisted Chats:**\n\n" |
|
j = 0 |
|
for count, chat_id in enumerate(await db.get_alldlbot_blacklist_chat(client.me.id), 1): |
|
try: |
|
title = (await client.get_chat(chat_id)).title |
|
except Exception: |
|
title = "Private" |
|
j = 1 |
|
text += f"**{count}. {title}** [`{chat_id}`]\n" |
|
if j == 0: |
|
await message.reply_text("No Blacklisted Chats") |
|
else: |
|
await message.reply_text(text) |
|
|
|
@Client.on_message( |
|
~filters.scheduled |
|
& filters.command(["listsudo"]) |
|
& ~filters.forwarded |
|
) |
|
async def list_sudo_func(client, message: Message): |
|
if message.chat.type.value != "supergroup": |
|
return await message.reply_text("This command can only be used in supergroups.") |
|
is_sudo = await db.get_alldlbot_sudouser(client.me.id, message.from_user.id) |
|
protect_own = await db.get_alldlbot_by_user_id(message.from_user.id) |
|
if not protect_own and not is_sudo: |
|
return await message.reply_text("You are not allowed here.") |
|
text = "**List SudoUser:**\n\n" |
|
j = 0 |
|
for count, user_id in enumerate(await db.get_alldlbot_allsudouser(client.me.id), 1): |
|
try: |
|
title = (await client.get_users(user_id)).first_name |
|
except Exception: |
|
title = "Private" |
|
j = 1 |
|
text += f"**{count}. {title}** [`{user_id}`]\n" |
|
if j == 0: |
|
await message.reply_text("No List SudoUser") |
|
else: |
|
await message.reply_text(text) |
|
|
|
@Client.on_message( |
|
~filters.scheduled |
|
& filters.command(["viewblacklistuser"]) |
|
& ~filters.forwarded |
|
) |
|
async def view_blacklist_user_func(client, message: Message): |
|
if message.chat.type.value != "supergroup": |
|
return await message.reply_text("This command can only be used in supergroups.") |
|
is_sudo = await db.get_alldlbot_sudouser(client.me.id, message.from_user.id) |
|
protect_own = await db.get_alldlbot_by_user_id(message.from_user.id) |
|
if not protect_own and not is_sudo: |
|
return await message.reply_text("You are not allowed here.") |
|
text = "**Blacklisted Users:**\n\n" |
|
j = 0 |
|
for count, user_id in enumerate(await db.get_alldlbot_allblacklist_user(client.me.id), 1): |
|
try: |
|
title = (await client.get_users(user_id)).first_name |
|
except Exception: |
|
title = "Private" |
|
j = 1 |
|
text += f"**{count}. {title}** [`{user_id}`]\n" |
|
if j == 0: |
|
await message.reply_text("No Blacklisted Users") |
|
else: |
|
await message.reply_text(text) |