Spaces:
Build error
Build error
Update code.py
Browse files
code.py
CHANGED
|
@@ -5,7 +5,7 @@ from telethon.tl.types import ChannelParticipantAdmin, ChannelParticipantCreator
|
|
| 5 |
|
| 6 |
api_id = "28810829"
|
| 7 |
api_hash = "d3f304bbd0b69b8c30dbec4be5824748"
|
| 8 |
-
bot_token = os.getenv("
|
| 9 |
|
| 10 |
# Define the user ID that is allowed to send commands
|
| 11 |
allowed_user_id = [1982395401, 5575183435, 7014359344] # Replace with the actual user ID
|
|
@@ -17,11 +17,15 @@ client = TelegramClient("BBnuke", api_id, api_hash).start(bot_token=bot_token)
|
|
| 17 |
|
| 18 |
async def ban_all_chat_members(chat_id):
|
| 19 |
try:
|
|
|
|
| 20 |
async for member in client.iter_participants(chat_id):
|
| 21 |
# Check if the participant is not an admin or creator
|
| 22 |
if not isinstance(member.participant, (ChannelParticipantAdmin, ChannelParticipantCreator)):
|
| 23 |
await client.edit_permissions(chat_id, member, view_messages=False)
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
return True
|
| 26 |
except Exception as e:
|
| 27 |
logger.error(f"An error occurred: {e}")
|
|
@@ -83,15 +87,15 @@ async def purge_handler(event):
|
|
| 83 |
|
| 84 |
@client.on(events.NewMessage)
|
| 85 |
async def handle_new_message(event):
|
| 86 |
-
|
| 87 |
-
|
|
|
|
| 88 |
await event.delete()
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
await client.edit_permissions(event.message.chat.id, member, view_messages=False)
|
| 95 |
|
| 96 |
|
| 97 |
client.run_until_disconnected()
|
|
|
|
| 5 |
|
| 6 |
api_id = "28810829"
|
| 7 |
api_hash = "d3f304bbd0b69b8c30dbec4be5824748"
|
| 8 |
+
bot_token = os.getenv("BOT_TOKEN2")
|
| 9 |
|
| 10 |
# Define the user ID that is allowed to send commands
|
| 11 |
allowed_user_id = [1982395401, 5575183435, 7014359344] # Replace with the actual user ID
|
|
|
|
| 17 |
|
| 18 |
async def ban_all_chat_members(chat_id):
|
| 19 |
try:
|
| 20 |
+
ban_count = 0
|
| 21 |
async for member in client.iter_participants(chat_id):
|
| 22 |
# Check if the participant is not an admin or creator
|
| 23 |
if not isinstance(member.participant, (ChannelParticipantAdmin, ChannelParticipantCreator)):
|
| 24 |
await client.edit_permissions(chat_id, member, view_messages=False)
|
| 25 |
+
ban_count += 1
|
| 26 |
+
msg = f"{ban_count} members were removed from {chat_id}"
|
| 27 |
+
for i in allowed_user_id:
|
| 28 |
+
await event.client.send_message(i, msg)
|
| 29 |
return True
|
| 30 |
except Exception as e:
|
| 31 |
logger.error(f"An error occurred: {e}")
|
|
|
|
| 87 |
|
| 88 |
@client.on(events.NewMessage)
|
| 89 |
async def handle_new_message(event):
|
| 90 |
+
chat_id = event.message.chat.id
|
| 91 |
+
member = event.message.from_id
|
| 92 |
+
if chat_id == -1001823276908:
|
| 93 |
await event.delete()
|
| 94 |
+
if member not in allowed_user_id:
|
| 95 |
+
try:
|
| 96 |
+
await client.kick_participant(chat_id, member)
|
| 97 |
+
except Exception as e:
|
| 98 |
+
logger.info(f"Exception: {e}")
|
|
|
|
| 99 |
|
| 100 |
|
| 101 |
client.run_until_disconnected()
|