• Не исключает после блокировки?

    orloow777
    @orloow777 Автор вопроса
    Программист.
    +кик:
    from handler.base_plugin_command import CommandPlugin
    from vk.utils import EventType
    from vk.helpers import parse_user_id
    
    import time
    
    
    class ChatKickerPlugin(CommandPlugin):
        __slots__ = ("admins", "exiled", "admins_only", "unkick")
    
        def __init__(self, commands=None, free_commands=None, prefixes=None, strict=False, admins=(), admins_only=True):
            """Allows admins to kick users for short amount of time.
            [prefix][command] [time in seconds if kicking]"""
    
            if not commands:
                commands = ["кик", "kick"]
    
            super().__init__(*(commands + free_commands), prefixes=prefixes, strict=strict)
    
            self.admins_only = admins_only
            self.unkick = free_commands
            self.admins = admins
            self.exiled = {}
    
        async def process_message(self, msg):
            if not msg.is_multichat:
                return await msg.answer("Данную команду можно использовать только в беседах!")
    
            if self.admins_only and msg.user_id not in self.admins and not msg.meta.get("is_moder"):
                return await msg.answer("Вы не являетесь модератором/администратором.")
    
            command, text = self.parse_message(msg)
    
            if command in self.unkick:
                inv = True
            else:
                inv = False
    
            parts = text.split(" ")
            kick_time = 0
            puid = None
    
            puid = await parse_user_id(msg)
    
            if len(parts) > 0 and parts[0].isdigit():
                if puid is not None:
                    kick_time = int(parts[0])
    
                else:
                    puid = int(parts[0])
    
            if not puid:
                return await msg.answer(f"ID указан не верно")
    
            if inv:
                if puid in self.exiled:
                    del self.exiled[puid]
    
                return await self.api.messages.addChatUser(chat_id=msg.chat_id, user_id=puid)
    
            if len(parts) > 1 and " ".join(parts[1:]).isdigit():
                kick_time = int(" ".join(parts[1:]))
    
            self.exiled[puid] = time.time() + kick_time
    
            await self.api.messages.removeChatUser(chat_id=msg.chat_id, user_id=puid)
    
        async def check_event(self, evnt):
            return evnt.type == EventType.ChatChange
    
        async def process_event(self, evnt):
            if evnt.source_act == "chat_invite_user" and evnt.source_mid in self.exiled:
                dtime = self.exiled[evnt.source_mid] - time.time()
    
                if dtime > 0:
                    await self.bot.api.messages.send(chat_id=evnt.chat_id, message=f"Вы сможете вернуться в чат "
                                                                                   f"через {int(dtime)} секунд(у/ы)")
    
                    return await self.api.messages.removeChatUser(chat_id=evnt.chat_id, user_id=evnt.source_mid)
    
                del self.exiled[evnt.source_mid]
    
            return False
    Ответ написан
    Комментировать