mirror of https://github.com/Ruslan-Isaev/modules
Update Amnesty.py
parent
a8788d2c24
commit
1ffa36c2cc
30
Amnesty.py
30
Amnesty.py
|
@ -8,6 +8,7 @@ import time
|
||||||
from .. import loader, utils
|
from .. import loader, utils
|
||||||
import typing
|
import typing
|
||||||
from telethon.errors import ChatAdminRequiredError, UserAdminInvalidError
|
from telethon.errors import ChatAdminRequiredError, UserAdminInvalidError
|
||||||
|
from telethon.tl.functions.contacts import GetBlockedRequest, UnblockRequest
|
||||||
|
|
||||||
def seq_rights(sequence: str, inv: bool = False) -> typing.Union[dict, None]:
|
def seq_rights(sequence: str, inv: bool = False) -> typing.Union[dict, None]:
|
||||||
if not sequence:
|
if not sequence:
|
||||||
|
@ -45,9 +46,16 @@ def seq_rights(sequence: str, inv: bool = False) -> typing.Union[dict, None]:
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
async def unblock_user(message, user_id, i, ids):
|
||||||
|
try:
|
||||||
|
await message.client(UnblockRequest(id=user_id))
|
||||||
|
await utils.answer(message, f"♻️ <b>Разбанено пользователей: {i + 1}/{int(len(ids))}</b>")
|
||||||
|
except Exception as e:
|
||||||
|
await utils.answer(message, f"🚫 <b> Ошибка! </b>\n\n<code>{e}</code>")
|
||||||
|
|
||||||
@loader.tds
|
@loader.tds
|
||||||
class AmnestyMod(loader.Module):
|
class AmnestyMod(loader.Module):
|
||||||
"""Модуль для разбана всех пользователей в чате (амнистия)."""
|
"""Модуль для разбана всех пользователей в чате или в лс (амнистия)"""
|
||||||
|
|
||||||
strings = {
|
strings = {
|
||||||
"name": "Amnesty",
|
"name": "Amnesty",
|
||||||
|
@ -55,7 +63,7 @@ class AmnestyMod(loader.Module):
|
||||||
|
|
||||||
@loader.command()
|
@loader.command()
|
||||||
async def amnestycmd(self, message):
|
async def amnestycmd(self, message):
|
||||||
""" - разблокирует всех"""
|
""" - разблокирует всех в чате"""
|
||||||
try:
|
try:
|
||||||
chat_id = message.chat.id
|
chat_id = message.chat.id
|
||||||
except:
|
except:
|
||||||
|
@ -64,6 +72,9 @@ class AmnestyMod(loader.Module):
|
||||||
chat = await message.client.get_participants(chat_id, filter=ChannelParticipantsKicked)
|
chat = await message.client.get_participants(chat_id, filter=ChannelParticipantsKicked)
|
||||||
ids = [user.id for user in chat]
|
ids = [user.id for user in chat]
|
||||||
i = 0
|
i = 0
|
||||||
|
if len(ids) == 0:
|
||||||
|
await utils.answer(message, "<b>Черный список чата уже пустой!</b>")
|
||||||
|
return
|
||||||
for id in ids:
|
for id in ids:
|
||||||
try:
|
try:
|
||||||
await self.client.edit_permissions(chat_id, id, None, **seq_rights('0'),)
|
await self.client.edit_permissions(chat_id, id, None, **seq_rights('0'),)
|
||||||
|
@ -77,3 +88,18 @@ class AmnestyMod(loader.Module):
|
||||||
i += 1
|
i += 1
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
await utils.answer(message, f"✅ <b>Успешно! {int(len(ids))} пользователей разблокировано!</b>")
|
await utils.answer(message, f"✅ <b>Успешно! {int(len(ids))} пользователей разблокировано!</b>")
|
||||||
|
|
||||||
|
@loader.command()
|
||||||
|
async def amnistiacmd(self, message):
|
||||||
|
""" - разблокирует всех в лс"""
|
||||||
|
chat = await message.client(GetBlockedRequest(offset=0, limit=500))
|
||||||
|
i = 0
|
||||||
|
ids = [user.id for user in chat.users]
|
||||||
|
if len(ids) == 0:
|
||||||
|
await utils.answer(message, "<b>Черный список пустой!</b>")
|
||||||
|
return
|
||||||
|
for id in ids:
|
||||||
|
await unblock_user(message, id, i, ids)
|
||||||
|
i += 1
|
||||||
|
time.sleep(1)
|
||||||
|
await utils.answer(message, f"✅ <b>Успешно! {int(len(ids))} пользователей разблокировано!</b>")
|
||||||
|
|
Loading…
Reference in New Issue