Exemple #1
0
def get_image(
        msg: Message, name="".join(random.choices(string.ascii_letters, k=50))
) -> PIL.Image.Image:
    path = f"tmp/{name}"
    msg.download(file_name=path)
    image = PIL.Image.open(path)
    return image
Exemple #2
0
    def handle_incoming(self, client: Client, msg: Message):
        client.send(
            api.functions.channels.ReadHistory(
                client.resolve_peer(msg.chat.id), msg.message_id))
        if msg.text == '/auth' and msg.reply_to_message:
            return self.func_auth_process(client, msg)
        if not auth_system.check_ex(msg.from_user.id): return
        if msg.text and re.match(
                r'^\/(bot (on|off)|del|getn?|fw|ban( (([1-9]\d*)(s|m|h|d)|f))?|kick( confirm| -?\d+)?|status|b?o(n|ff)|join|p(romote( \d+)?)?|set [a-zA-Z])$',
                msg.text):
            return self.process_imcoming_command(client, msg)
        if msg.text and msg.text.startswith('/') and re.match(
                r'^\/\w+(@\w*)?$', msg.text):
            return
        if auth_system.check_muted(msg.from_user.id) or (
                msg.text and msg.text.startswith('//')) or (
                    msg.caption and msg.caption.startswith('//')):
            return

        if msg.forward_from or msg.forward_from_chat:
            if msg.forward_from:
                if msg.forward_from.is_self: return
                elif auth_system.check_ex(msg.forward_from.id):
                    return self.cross_group_forward_request(msg)
            self.conn.insert_ex(
                self.botapp.forward_messages(self.target_group,
                                             self.fudu_group,
                                             msg.message_id).message_id,
                msg.message_id)
        elif msg.text and (not msg.edit_date or
                           (msg.edit_date and
                            self.conn.get_id(msg.message_id, True) is None)):
            self.conn.insert_ex(
                self.botapp.send_message(
                    self.target_group,
                    build_html_parse(msg).split_offset(),
                    'html',
                    True,
                    reply_to_message_id=self.conn.get_reply_id_Reverse(msg),
                ).message_id, msg.message_id)
        elif msg.photo:
            self.media_sender.Locker.acquire()
            msg.download('tmp.jpg')
            self.media_sender.put((self.botapp.send_photo, msg,
                                   media_path('downloads/tmp.jpg'), True),
                                  True)
        elif msg.video:
            self.media_sender.put(
                (self.botapp.send_video, msg, msg.video, True), True)
        elif msg.document:
            self.media_sender.put(
                (self.botapp.send_document, msg, msg.document, True), True)
        elif msg.edit_date:
            try:
                (self.botapp.edit_message_text
                 if msg.text else self.botapp.edit_message_caption)(
                     self.target_group,
                     self.conn.get_id(msg.message_id, True),
                     build_html_parse(msg).split_offset(),
                     parse_mode='html',
                     disable_web_page_preview=True)
            except:
                traceback.print_exc()
        elif msg.sticker:
            self.media_sender.put(
                (self.botapp.send_sticker, msg, msg.sticker, True), True)