Esempio n. 1
0
 def process_args(self, kwargs):
     args = defaultdict(str)
     for k, v in kwargs.items():
         if is_string(v):
             v = to_text(v)
         args[k] = v
     return args
Esempio n. 2
0
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) > 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 <= len(reply) <= 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
        )
    return reply
Esempio n. 3
0
 def process_args(self, kwargs):
     args = defaultdict(str)
     for k, v in kwargs.items():
         if is_string(v):
             v = to_text(v)
         args[k] = v
     return args
Esempio n. 4
0
 def onclick(message, session):
     _name, action_id = message.key.split(',')
     action_id = int(action_id)
     if _name:
         action = request.env()[_name].sudo().browse(action_id)
         ret = action.get_wx_reply()
         if is_string(ret):
             return create_reply(ret, message=message)
         elif isinstance(ret, list):
             return create_reply(ret, message=message)
         elif type(ret)==dict:
             media = ret
             media_type = media['media_type']
             media_id = media['media_id']
             from werobot.replies import ImageReply, VoiceReply, VideoReply, ArticlesReply
             if media_type=='image':
                 return ImageReply(message=message, media_id=media_id).render()
             elif media_type=='voice':
                 return VoiceReply(message=message, media_id=media_id).render()
             elif media_type=='video':
                 return VideoReply(message=message, media_id=media_id).render()
             elif media_type=='news':
                 from .. import client
                 entry = client.wxenv(request.env)
                 entry.wxclient.send_news_message(message.source, media_id)
Esempio n. 5
0
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) > 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 <= len(reply) <= 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
        )
    return reply
Esempio n. 6
0
def create_reply(reply, message=None):
    if isinstance(reply, WeChatReply):
        return reply.render()
    elif is_string(reply):
        reply = TextReply(message=message, content=reply)
        return reply.render()
    elif isinstance(reply, list) and all([len(x) == 4 for x in reply]):
        if len(reply) > 10:
            raise AttributeError("Can't add more than 10 articles"
                                 " in an ArticlesReply")
        r = NewsReply(message=message)
        for article in reply:
            article = Article(*article)
            r.add_article(article)
        return r.render()
Esempio n. 7
0
    def __init__(self, message=None, **kwargs):
        if message and "source" not in kwargs:
            kwargs["source"] = message.target

        if message and "target" not in kwargs:
            kwargs["target"] = message.source

        if 'time' not in kwargs:
            kwargs["time"] = int(time.time())

        args = defaultdict(str)
        for k, v in kwargs.items():
            if is_string(v):
                v = to_text(v)
            args[k] = v
        self.process_args(args)
        self._args = args
Esempio n. 8
0
    def __init__(self, message=None, **kwargs):
        if message and "source" not in kwargs:
            kwargs["source"] = message.target

        if message and "target" not in kwargs:
            kwargs["target"] = message.source

        if 'time' not in kwargs:
            kwargs["time"] = int(time.time())

        args = defaultdict(str)
        for k, v in kwargs.items():
            if is_string(v):
                v = to_text(v)
            args[k] = v
        self.process_args(args)
        self._args = args
Esempio n. 9
0
    def __init__(self, message=None, **kwargs):
        if "source" not in kwargs and isinstance(message, WeChatMessage):
            kwargs["source"] = message.target

        if "target" not in kwargs and isinstance(message, WeChatMessage):
            kwargs["target"] = message.source

        if 'time' not in kwargs:
            kwargs["time"] = int(time.time())

        args = dict()
        for k, v in kwargs.items():
            if is_string(v):
                v = to_text(v)
            args[k] = v

        self._args = args
Esempio n. 10
0
 def onclick(message, session):
     _name, action_id = message.key.split(',')
     action_id = int(action_id)
     if _name:
         action = request.env()[_name].sudo().browse(action_id)
         ret = action.get_wx_reply()
         if is_string(ret):
             return create_reply(ret, message=message)
         elif isinstance(ret, list):
             return create_reply(ret, message=message)
         else:
             media = ret
             media_type = media.media_type
             from werobot.replies import ImageReply, VoiceReply, VideoReply, ArticlesReply
             if media_type=='image':
                 return ImageReply(message=message, media_id=media.media_id).render()
             elif media_type=='voice':
                 return VoiceReply(message=message, media_id=media.media_id).render()
             elif media_type=='video':
                 return VideoReply(message=message, media_id=media.media_id).render()