Ejemplo n.º 1
0
    def post(self, post: Message) -> bool:

        self.reset()

        if post.should_skip:
            return False

        logger.info(f"TootPoster Working on {post.type} {post.id}")
        # logger.debug(post.dump_data())

        post.prepare_for_post(length=MASTODON_TOOT_LENGTH)

        if self.send:

            self.transfer_attachments(post)

            reply_to = None
            visibility = self.bridge.t_settings.toot_visibility
            if post.is_retweet:
                visibility = 'unlisted'

            if post.is_self_reply:
                mapping = self.session.query(Mapping).filter_by(
                    twitter_id=post.in_reply_to_id).first()

                if mapping:
                    reply_to = mapping.mastodon_id
                    logger.info(f"Replying to mastodon status {reply_to}")
                else:
                    # we don't know about this message which means it wasn't posted so let's skip it
                    logger.info("Skipping reply to unknown message")
                    return False

            if self.send:
                mastodon_last_id = self.send_toot(post.message_parts[0],
                                                  reply_to,
                                                  media_ids=self.media_ids,
                                                  sensitive=post.is_sensitive,
                                                  msg_type=post.type,
                                                  cw=post.cw,
                                                  visibility=visibility)

                if mastodon_last_id:
                    m = Mapping()
                    m.mastodon_id = mastodon_last_id
                    m.twitter_id = post.id
                    self.session.add(m)

                    self.bridge.mastodon_last_id = mastodon_last_id

                self.session.commit()

        else:
            logger.info(post.media_attachments)
            logger.info(post.clean_content)
            return False

        return True
Ejemplo n.º 2
0
    def post(self, post: Message) -> bool:

        self.reset()

        logger.info(f"TootPoster Working on {post.type} {post.id}")
        logger.debug(pp.pformat(post.dump_data()))

        if post.should_skip:
            return False

        post.prepare_for_post(length=MASTODON_TOOT_LENGTH)

        if self.send:

            self.transfer_attachments(post)

            reply_to = None

            if post.is_self_reply:
                mapping = self.session.query(Mapping).filter_by(twitter_id=post.in_reply_to_id).first()

                if mapping:
                    reply_to = mapping.mastodon_id
                    logger.info(f"Replying to mastodon status {reply_to}")

            if self.send:
                mastodon_last_id = self.send_toot(post.message_parts[0],
                                                  reply_to,
                                                  media_ids=self.media_ids,
                                                  sensitive=post.sensitive,
                                                  msg_type=post.type)
                logger.info(f"Toot ID: {mastodon_last_id}")

                if mastodon_last_id:
                    m = Mapping()
                    m.mastodon_id = mastodon_last_id
                    m.twitter_id = post.id
                    self.session.add(m)

                    self.bridge.mastodon_last_id = mastodon_last_id

                self.session.commit()

        else:
            logger.info(post.media_attachments)
            logger.info(post.clean_content)
            return False

        return True
Ejemplo n.º 3
0
    def post(self, post: Message) -> bool:

        self.reset()

        if post.should_skip:
            return False

        logger.info(f"TweetPoster Working on {post.type} {post.id}")
        # logger.debug(pp.pformat(post.dump_data()))

        post.prepare_for_post(length=TWEET_LENGTH)

        if self.send:

            if post.is_sensitive and self.bridge.t_settings.post_sensitive_behind_link:
                pass
            else:
                self.transfer_attachments(post)

            reply_to = None

            if post.is_self_reply:

                # In the case where a toot has been broken into multiple tweets
                # we want the last one posted
                mapping = self.session.query(Mapping).filter_by(
                    mastodon_id=post.in_reply_to_id).order_by(
                        Mapping.created.desc()).first()

                if mapping:
                    reply_to = mapping.twitter_id
                    logger.info(
                        f"Replying to Twitter status {reply_to} / masto status {post.in_reply_to_id}"
                    )
                else:
                    # we don't know about this message which means it wasn't posted so let's skip it
                    logger.info("Skipping reply to unknown message")
                    return False

            last_id = len(post.message_parts) - 1
            for index, status in enumerate(post.message_parts):

                # Do normal posting for all but the last tweet where we need to upload media
                if index == last_id:
                    reply_to = self.send_tweet(status, reply_to,
                                               self.media_ids)

                else:
                    reply_to = self.send_tweet(status, reply_to)

                if reply_to:
                    self.bridge.twitter_last_id = reply_to
                    logger.info(f"Tweet ID: {reply_to}")

                    if post.type == "Toot":
                        m = Mapping()
                        m.mastodon_id = post.id
                        m.twitter_id = reply_to
                        self.session.add(m)
                else:
                    return False

                if post.type == "Toot":
                    self.bridge.mastodon_last_id = post.id

                try:
                    self.session.commit()
                except OperationalError as e:
                    # MySQL might be down
                    logger.error(e)
                    sys.exit()

            return True
        else:
            # logger.info(post.media_attachments)
            logger.info(post.clean_content)
            return False
Ejemplo n.º 4
0
    def post(self, post: Message) -> bool:

        self.reset()

        logger.info(f"TweetPoster Working on {post.type} {post.id}")
        logger.debug(pp.pformat(post.dump_data()))

        if post.should_skip:
            return False

        post.prepare_for_post(length=TWEET_LENGTH)

        if self.send:

            self.transfer_attachments(post)

            reply_to = None

            if post.is_self_reply:

                # In the case where a toot has been broken into multiple tweets
                # we want the last one posted
                mapping = self.session.query(Mapping).filter_by(
                    mastodon_id=post.in_reply_to_id).order_by(
                        Mapping.created.desc()).first()

                if mapping:
                    reply_to = mapping.twitter_id
                    logger.info(
                        f"Replying to twitter status {reply_to} / masto status {post.in_reply_to_id}"
                    )

            last_id = len(post.message_parts) - 1
            for index, status in enumerate(post.message_parts):

                # Do normal posting for all but the last tweet where we need to upload media
                if index == last_id:
                    reply_to = self.send_tweet(status, reply_to,
                                               self.media_ids)

                else:
                    reply_to = self.send_tweet(status, reply_to)

                if reply_to:
                    self.bridge.twitter_last_id = reply_to
                    logger.info(f"Tweet ID: {reply_to}")

                    if post.type == "Toot":
                        m = Mapping()
                        m.mastodon_id = post.id
                        m.twitter_id = reply_to
                        self.session.add(m)
                else:
                    return False

                if post.type == "Toot":
                    self.bridge.mastodon_last_id = post.id

                self.session.commit()

            return True
        else:
            logger.info(post.media_attachments)
            logger.info(post.clean_content)
            return False