Beispiel #1
0
    def error_content(self, message_content: MessageContent,
                      error_post: Optional[ErrorPost]) -> MessageContent:
        if not error_post:
            message = 'No posts found'
        else:
            message = error_post.message

        message_content.add_field(name='Error', value=message)
        message_content.color = Color.red()

        return message_content
Beispiel #2
0
    def to_message_content(self) -> MessageContent:
        embed = Embed()
        embed.colour = Color.red()
        embed.description = ''

        embed.add_field(name='Error', value=self.message)

        return MessageContent(embed=embed)
Beispiel #3
0
    def generic_display(self) -> MessageContent:
        post = self.fetcher.get_post()

        if not post:
            return self.error_content(MessageContent(), None)

        message_content = post.to_message_content()

        message_content.page = self.fetcher.paginator.display_page()
        message_content.total_pages = self.fetcher.paginator.post_count

        if isinstance(post, ErrorPost):
            return self.error_content(message_content, post)

        return self.success_content(message_content)
Beispiel #4
0
    def to_message_content(self) -> MessageContent:
        embed = Embed()
        embed.colour = Color.green()

        if self.source:
            embed.add_field(name='Source', value=self.source, inline=False)
        if self.created_at:
            if self.created_at.isnumeric():
                embed.timestamp = datetime.datetime.fromtimestamp(
                    int(self.created_at))
            else:
                embed.timestamp = parser.parse(self.created_at)
        if self.score:
            embed.set_footer(text=f'Score: {self.score}')

        if self.file_url:
            embed.set_image(url=self.file_url)

        return MessageContent(self.is_animated(), self.file_url, embed)
Beispiel #5
0
 def error_content(self, message_content: MessageContent, error_post: Optional[ErrorPost]) -> MessageContent:
     message_content.color = Color.red()
     message_content.add_field(name='Error', value=error_post.message)
     return message_content
Beispiel #6
0
 def success_content(self,
                     message_content: MessageContent) -> MessageContent:
     message_content.file_url = self.fetcher.get_post().file_url
     return message_content
Beispiel #7
0
 def to_message_content(self) -> MessageContent:
     return MessageContent(title='Error',
                           description=self.message,
                           color=Color.red())
Beispiel #8
0
 def to_message_content(self) -> MessageContent:
     return MessageContent(**self.__dict__)