How to use the werobot.replies.WeChatReply 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_wechat_reply():
    message = parse_user_msg(
        """
        
        
        
        1348831860
        
        
        
        1234567890123456
        
    """
    )
    s = to_binary("喵fdsjaklfsk")
    reply = WeChatReply(message=message, s=s)
    assert reply._args['source'] == 'toUser'
    assert reply._args['target'] == 'fromUser'
    assert reply._args['s'] == to_text(s)
    assert isinstance(reply._args['time'], int)
github offu / WeRoBot / werobot / replies.py View on Github external
TEMPLATE = to_text(
        """
    
    
    
    {time}
    
    
    
    
    
    """
    )


class VideoReply(WeChatReply):
    TEMPLATE = to_text(
        """
    
    
    
    {time}
    
    <video>
    
    <title>&lt;![CDATA[{title}]]&gt;</title>
    
    </video>
    
    """
    )
github offu / WeRoBot / werobot / replies.py View on Github external
TEMPLATE = to_text(
        """
    
    
    
    {time}
    
    <img>
    
    
    
    """
    )


class VoiceReply(WeChatReply):
    TEMPLATE = to_text(
        """
    
    
    
    {time}
    
    
    
    
    
    """
    )


class VideoReply(WeChatReply):
github offu / WeRoBot / werobot / replies.py View on Github external
"""
            )
        else:
            return to_text(
                """
            
            
            
            {time}
            
            
            """
            )


class SuccessReply(WeChatReply):
    def render(self):
        return "success"


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)
github offu / WeRoBot / werobot / replies.py View on Github external
)
        else:
            self._articles.append(article)

    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)


class MusicReply(WeChatReply):
    TEMPLATE = to_text(
        """
    
    
    
    {time}
    
    
    <title>&lt;![CDATA[{title}]]&gt;</title>
    
    
    
    
    
    """
    )
github offu / WeRoBot / werobot / replies.py View on Github external
class TextReply(WeChatReply):
    TEMPLATE = to_text(
        """
    
    
    
    {time}
    
    <content></content>
    
    """
    )


class ImageReply(WeChatReply):
    TEMPLATE = to_text(
        """
    
    
    
    {time}
    
    <img>
    
    
    
    """
    )


class VoiceReply(WeChatReply):
github offu / WeRoBot / werobot / replies.py View on Github external
<title>&lt;![CDATA[{title}]]&gt;</title>
    
    
    
    
    
    """
    )

    def process_args(self, args):
        if 'hq_url' not in args:
            args['hq_url'] = args['url']


class TransferCustomerServiceReply(WeChatReply):
    @property
    def TEMPLATE(self):
        if 'account' in self._args:
            return to_text(
                """
            
            
            
            {time}
            
            
                 
             
            
            """
            )
github offu / WeRoBot / werobot / replies.py View on Github external
typename="Article",
    field_names=("title", "description", "img", "url"),
    tempalte=to_text(
        """
    
    <title>&lt;![CDATA[{title}]]&gt;</title>
    
    
    
    
    """
    )
)


class ArticlesReply(WeChatReply):
    TEMPLATE = to_text(
        """
    
    
    
    {time}
    
    <content></content>
    {count}
    {items}
    
    """
    )

    def __init__(self, message=None, **kwargs):
        super(ArticlesReply, self).__init__(message, **kwargs)
github offu / WeRoBot / werobot / replies.py View on Github external
for k, v in kwargs.items():
            if is_string(v):
                v = to_text(v)
            args[k] = v
        self.process_args(args)
        self._args = args

    def render(self):
        return to_text(self.TEMPLATE.format(**self._args))

    def __getattr__(self, item):
        if item in self._args:
            return self._args[item]


class TextReply(WeChatReply):
    TEMPLATE = to_text(
        """
    
    
    
    {time}
    
    <content></content>
    
    """
    )


class ImageReply(WeChatReply):
    TEMPLATE = to_text(
        """