コード例 #1
0
 def say_what(sess: TkChatSession, sig: Signal):
     assert isinstance(sig, Message)
     meta_data = SignalMetaData(origin=sig.meta_data.addressees[0]
                                if sig.meta_data.addressees else 'Bot',
                                addressees=[sig.meta_data.origin],
                                response_to=sig.meta_data.identifier,
                                sent_at=datetime.datetime.now(),
                                room=sig.meta_data.room)
     return Message(meta_data=meta_data,
                    content="You said: %s" % sig.content)
コード例 #2
0
 def on_submit(self, event=None):
     text = self._input_field.get().strip()
     self._input_field.delete(0, tkinter.END)
     if text:
         self.show(self.user_handle + ': ' + text)
         meta_data = SignalMetaData(
             identifier=SignalID(self.user_handle + str(time.time())),
             origin=Handle(self.user_handle),
             sent_at=datetime.datetime.now(),
         )
         signal = Message(meta_data=meta_data, content=text)
         self.receive(signal)
コード例 #3
0
ファイル: slack.py プロジェクト: hosford42/Chatty
    def _handle_inbound_message(self, event):
        # Make sure it's an ordinary message.
        if (event.get('subtype') or not event.get('text')
                or not event.get('channel') or event.get('hidden')
                or float(event.get('ts', 0)) < self._starting.timestamp()):
            # TODO: Convert these to the appropriate MIME representation and pass them on to receive().
            LOGGER.warning("Ignoring non-standard message: %s" % event)
            return

        # Keys: type, ts (time stamp string), team, user, channel, text
        content = event['text']
        meta_data = self._get_event_meta_data(event)
        message = Message(meta_data, content)
        self.receive(message)
コード例 #4
0
ファイル: email.py プロジェクト: hosford42/Chatty
    def email_to_signal(cls, message: EmailMessage) -> 'Signal':
        meta_data = SignalMetaData(
            identifier=message['message-id'],
            origin=message['from'],
            addressees=parse_email_address_list(message['to']),
            visible_to=parse_email_address_list(message['cc']),
            response_to=message['in-reply-to'],
            sent_at=parse_email_datetime(message['date']),
            received_at=parse_email_datetime(message['received']))

        # Check if it's a delivery failure notification.
        if is_delivery_status_notification(message):
            return DeliveryFailure(meta_data, content=message)

        return Message(meta_data, message)
コード例 #5
0
    def on_group_chat_message(self, message):
        try:
            LOGGER.info("Group-chat message received.")

            # Only handle group chat messages
            if message['type'] != 'groupchat':
                LOGGER.debug("Ignoring non-groupchat message.")
                return

            meta_data = self._get_meta_data(message)
            message = Message(meta_data, message['body'])
            self.receive(message)
        except Exception as exc:
            LOGGER.exception("Error in on_group_chat_message()")
            self._notify_thread_error(exc)
コード例 #6
0
    def on_message(self, message):
        try:
            LOGGER.info("Message received.")

            # Only handle regular chat messages
            if message['type'] not in ('chat', 'normal'):
                LOGGER.debug("Ignoring non-chat message.")
                return

            meta_data = self._get_meta_data(message)
            message = Message(meta_data, message['body'])
            self.receive(message)
        except Exception as exc:
            LOGGER.exception("Error in on_message()")
            self._notify_thread_error(exc)
コード例 #7
0
    def test_delivery_failure(self):
        sent_at = datetime.datetime.now()
        meta_data = SignalMetaData(
            identifier=SignalID('bad-message-%s' % sent_at.timestamp()),
            origin=Handle('mailer-daemon@' + self.smtp_config.host),
            addressees=[self.imap_config.handle_configs[0].handle],
            sent_at=sent_at)
        content = "Delivery failure"
        message = Message(meta_data, content)
        self.sender_session.send(message)

        for _ in range(self.max_receiver_delay * 1000):
            time.sleep(.001)
            if self.received:
                failure = self.received.popleft()
                break
        else:
            failure = self.received.popleft()
        assert isinstance(failure, DeliveryFailure)
        assert failure.meta_data.identifier == meta_data.identifier
コード例 #8
0
    def test_delivery_failure(self):
        sent_at = datetime.datetime.now()
        meta_data = SignalMetaData(
            origin=self.slack_config2.handle_configs[0].handle,
            addressees=[Handle('nonexistent_channel')],
            sent_at=sent_at
        )
        content = "Delivery failure"
        message = Message(meta_data, content)
        self.receiver_session.send(message)

        for _ in range(self.max_receiver_delay * 1000):
            time.sleep(.001)
            if self.received:
                failure = self.received.popleft()
                break
        else:
            failure = self.received.popleft()
        assert isinstance(failure, DeliveryFailure)
        assert failure.meta_data.identifier == meta_data.identifier