示例#1
0
    async def unfban_user(self, message):
        """Unban a user on federation"""
        chat_id = message.chat.id
        if message.chat.type == "private":
            return await message.reply_text(await self.bot.text(
                chat_id, "err-chat-groups"))

        banner = message.from_user
        fed_data = await self.get_fed_bychat(chat_id)
        if not fed_data:
            return await message.reply_text(await self.bot.text(
                chat_id, "fed-no-fed-chat"))

        if not self.is_fed_admin(fed_data, banner.id):
            return await message.reply_text(await self.bot.text(
                chat_id, "fed-admin-only"))

        to_unban, _ = extract_user_and_text(message)
        if not to_unban:
            return await message.reply_text(await self.bot.text(
                chat_id, "fed-no-ban-user"))

        user = await extract_user(self.bot.client, to_unban)
        if str(user.id) not in fed_data.get("banned").keys():
            return await message.reply_text(await self.bot.text(
                chat_id, "fed-user-not-banned"))

        await self.fban_user(fed_data["_id"],
                             user.id,
                             ParsedChatMember(user).fullname,
                             ban=False)

        text = await self.bot.text(chat_id, "fed-unban-info", fed_data["name"],
                                   banner.mention, user.mention, user.id)
        await message.reply_text(text)
        LOGGER.debug(f"Unfedban {user.id} on {fed_data['_id']}")
        for chats in fed_data["chats"]:
            await self.bot.client.unban_chat_member(chats, user.id)
        # send message to federation log
        flog = fed_data.get("log", None)
        if flog:
            await self.bot.client.send_message(flog,
                                               text,
                                               disable_web_page_preview=True)
示例#2
0
 async def parse_user(user) -> ParsedChatMember:
     """ Get user attribute """
     parsed_user = ParsedChatMember(user)
     return parsed_user
示例#3
0
 async def parse_member(self, user_ids) -> ParsedChatMember:
     """ Get member atrribute """
     member = await extract_user(self.bot.client, user_ids)
     return ParsedChatMember(member)
示例#4
0
    async def fed_ban(self, message):
        """Fed ban a user"""
        chat_id = message.chat.id
        if message.chat.type == "private":
            return await message.reply_text(await self.bot.text(
                chat_id, "err-chat-groups"))

        banner = message.from_user
        fed_data = await self.get_fed_bychat(chat_id)
        if not fed_data:
            return await message.reply_text(await self.bot.text(
                chat_id, "fed-no-fed-chat"))

        if not self.is_fed_admin(fed_data, banner.id):
            return await message.reply_text(await self.bot.text(
                chat_id, "fed-admin-only"))

        to_ban, reason = extract_user_and_text(message)
        if not to_ban:
            return await message.reply_text(await self.bot.text(
                chat_id, "fed-no-ban-user"))

        user = await extract_user(self.bot.client, to_ban)
        user_id = user.id
        if user_id == self.bot.identifier:
            return await message.reply_text(await self.bot.text(
                chat_id, "fed-ban-self"))
        if self.is_fed_admin(fed_data, user_id):
            return await message.reply_text(await self.bot.text(
                chat_id, "fed-ban-owner"))
        if user_id in self.bot.staff_id or user_id in (777000, 1087968824):
            return await message.reply_text(await self.bot.text(
                chat_id, "fed-ban-protected"))

        if not reason:
            reason = "No reason given."
        update = False
        if str(user_id) in fed_data.get("banned", {}).keys():
            update = True

        banned_user = ParsedChatMember(user)
        await self.fban_user(fed_data["_id"], user_id, banned_user.fullname,
                             reason, True)
        if update:
            text = await self.bot.text(
                chat_id,
                "fed-ban-info-update",
                fed_data["name"],
                banner.mention,
                banned_user.mention,
                user_id,
                fed_data["banned"][str(user_id)]["reason"],
                reason,
            )
        else:
            text = await self.bot.text(
                chat_id,
                "fed-ban-info",
                fed_data["name"],
                banner.mention,
                banned_user.mention,
                user_id,
                reason,
            )

        await message.reply_text(text, disable_web_page_preview=True)
        LOGGER.debug(f"New fedban {user_id} on {fed_data['id']}")
        for chats in fed_data["chats"]:
            await self.bot.client.kick_chat_member(chats, user_id)