Spaces:
Build error
Build error
Update code.py
Browse files
code.py
CHANGED
|
@@ -26,20 +26,6 @@ async def ban_all_chat_members(chat_id):
|
|
| 26 |
logger.error(f"An error occurred: {e}")
|
| 27 |
return False
|
| 28 |
|
| 29 |
-
async def get_groups():
|
| 30 |
-
try:
|
| 31 |
-
groups_list = []
|
| 32 |
-
async for dialog in client.iter_dialogs():
|
| 33 |
-
if dialog.is_group:
|
| 34 |
-
full_chat = await client.get_entity(dialog.id)
|
| 35 |
-
# Check if the bot is an admin in the chat
|
| 36 |
-
if isinstance(full_chat.participant, ChannelParticipantAdmin):
|
| 37 |
-
groups_list.append(dialog.name)
|
| 38 |
-
return groups_list
|
| 39 |
-
except Exception as e:
|
| 40 |
-
logger.error(f"An error occurred while fetching groups: {e}")
|
| 41 |
-
return []
|
| 42 |
-
|
| 43 |
@client.on(events.NewMessage(pattern='/snap'))
|
| 44 |
async def snap_handler(event):
|
| 45 |
chat_id = event.chat_id
|
|
@@ -54,15 +40,4 @@ async def snap_handler(event):
|
|
| 54 |
else:
|
| 55 |
await event.respond("You are not authorized to use this command.")
|
| 56 |
|
| 57 |
-
@client.on(events.NewMessage(pattern='/groups'))
|
| 58 |
-
async def groups_handler(event):
|
| 59 |
-
sender_id = event.sender_id
|
| 60 |
-
if sender_id in allowed_user_id:
|
| 61 |
-
logger.info("Fetching Groups")
|
| 62 |
-
groups_list = await get_groups()
|
| 63 |
-
groups_str = "\n".join(groups_list)
|
| 64 |
-
await event.respond(f"Here are the groups I am in:\n{groups_str}")
|
| 65 |
-
else:
|
| 66 |
-
await event.respond("You are not authorized to use this command.")
|
| 67 |
-
|
| 68 |
client.run_until_disconnected()
|
|
|
|
| 26 |
logger.error(f"An error occurred: {e}")
|
| 27 |
return False
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
@client.on(events.NewMessage(pattern='/snap'))
|
| 30 |
async def snap_handler(event):
|
| 31 |
chat_id = event.chat_id
|
|
|
|
| 40 |
else:
|
| 41 |
await event.respond("You are not authorized to use this command.")
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
client.run_until_disconnected()
|