コード例 #1
0
async def get_inote(note_id: int, chat_id: int, user_id: int):
    message = await userge.bot.get_messages(Config.LOG_CHANNEL_ID, note_id)
    caption = ""
    if message.caption:
        caption = message.caption.html.split("\n\n", maxsplit=1)[-1]
    elif message.text:
        caption = message.text.html.split("\n\n", maxsplit=1)[-1]
    if caption:
        caption = no_mention(caption)
        u_dict = await userge.get_user_dict(user_id)
        u_dict["mention"] = no_mention(u_dict["mention"])
        chat = await userge.get_chat(chat_id)
        u_dict.update({
            "chat": chat.title if chat.title else "this group",
            "count": chat.members_count,
        })
        caption = caption.format_map(SafeDict(**u_dict))
    file_id = get_file_id(message)
    caption, buttons = parse_buttons(caption)
    if message.media and file_id:
        if message.photo:
            type_ = "photo"
        else:
            type_ = "media"
    else:
        type_ = "text"
    return {
        "type": type_,
        "file_id": file_id,
        "caption": caption,
        "buttons": buttons
    }
コード例 #2
0
    async def forward_stored(self,
                             client: Union['_client.Userge', '_client._UsergeBot'],
                             message_id: int,
                             chat_id: int,
                             user_id: int,
                             reply_to_message_id: int,
                             del_in: int = 0) -> None:
        """\nforward stored message from log channel.

        Parameters:
            client (`Userge` | `usergeBot`):
                Pass Userge or UsergeBot.

            message_id (`int`):
                Message id of stored message.

            chat_id (`int`):
                ID of chat (dest) you want to farward.

            user_id (`int`):
                ID of user you want to reply.

            reply_to_message_id (`int`):
                If the message is a reply, ID of the original message.

            del_in (`int`):
                Time in Seconds for delete that message.

        Returns:
            None
        """
        if message_id and isinstance(message_id, int):
            message = await client.get_messages(chat_id=Config.LOG_CHANNEL_ID,
                                                message_ids=message_id)
            caption = ''
            file_id = file_ref = None
            if message.caption:
                caption = message.caption.html.split('\n\n', maxsplit=1)[-1]
            elif message.text:
                caption = message.text.html.split('\n\n', maxsplit=1)[-1]
            if caption:
                u_dict = await client.get_user_dict(user_id)
                chat = await client.get_chat(chat_id)
                u_dict.update({
                    'chat': chat.title if chat.title else "this group",
                    'count': chat.members_count})
                caption = caption.format_map(SafeDict(**u_dict))
            file_id, file_ref = get_file_id_and_ref(message)
            caption, buttons = parse_buttons(caption)
            if message.media and file_id and file_ref:
                msg = await client.send_cached_media(
                    chat_id=chat_id,
                    file_id=file_id,
                    file_ref=file_ref,
                    caption=caption,
                    reply_to_message_id=reply_to_message_id,
                    reply_markup=buttons if client.is_bot and buttons else None)
            else:
                msg = await client.send_message(
                    chat_id=chat_id,
                    text=caption,
                    reply_to_message_id=reply_to_message_id,
                    disable_web_page_preview=True,
                    reply_markup=buttons if client.is_bot and buttons else None)
            if del_in and msg:
                await asyncio.sleep(del_in)
                await msg.delete()
コード例 #3
0
    async def forward_stored(self,
                             client: Union['_client.Userge',
                                           '_client.UsergeBot'],
                             message_id: int,
                             chat_id: int,
                             user_id: int,
                             reply_to_message_id: int,
                             dis_preview: bool = True,
                             del_in: int = 0,
                             allow_random: bool = True) -> None:
        """\nforward stored message from log channel.

        Parameters:
            client (`Userge` | `UsergeBot`):
                Pass Userge or UsergeBot.

            message_id (`int`):
                Message id of stored message.

            chat_id (`int`):
                ID of chat (dest) you want to farward.

            user_id (`int`):
                ID of user you want to reply.

            reply_to_message_id (`int`):
                If the message is a reply, ID of the original message.

            del_in (`int`):
                Time in Seconds for delete that message.

        Returns:
            None
        """
        if not message_id or not isinstance(message_id, int):
            return
        message = await client.get_messages(chat_id=self._id,
                                            message_ids=message_id)
        caption = ''
        if message.caption:
            caption = message.caption.html.split('\n\n', maxsplit=1)[-1]
        elif message.text:
            caption = message.text.html.split('\n\n', maxsplit=1)[-1]
        if caption:
            u_dict = await client.get_user_dict(user_id)
            chat = await client.get_chat(chat_id)
            u_dict.update({
                'chat': chat.title if chat.title else "this group",
                'count': chat.members_count
            })
            caption = caption.format_map(SafeDict(**u_dict))
        file_id = get_file_id(message)
        caption, buttons = parse_buttons(caption)
        split_char = r"%%%"
        if allow_random and split_char in caption:
            caption = rand_array(caption.split(split_char))
        try:
            if message.media and file_id:
                msg = await client.send_cached_media(
                    chat_id=chat_id,
                    file_id=file_id,
                    caption=caption,
                    reply_to_message_id=reply_to_message_id,
                    reply_markup=buttons
                    if client.is_bot and buttons else None)
            else:
                msg = await client.send_message(
                    chat_id=chat_id,
                    text=caption,
                    reply_to_message_id=reply_to_message_id,
                    disable_web_page_preview=dis_preview,
                    reply_markup=buttons
                    if client.is_bot and buttons else None)
            if del_in and msg:
                await asyncio.sleep(del_in)
                await msg.delete()
        except ChatWriteForbidden:
            pass