Ufoptg's picture
Upload 93 files
78b07ad verified
raw
history blame
12 kB
import random
from pyrogram import Client, filters
from pyrogram.enums import ChatType
from pyrogram.types import Message
from Hellbot.core import ENV
from . import Config, HelpMenu, Symbols, custom_handler, db, hellbot, on_message
blocked_messages = [
"๐Ÿค User has entered the silent zone.",
"๐Ÿ‘ป Message blocked. Ghost mode activated.",
"๐Ÿ–๏ธ Sorry, the user is on vacation in Blockland.",
"๐Ÿšซ Message blocked. Time for a digital forcefield.",
"๐Ÿšท User temporarily ejected from my DM.",
"๐ŸŒ‘ Blocking vibes only. Silence in progress.",
"๐Ÿ”‡ Shhh... message blocked for tranquility.",
"๐Ÿšท Access denied. User in the digital timeout corner.",
"โ›” User temporarily MIA from the conversation.",
"๐Ÿ”’ Message blocked. Secret mission engaged.",
]
unblocked_messages = [
"๐ŸŽ‰ Welcome back! Digital barrier lifted.",
"๐ŸŒŠ Unblocked! Get ready for a flood of messages.",
"๐Ÿ—๏ธ User released from message jail. Freedom at last!",
"๐Ÿ”“ Breaking the silence!.",
"๐Ÿ“ฌ User back on the radar. Messages unlocked!",
"๐Ÿš€ Soaring back into the conversation!",
"๐ŸŒ Reconnecting user to the chat matrix.",
"๐Ÿ“ˆ Unblocking for an influx of communication!",
"๐Ÿš€ Launching user back into the message cosmos!",
"๐ŸŽ™๏ธ Unblocked and ready for the conversation spotlight!",
]
WARNS = {}
PREV_MESSAGE = {}
@on_message("block", allow_stan=True)
async def block_user(client: Client, message: Message):
if len(message.command) > 1:
try:
user = await client.get_users(message.command[1])
except Exception as e:
return await hellbot.error(message, f"`{e}`")
elif message.chat.type == ChatType.PRIVATE:
user = message.chat
elif message.reply_to_message:
user = message.reply_to_message.from_user
else:
return await hellbot.delete(
message, "`Reply to a user or give their id/username`"
)
if user.id == client.me.id:
return await hellbot.delete(message, "`I can't block myself`")
if user.id in Config.DEVS:
return await hellbot.delete(message, "`I can't block my devs`")
success = await client.block_user(user.id)
if success:
await hellbot.delete(
message,
f"**{random.choice(blocked_messages)}\n\n{Symbols.cross_mark} Blocked:** {user.mention}",
)
else:
await hellbot.error(message, f"`Couldn't block {user.mention}`")
@on_message("unblock", allow_stan=True)
async def unblock_user(client: Client, message: Message):
if len(message.command) > 1:
try:
user = await client.get_users(message.command[1])
except Exception as e:
return await hellbot.error(message, f"`{e}`")
elif message.reply_to_message:
user = message.reply_to_message.from_user
else:
return await hellbot.delete(
message, "`Reply to a user or give their id/username`"
)
if user.id == client.me.id:
return await hellbot.delete(message, "`I can't unblock myself`")
success = await client.unblock_user(user.id)
if success:
await hellbot.delete(
message,
f"**{random.choice(unblocked_messages)}\n\n{Symbols.check_mark} Unblocked:** {user.mention}",
)
else:
await hellbot.error(message, f"`Couldn't unblock {user.mention}`")
@on_message(["allow", "approve"], allow_stan=True)
async def allow_pm(client: Client, message: Message):
if len(message.command) > 1:
try:
user = await client.get_users(message.command[1])
user_id = user.id
user_mention = user.mention
except Exception as e:
return await hellbot.error(message, f"`{e}`")
elif message.chat.type == ChatType.PRIVATE:
user_id = message.chat.id
user_mention = message.chat.first_name or message.chat.title
elif message.reply_to_message:
user_id = message.reply_to_message.from_user.id
user_mention = message.reply_to_message.from_user.mention
else:
return await hellbot.delete(
message, "`Reply to a user or give their id/username`"
)
if user_id == client.me.id:
return await hellbot.delete(message, "`I can't allow myself`")
if await db.is_pmpermit(client.me.id, user_id):
return await hellbot.delete(message, "`User is already allowed to pm!`")
await db.add_pmpermit(client.me.id, user_id)
await hellbot.delete(message, f"**{Symbols.check_mark} Allowed:** {user_mention}")
@on_message(["disallow", "disapprove"], allow_stan=True)
async def disallow_pm(client: Client, message: Message):
if len(message.command) > 1:
try:
user = await client.get_users(message.command[1])
user_id = user.id
user_mention = user.mention
except Exception as e:
return await hellbot.error(message, f"`{e}`")
elif message.chat.type == ChatType.PRIVATE:
user_id = message.chat.id
user_mention = message.chat.first_name or message.chat.title
elif message.reply_to_message:
user_id = message.reply_to_message.from_user.id
user_mention = message.reply_to_message.from_user.mention
else:
return await hellbot.delete(
message, "`Reply to a user or give their id/username`"
)
if user_id == client.me.id:
return await hellbot.delete(message, "`I can't disallow myself`")
if not await db.is_pmpermit(client.me.id, user_id):
return await hellbot.delete(message, "`User is not allowed to pm!`")
await db.rm_pmpermit(client.me.id, user_id)
await hellbot.delete(
message, f"**{Symbols.cross_mark} Disallowed:** {user_mention}"
)
@on_message(["allowlist", "approvelist"], allow_stan=True)
async def allowlist(client: Client, message: Message):
hell = await hellbot.edit(message, "`Fetching allowlist...`")
users = await db.get_all_pmpermits(client.me.id)
if not users:
return await hellbot.delete(hell, "`No users allowed to pm!`")
text = "**๐Ÿ€ ๐– ๐—‰๐—‰๐—‹๐—ˆ๐—๐–พ๐–ฝ ๐–ด๐—Œ๐–พ๐—‹'๐—Œ ๐–ซ๐—‚๐—Œ๐—:**\n\n"
for user in users:
try:
name = (await client.get_users(user["user"])).first_name
text += f" {Symbols.anchor} {name} (`{user['user']}`) | {user['date']}\n"
except:
text += f" {Symbols.anchor} Unkown Peer (`{user['user']}`) | {user['date']}\n"
await hell.edit(text)
@on_message("pmpermit", allow_stan=True)
async def set_pmpermit(_, message: Message):
if len(message.command) < 2:
status = await db.get_env(ENV.pmpermit)
text = "Enabled" if status else "Disabled"
return await hellbot.delete(
message,
f"**Current PM Permit Setting:** `{text}`\n\nTo change the setting give either `on` or `off` as argument.",
)
cmd = message.command[1].lower().strip()
if cmd == "on":
await db.set_env(ENV.pmpermit, True)
await hellbot.delete(message, "**PM Permit Enabled!**")
elif cmd == "off":
await db.set_env(ENV.pmpermit, False)
await hellbot.delete(message, "**PM Permit Disabled!**")
else:
await hellbot.delete(message, "**Invalid Argument!**")
@custom_handler(filters.outgoing & filters.private & ~filters.bot)
async def handler_outgoing_pm(client: Client, message: Message):
if message.chat.id == 777000:
return
if not await db.get_env(ENV.pmpermit):
return
if not await db.is_pmpermit(client.me.id, message.chat.id):
await db.add_pmpermit(client.me.id, message.chat.id)
hell = await client.send_message(message.chat.id, "Approving ...")
await hellbot.delete(
hell,
f"**{Symbols.check_mark} Auto-Approved Outgoing PM:** {message.chat.first_name}",
)
@custom_handler(filters.incoming & filters.private & ~filters.bot & ~filters.service)
async def handle_incoming_pm(client: Client, message: Message):
if message.from_user.id in Config.DEVS:
return
if message.from_user.id == 777000:
return
if not await db.get_env(ENV.pmpermit):
return
if await db.is_pmpermit(client.me.id, message.from_user.id):
return
if message.from_user.id in Config.AUTH_USERS:
return
max_spam = await db.get_env(ENV.pm_max_spam)
max_spam = int(max_spam) if max_spam else 3
warns = WARNS.get(client.me.id, {}).get(message.from_user.id, max_spam)
if warns <= 0:
await client.block_user(message.from_user.id)
WARNS[client.me.id] = {message.from_user.id: max_spam}
return await client.send_message(
message.from_user.id,
f"**{Symbols.cross_mark} ๐–ค๐—‡๐—ˆ๐—Ž๐—€๐— ๐—ˆ๐–ฟ ๐—’๐—ˆ๐—Ž๐—‹ ๐—Œ๐—‰๐–บ๐—†๐—†๐—‚๐—‡๐—€ ๐—๐–พ๐—‹๐–พ! ๐–ก๐—…๐—ˆ๐–ผ๐—„๐—‚๐—‡๐—€ ๐—’๐—ˆ๐—Ž ๐–ฟ๐—‹๐—ˆ๐—† ๐–ฏ๐–ฌ ๐—Ž๐—‡๐—๐—‚๐—… ๐–ฟ๐—Ž๐—‹๐—๐—๐–พ๐—‹ ๐—‡๐—ˆ๐—๐—‚๐–ผ๐–พ.**",
)
pm_msg = f"๐Ÿ€ ๐‡๐ž๐ฅ๐ฅ๐๐จ๐ญ ๐๐Œ ๐’๐ž๐œ๐ฎ๐ซ๐ข๐ญ๐ฒ!\n\n"
custom_pmmsg = await db.get_env(ENV.custom_pmpermit)
if custom_pmmsg:
pm_msg += f"{custom_pmmsg}\n**๐–ธ๐—ˆ๐—Ž ๐—๐–บ๐—๐–พ {warns} ๐—๐–บ๐—‹๐—‡๐—‚๐—‡๐—€๐—Œ ๐—…๐–พ๐–ฟ๐—!**"
else:
pm_msg += f"**๐Ÿ‘‹ ๐–ง๐–พ๐—…๐—…๐—ˆ {message.from_user.mention}!**\n๐–ณ๐—๐—‚๐—Œ ๐—‚๐—Œ ๐–บ๐—‡ ๐–บ๐—Ž๐—๐—ˆ๐—†๐–บ๐—๐–พ๐–ฝ ๐—†๐–พ๐—Œ๐—Œ๐–บ๐—€๐–พ ๐–บ๐—‡๐–ฝ ๐—’๐—ˆ๐—Ž ๐–บ๐—‹๐–พ ๐—‹๐–พ๐—Š๐—Ž๐–พ๐—Œ๐—๐–พ๐–ฝ ๐—‡๐—ˆ๐— ๐—๐—ˆ ๐—Œ๐—‰๐–บ๐—† ๐—†๐–พ๐—Œ๐—Œ๐–บ๐—€๐–พ๐—Œ ๐—๐–พ๐—‹๐–พ! \n**๐–ธ๐—ˆ๐—Ž ๐—๐–บ๐—๐–พ {warns} ๐—๐–บ๐—‹๐—‡๐—‚๐—‡๐—€๐—Œ ๐—…๐–พ๐–ฟ๐—!**"
try:
pm_pic = await db.get_env(ENV.pmpermit_pic)
if pm_pic and pm_pic.endswith(".mp4"):
msg = await client.send_video(
message.from_user.id,
pm_pic,
pm_msg,
)
elif pm_pic:
msg = await client.send_photo(
message.from_user.id,
pm_pic,
pm_msg,
)
else:
msg = await client.send_message(
message.from_user.id,
pm_msg,
disable_web_page_preview=True,
)
except:
msg = await client.send_message(
message.from_user.id,
pm_msg,
disable_web_page_preview=True,
)
prev_msg = PREV_MESSAGE.get(client.me.id, {}).get(message.from_user.id, None)
if prev_msg:
await prev_msg.delete()
PREV_MESSAGE[client.me.id] = {message.from_user.id: msg}
WARNS[client.me.id] = {message.from_user.id: warns - 1}
HelpMenu("pmpermit").add(
"block",
"<reply to user>/<userid/username>",
"Block a user from pm-ing you.",
"block @ForGo10God",
).add(
"unblock",
"<reply to user>/<userid/username>",
"Unblock a user from pm-ing you.",
"unblock @ForGo10God",
).add(
"allow",
"<reply to user>/<userid/username>",
"Allow a user to pm you.",
"allow @ForGo10God",
"An alias of 'approve' is also available.",
).add(
"disallow",
"<reply to user>/<userid/username>",
"Disallow a user to pm you.",
"disallow @ForGo10God",
"An alias of 'disapprove' is also available.",
).add(
"allowlist",
None,
"List all users allowed to pm you.",
"allowlist",
"An alias of 'approvelist' is also available.",
).info(
"Manage who can pm you."
).done()