Example #1
0
 def edit_text_message(self,
                       message: Message,
                       reactions: bool = False,
                       commands: bool = False,
                       substitution: bool = False) -> Message:
     message.edit = True
     message.text = f"Edited {message.type.name} message {message.uid} @ {time.time_ns()}"
     message = self.attach_message_properties(message, reactions, commands,
                                              substitution)
     self.messages_sent[message.uid] = message
     coordinator.send_message(message)
     return message
Example #2
0
 def edit_file_like_message_text(self,
                                 message: Message,
                                 reactions: bool = False,
                                 commands: bool = False,
                                 substitution: bool = False) -> Message:
     message.text = f"Content of edited {message.type.name} message with ID {message.uid}"
     message.edit = True
     message.edit_media = False
     message = self.attach_message_properties(message, reactions, commands,
                                              substitution)
     self.messages_sent[message.uid] = message
     coordinator.send_message(message)
     return message
Example #3
0
 def edit_location_message(self,
                           message: Message,
                           reactions: bool = False,
                           commands: bool = False,
                           substitution: bool = False) -> Message:
     message.text = f"Content of edited location message with ID {message.uid}"
     message.edit = True
     message.attributes = LocationAttribute(
         latitude=random.uniform(0.0, 90.0),
         longitude=random.uniform(0.0, 90.0))
     message = self.attach_message_properties(message, reactions, commands,
                                              substitution)
     self.messages_sent[message.uid] = message
     coordinator.send_message(message)
     return message
Example #4
0
    def edit_link_message(self,
                          message: Message,
                          reactions: bool = False,
                          commands: bool = False,
                          substitution: bool = False) -> Message:

        message.text = f"Content of edited link message with ID {message.uid}"
        message.edit = True
        message.attributes = LinkAttribute(
            title="EH Forwarder Bot (edited)",
            description="EH Forwarder Bot project site. (edited)",
            url="https://efb.1a23.studio/#edited")
        message = self.attach_message_properties(message, reactions, commands,
                                                 substitution)
        self.messages_sent[message.uid] = message
        coordinator.send_message(message)
        return message
Example #5
0
    def process_audio(self, message: Message, audio: NamedTemporaryFile):
        try:
            # reply_text: str = '\n'.join(self.recognize(audio.name, self.lang))
            reply_text: str = '\n'.join(self.recognize(audio.name))
        except Exception:
            reply_text = 'Failed to recognize voice content.'
        if getattr(message, 'text', None) is None:
            message.text = ""
        message.text += reply_text
        message.text = message.text[:4000]

        # message.file = None
        message.edit = True
        message.edit_media = False
        coordinator.send_message(message)

        audio.close()
Example #6
0
 def edit_file_like_message(self,
                            message: Message,
                            file_path: Path,
                            mime: str,
                            reactions: bool = False,
                            commands: bool = False,
                            substitution: bool = False) -> Message:
     message.text = f"Content of edited {message.type.name} media with ID {message.uid}"
     message.edit = True
     message.edit_media = True
     message.file = file_path.open('rb')
     message.filename = file_path.name
     message.path = file_path
     message.mime = mime
     message = self.attach_message_properties(message, reactions, commands,
                                              substitution)
     self.messages_sent[message.uid] = message
     coordinator.send_message(message)
     return message
Example #7
0
    def master_qr_code(self, uuid, status, qrcode=None):
        status = int(status)
        if self.qr_uuid == (uuid, status):
            return
        self.qr_uuid = (uuid, status)

        msg = Message(
            uid=f"ews_auth_{uuid}_{status}_{uuid4()}",
            type=MsgType.Text,
            chat=self.user_auth_chat,
            author=self.user_auth_chat.other,
            deliver_to=coordinator.master,
        )

        if status == 201:
            msg.type = MsgType.Text
            msg.text = self._('Confirm on your phone.')
            self.master_qr_picture_id = None
        elif status == 200:
            msg.type = MsgType.Text
            msg.text = self._("Successfully logged in.")
            self.master_qr_picture_id = None
        elif uuid != self.qr_uuid:
            msg.type = MsgType.Image
            file = NamedTemporaryFile(suffix=".png")
            qr_url = "https://login.weixin.qq.com/l/" + uuid
            QRCode(qr_url).png(file, scale=10)
            msg.text = self._("QR code expired, please scan the new one.")
            msg.path = Path(file.name)
            msg.file = file
            msg.mime = 'image/png'
            if self.master_qr_picture_id is not None:
                msg.edit = True
                msg.edit_media = True
                msg.uid = self.master_qr_picture_id
            else:
                self.master_qr_picture_id = msg.uid
        if status in (200, 201) or uuid != self.qr_uuid:
            coordinator.send_message(msg)