Beispiel #1
0
def echo(message):
    # 提取消息
    msg = message.content
    # 解析消息
    if  re.compile(".*?你好.*?").match(msg) or\
        re.compile(".*?嗨.*?").match(msg) or\
        re.compile(".*?哈喽.*?").match(msg) or\
        re.compile(".*?hello.*?").match(msg) or\
        re.compile(".*?hi.*?").match(msg) or\
        re.compile(".*?who are you.*?").match(msg) or\
        re.compile(".*?你是谁.*?").match(msg) or\
        re.compile(".*?你的名字.*?").match(msg) or\
        re.compile(".*?你谁啊.*?").match(msg) or\
        re.compile(".*?什么名字.*?").match(msg) :
        return "你好~\n我是菜鸡家萌萌哒φ(>ω<*) 的机器人哦,他是大菜鸡,我就是小菜鸡辣ヾ(=・ω・=)o(绅士脸)"
    elif re.compile(".*?(厉害|棒).*?").match(msg):
        return '承让承让 (๑•̀ㅂ•́)ﻭ✧'
    elif re.compile(".*?想你.*?").match(msg):
        return '我也想你'
    elif re.compile(".*?miss you.*?").match(msg):
        return 'I miss you,too'
    elif re.compile(".*?我爱你.*?").match(msg):
        return '我也爱你'
    elif re.compile(".*?love you.*?").match(msg):
        return 'I love you,too'
    elif re.compile(".*?美女.*?").match(msg):
        return '我是男生哦♂'
    elif re.compile(".*?帅哥.*?").match(msg):
        return '谢谢夸奖 (๑•̀ㅂ•́)ﻭ✧'
    elif re.compile(".*?是傻逼.*?").match(msg):
        return '我觉得你也是啊'
    elif re.compile(".*?傻逼.*?").match(msg):
        return '爸爸不想理你'

    elif re.compile(".*?(干啥|干什么|在干嘛).*?").match(msg):
        return do[random.randint(0, 3)]
    elif re.compile(".*?图片.*?").match(msg):
        reply = ImageReply(message=message, media_id=img_id)
        return reply
    elif re.compile(".*?唱.*?歌.*?").match(msg):
        reply = VoiceReply(message=message, media_id=voice_id)
        return reply
    elif re.compile(".*?音乐.*?").match(msg):
        reply = VoiceReply(message=message, media_id=voice_id)
        return reply
    elif re.compile(".*?(吗|呢).*?").match(msg):
        return say[random.randint(0, 3)]
    elif (msg == '文章'):
        #reply = client.send_news_message(message.source,news_id)#只有认证才可以进行客服消息回复,不然只能调取外部数据,使用Reply不接受media_id
        #return reply
        return "不好意思啊,我还没进行认证,无法发送微信文章哦"
    else:
        return msg
Beispiel #2
0
def test_voice_reply():
    t = int(time.time())
    reply = VoiceReply(
        target='tgu', source='su', media_id="fdasfdasfasd", time=t
    )
    assert reply.render().strip() == """
    <xml>
    <ToUserName><![CDATA[tgu]]></ToUserName>
    <FromUserName><![CDATA[su]]></FromUserName>
    <CreateTime>{time}</CreateTime>
    <MsgType><![CDATA[voice]]></MsgType>
    <Voice>
    <MediaId><![CDATA[fdasfdasfasd]]></MediaId>
    </Voice>
    </xml>""".format(time=t).strip()
Beispiel #3
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)
Beispiel #4
0
def test_voice_reply():
    t = int(time.time())
    reply = VoiceReply(target='tgu',
                       source='su',
                       media_id="fdasfdasfasd",
                       time=t)
    assert reply.render().strip() == """
    <xml>
    <ToUserName><![CDATA[tgu]]></ToUserName>
    <FromUserName><![CDATA[su]]></FromUserName>
    <CreateTime>{time}</CreateTime>
    <MsgType><![CDATA[voice]]></MsgType>
    <Voice>
    <MediaId><![CDATA[fdasfdasfasd]]></MediaId>
    </Voice>
    </xml>""".format(time=t).strip()
Beispiel #5
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()