Spaces:
Runtime error
Runtime error
File size: 12,010 Bytes
78b07ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
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()
|