SoulofSukuna commited on
Commit
25139e1
·
verified ·
1 Parent(s): 9b0ab22

Update code.py

Browse files
Files changed (1) hide show
  1. code.py +14 -10
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("BOT_TOKEN")
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
- #await client.kick_participant(chat_id, member)
 
 
 
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
- if event.message.chat.id == -1001823276908:
87
- # Delete the message
 
88
  await event.delete()
89
-
90
- # Get the user who sent the message
91
- member = event.message.from_id
92
-
93
- # Restrict the user's permissions
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()