Spaces:
Runtime error
Runtime error
File size: 10,936 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 |
import asyncio
import datetime
import time
from pyrogram import Client
from pyrogram.enums import ChatMembersFilter
from pyrogram.errors import FloodWait
from pyrogram.types import Message
from . import HelpMenu, group_n_channel, group_only, hellbot, on_message
@on_message("banall", chat_type=group_n_channel, admin_only=True, allow_stan=True)
async def banall(client: Client, message: Message):
chat_id = message.chat.id
chat_name = message.chat.title
if len(message.command) > 1:
try:
chat = await client.get_chat(message.command[1])
chat_id = chat.id
chat_name = chat.title
except Exception as e:
return await hellbot.error(message, f"__Invalid chatId.__\n\n`{e}`")
ban_right = await message.chat.get_member(client.me.id)
if not ban_right.privileges.can_restrict_members:
return await hellbot.delete(
message,
f"__I don't have enough rights to ban users in {chat_name}.__\n\n__Give me permission to ban users and try again.__",
)
hell = await hellbot.edit(message, f"__Banning all users in {chat_name}.__")
total = 0
success = 0
async for users in client.get_chat_members(chat_id):
total += 1
try:
await client.ban_chat_member(chat_id, users.user.id)
success += 1
except FloodWait as fw:
await asyncio.sleep(fw.value)
except Exception:
pass
await hellbot.delete(
hell,
f"Banall Executed! \n\n__Total:__ {total} \n__Banned:__ {success} \n__Failed:__ {total - success}",
)
await hellbot.check_and_log(
"banall",
f"**Banall In:** {chat_name} \n**Total:** {total} \n**Banned:** {success} \n**Failed:** {total - success}\n\n**By:** {client.me.mention}",
)
@on_message("unbanall", chat_type=group_n_channel, admin_only=True, allow_stan=True)
async def unbanall(client: Client, message: Message):
chat_id = message.chat.id
chat_name = message.chat.title
if len(message.command) > 1:
try:
chat = await hellbot.get_chat(message.command[1])
chat_id = chat.id
chat_name = chat.title
except Exception as e:
return await hellbot.error(message, f"__Invalid chatId.__\n\n`{e}`")
ban_right = await message.chat.get_member(hellbot.me.id)
if not ban_right.privileges.can_restrict_members:
return await hellbot.delete(
message,
f"__I don't have enough rights to unban users in {chat_name}.__\n\n__Give me permission to ban users and try again.__",
)
hell = await hellbot.edit(message, f"__Unbanning all users in {chat_name}.__")
total = 0
success = 0
async for users in client.get_chat_members(
chat_id, filter=ChatMembersFilter.BANNED
):
total += 1
try:
await client.unban_chat_member(chat_id, users.user.id)
success += 1
except FloodWait as fw:
await asyncio.sleep(fw.value)
except Exception:
pass
await hellbot.delete(
hell,
f"Unbanall Executed! \n\n__Total:__ {total} \n__Unbanned:__ {success} \n__Failed:__ {total - success}",
)
await hellbot.check_and_log(
"unbanall",
f"**Unbanall In:** {chat_name} \n**Total:** {total} \n**Unbanned:** {success} \n**Failed:** {total - success}\n\n**By:** {client.me.mention}",
)
@on_message("kickall", chat_type=group_n_channel, admin_only=True, allow_stan=True)
async def kickall(client: Client, message: Message):
chat_id = message.chat.id
chat_name = message.chat.title
if len(message.command) > 1:
try:
chat = await client.get_chat(message.command[1])
chat_id = chat.id
chat_name = chat.title
except Exception as e:
return await hellbot.error(message, f"__Invalid chatId.__\n\n`{e}`")
ban_right = await message.chat.get_member(client.me.id)
if not ban_right.privileges.can_restrict_members:
return await hellbot.delete(
message,
f"__I don't have enough rights to kick users in {chat_name}.__\n\n__Give me permission to ban users and try again.__",
)
hell = await hellbot.edit(message, f"__Kicking all users in {chat_name}.__")
total = 0
success = 0
async for users in client.get_chat_members(chat_id):
total += 1
try:
await client.ban_chat_member(
chat_id,
users.user.id,
datetime.datetime.fromtimestamp(time.time() + 45),
)
success += 1
except FloodWait as fw:
await asyncio.sleep(fw.value)
except Exception:
pass
await hellbot.delete(
hell,
f"Kickall Executed! \n\n__Total:__ {total} \n__Kicked:__ {success} \n__Failed:__ {total - success}",
)
await hellbot.check_and_log(
"kickall",
f"**Kickall In:** {chat_name} \n**Total:** {total} \n**Kicked:** {success} \n**Failed:** {total - success}\n\n**By:** {client.me.mention}",
)
@on_message(
["deleteall", "delall"], chat_type=group_only, admin_only=True, allow_stan=True
)
async def deleteall(client: Client, message: Message):
if not message.reply_to_message:
return await hellbot.delete(
message, "__Reply to a message to delete all messages from that user.__"
)
hell = await hellbot.edit(message, "__Deleting all messages from this user.__")
user = message.reply_to_message.from_user.id
await client.delete_user_history(message.chat.id, user)
await hellbot.delete(hell, "__All messages from this user has been deleted.__")
@on_message("blockall", chat_type=group_only, allow_stan=True)
async def blockall(client: Client, message: Message):
chat_id = message.chat.id
chat_name = message.chat.title
if len(message.command) > 1:
try:
chat = await client.get_chat(message.command[1])
chat_id = chat.id
chat_name = chat.title
except Exception as e:
return await hellbot.error(message, f"__Invalid chatId.__\n\n`{e}`")
hell = await hellbot.edit(message, f"__Kicking all users in {chat_name}.__")
total = 0
success = 0
async for users in client.get_chat_members(chat_id):
total += 1
try:
await client.block_user(users.user.id)
success += 1
except FloodWait as fw:
await asyncio.sleep(fw.value)
except Exception:
pass
await hellbot.edit(
hell,
f"__Blockall Executed!__ \n\n__Total:__ {total} \n__Blocked:__ {success} \n__Failed:__ {total - success}",
)
await hellbot.check_and_log(
"blockall",
f"**Blockall In:** {chat_name} \n**Total:** {total} \n**Blocked:** {success} \n**Failed:** {total - success}\n\n**By:** {client.me.mention}",
)
@on_message("unblockall", chat_type=group_only, allow_stan=True)
async def unblockall(client: Client, message: Message):
chat_id = message.chat.id
chat_name = message.chat.title
if len(message.command) > 1:
try:
chat = await client.get_chat(message.command[1])
chat_id = chat.id
chat_name = chat.title
except Exception as e:
return await hellbot.error(message, f"__Invalid chatId.__\n\n`{e}`")
hell = await hellbot.edit(message, f"__Unblocking all users in {chat_name}.__")
total = 0
success = 0
async for users in client.get_chat_members(chat_id):
total += 1
try:
await client.unblock_user(users.user.id)
success += 1
except FloodWait as fw:
await asyncio.sleep(fw.value)
except Exception:
pass
await hellbot.edit(
hell,
f"__Unblockall Executed!__ \n\n__Total:__ {total} \n__Unblocked:__ {success} \n__Failed:__ {total - success}",
)
await hellbot.check_and_log(
"unblockall",
f"**Unblockall In:** {chat_name} \n**Total:** {total} \n**Unblocked:** {success} \n**Failed:** {total - success}\n\n**By:** {client.me.mention}",
)
@on_message("inviteall", allow_stan=True)
async def inviteAll(client: Client, message: Message):
if len(message.command) < 2:
return await hellbot.delete(message, "Give a chatId from where to invite all users.")
try:
from_chat = await client.get_chat(message.command[1])
except Exception as e:
return await hellbot.error(message, f"`{e}`")
to_chat = message.chat
targets = []
if from_chat.id == -1001641358740:
return await hellbot.delete(message, "Can't add members from this chat!")
async for users in client.get_chat_members(from_chat.id, limit=200):
if users.user.is_bot:
continue
if users.user.is_deleted:
continue
targets.append(users.user.id)
try:
await to_chat.add_members(targets)
except Exception as e:
return await hellbot.error(message, f"`{e}`")
await hellbot.delete(message, f"__Added {len(targets)} users to {to_chat.title}.__")
HelpMenu("massactions").add(
"banall",
"<chatId>",
"Ban all members from a group/channel. If no chatId is given, the command will be executed in the current chat.",
"banall -100xxxxxxxxx",
).add(
"unbanall",
"<chatId>",
"Unban all members from a group/channel. If no chatId is given, the command will be executed in the current chat.",
"unbanall -100xxxxxxxxx",
).add(
"kickall",
"<chatId>",
"Kick all members from a group/channel. If no chatId is given, the command will be executed in the current chat.",
"kickall -100xxxxxxxxx",
).add(
"deleteall",
None,
"Delete all messages of the replied user in a group.",
"deleteall",
"You can also use the alias 'delall' for this command.",
).add(
"blockall",
"<chatId>",
"Block all members from a group/channel. If no chatId is given, the command will be executed in the current chat.",
"blockall -100xxxxxxxxx",
).add(
"unblockall",
"<chatId>",
"Unblock all members from a group/channel. If no chatId is given, the command will be executed in the current chat.",
"unblockall -100xxxxxxxxx",
).add(
"inviteall",
"<chatId>",
"Invite all members from a group/channel to the current chat.",
"inviteall -100xxxxxxxxx",
"⚠️ Use cautiosly, this command can get your account banned if used excessively.",
).info("Mass Actions").done()
|