How to use the werobot.replies.ArticlesReply function in WeRoBot

To help you get started, we’ve selected a few WeRoBot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github offu / WeRoBot / tests / test_replies.py View on Github external
def test_articles_reply():
    article = Article(
        title="tt", description="附近的萨卡里发生", img="http", url="uuu"
    )
    t = int(time.time())
    reply = ArticlesReply(target='tg', source='ss', time=t)
    assert reply.render().strip() == """
    
    
    
    {time}
    
    <content></content>
    0
    
    """.format(time=t).strip()

    reply._args['content'] = 'wwww'
    assert '<content></content>' in reply.render()
    reply.add_article(article)
    assert '1' in reply.render()
    assert article.render() in reply.render()
github offu / WeRoBot / tests / test_replies.py View on Github external
def test_process_articles_function_reply():
    reply = process_function_reply(
        [["tt1", 'ds1', 'img', 'url'], ["tt2", 'ds2', 'im2g', 'u2rl']]
    )
    assert isinstance(reply, ArticlesReply)
    assert len(reply._articles) == 2
    article_1, article_2 = reply._articles
    assert isinstance(article_1, Article), isinstance(article_2, Article)
    assert article_1.title == "tt1", article_2.title == "tt2"
    assert article_1.description == "ds1", article_2.description == "ds2"
    assert article_1.img == "img", article_2.img == "im2g"
    assert article_1.url == "url", article_2.url == "u2rl"

    process_function_reply([[1, 2, 3, 4]] * 10)

    with pytest.raises(AttributeError):
        process_function_reply([[1, 2, 3, 4]] * 11)
github liangliangyy / DjangoBlog / servermanager / robot.py View on Github external
def convert_to_articlereply(articles, message):
    reply = ArticlesReply(message=message)
    from blog.templatetags.blog_tags import custom_markdown, truncatechars_content
    from DjangoBlog.utils import CommonMarkdown
    from django.utils.safestring import mark_safe
    for post in articles:
        imgs = re.findall(r'(?:http\:|https\:)?\/\/.*\.(?:png|jpg)', post.body)
        imgurl = ''
        if imgs:
            imgurl = imgs[0]
        article = Article(
            title=post.title,
            description=truncatechars_content(post.body),
            img=imgurl,
            url=post.get_full_url()
        )
        reply.add_article(article)
    return reply
github offu / WeRoBot / werobot / replies.py View on Github external
def process_function_reply(reply, message=None):
    if is_string(reply):
        return TextReply(message=message, content=reply)
    elif isinstance(reply, list) and all([len(x) == 4 for x in reply]):
        if len(reply) &gt; 10:
            raise AttributeError(
                "Can't add more than 10 articles"
                " in an ArticlesReply"
            )
        r = ArticlesReply(message=message)
        for article in reply:
            article = Article(*article)
            r.add_article(article)
        return r
    elif isinstance(reply, list) and 3 &lt;= len(reply) &lt;= 4:
        if len(reply) == 3:
            # 如果数组长度为3, 那么高质量音乐链接的网址和普通质量的网址相同。
            reply.append(reply[-1])
        title, description, url, hq_url = reply
        return MusicReply(
            message=message,
            title=title,
            description=description,
            url=url,
            hq_url=hq_url
        )
github offu / WeRoBot / werobot / replies.py View on Github external
def __init__(self, message=None, **kwargs):
        super(ArticlesReply, self).__init__(message, **kwargs)
        self._articles = []
github offu / WeRoBot / werobot / replies.py View on Github external
def render(self):
        items = []
        for article in self._articles:
            items.append(article.render())
        self._args["items"] = ''.join(items)
        self._args["count"] = len(items)
        if "content" not in self._args:
            self._args["content"] = ''
        return ArticlesReply.TEMPLATE.format(**self._args)