Ufoptg commited on
Commit
8b0e484
1 Parent(s): f25b6b5

Update code2.py

Browse files
Files changed (1) hide show
  1. code2.py +11 -1
code2.py CHANGED
@@ -31,6 +31,7 @@ async def start(event):
31
  async def help(event):
32
  await event.respond('I can blacklist certain words. Just type them in a chat I am in!')
33
 
 
34
  @client.on(events.NewMessage(incoming=True))
35
  async def check_blacklist(event):
36
  if any(
@@ -45,7 +46,15 @@ async def check_blacklist(event):
45
  f"User id: {user.id}, username: {user.username}"
46
  )
47
 
48
- if not await client.is_admin(event.chat_id, user.id):
 
 
 
 
 
 
 
 
49
  try:
50
  await event.delete()
51
  logger.info("User is not an admin. Deleted the message.")
@@ -71,6 +80,7 @@ async def check_blacklist(event):
71
  else:
72
  logger.info("Message does not contain a blacklisted word.")
73
 
 
74
  @client.on(events.CallbackQuery())
75
  async def handle_button(event):
76
  user = await event.get_sender()
 
31
  async def help(event):
32
  await event.respond('I can blacklist certain words. Just type them in a chat I am in!')
33
 
34
+
35
  @client.on(events.NewMessage(incoming=True))
36
  async def check_blacklist(event):
37
  if any(
 
46
  f"User id: {user.id}, username: {user.username}"
47
  )
48
 
49
+ # Get the chat admin permissions
50
+ try:
51
+ chat_admins = await client.get_participants(event.chat_id, filter=ChannelParticipantsAdmins)
52
+ is_admin = any(admin.id == user.id for admin in chat_admins)
53
+ except Exception as e:
54
+ logger.error(f"Failed to check user admin status: {e}")
55
+ is_admin = False
56
+
57
+ if not is_admin:
58
  try:
59
  await event.delete()
60
  logger.info("User is not an admin. Deleted the message.")
 
80
  else:
81
  logger.info("Message does not contain a blacklisted word.")
82
 
83
+
84
  @client.on(events.CallbackQuery())
85
  async def handle_button(event):
86
  user = await event.get_sender()