Ejemplo n.º 1
0
def test_image_reply():
    t = int(time.time())
    reply = ImageReply(
        target='fromUser', source='toUser', media_id="fdasfdasfasd", time=t
    )
    assert reply.render().strip() == """
    <xml>
    <ToUserName><![CDATA[fromUser]]></ToUserName>
    <FromUserName><![CDATA[toUser]]></FromUserName>
    <CreateTime>{time}</CreateTime>
    <MsgType><![CDATA[image]]></MsgType>
    <Image>
    <MediaId><![CDATA[fdasfdasfasd]]></MediaId>
    </Image>
    </xml>""".format(time=t).strip()
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
def test_image_reply():
    t = int(time.time())
    reply = ImageReply(target='fromUser',
                       source='toUser',
                       media_id="fdasfdasfasd",
                       time=t)
    assert reply.render().strip() == """
    <xml>
    <ToUserName><![CDATA[fromUser]]></ToUserName>
    <FromUserName><![CDATA[toUser]]></FromUserName>
    <CreateTime>{time}</CreateTime>
    <MsgType><![CDATA[image]]></MsgType>
    <Image>
    <MediaId><![CDATA[fdasfdasfasd]]></MediaId>
    </Image>
    </xml>""".format(time=t).strip()
Ejemplo n.º 4
0
def blog(message,session):
    #print("msg", message.img)
    #print(type(message))
    #print(type(message.img))
    #print(message.__dict__)
    print("\n"+message.MediaId)
    changdu = str(len(session))
    session[changdu] = message.MediaId
    reply = ImageReply(message=message, media_id=message.MediaId)
    return reply
Ejemplo n.º 5
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
Ejemplo n.º 6
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()
Ejemplo n.º 7
0
def GetAnswer(problem, message):
    origin = 'Shanghai'
    r_sh = requests.post(
        'http://trash.lhsr.cn/sites/feiguan/trashTypes_2/TrashQuery_h5.aspx?kw='
        + problem)
    if (r_sh.status_code == 200):  #未考虑不是中文的情况
        reply = getHtml(r_sh.text)
    else:
        print('status_code:' + str(r_sh.status_code))
    if (reply == 0):
        origin = 'sap'
        payload = {'text': problem, 'language': 'zh'}
        headers = {
            'Authorization': 'Token 2ddf07e6a963d970354cd553f2a3c425',
            'content-type': 'application/json'
        }
        r_sap = requests.post("https://api.cai.tools.sap/v2/request",
                              data=json.dumps(payload),
                              headers=headers)
        #print(r.text)
        try:
            intents__ = json.loads(r_sap.text)['results']['intents']
        except TypeError:
            print('TypeError Happens:')
            print(json.loads(r_sap.text)['results'])
        if (intents__ == []):
            log_collect_data.info(
                '%s %s %s none %s' %
                (message.source, problem, message.type, origin))
            return reply_none
        else:
            reply = intents__[0]['slug']

    if (reply == 'greeting' or reply == 'famous_person'):
        return Reply2Picture[reply]
    # log record
    log_collect_data.info(
        '%s %s %s %s %s' %
        (message.source, problem, message.type, reply, origin))
    return ImageReply(message=message, media_id=Reply2Picture[reply])
Ejemplo n.º 8
0
def hello(message):
    print(message.content)
    if message.content.lower() in ['hello', '你好', '好', 'hi']:
        return "Hello, 欢迎来到【3E女子商学院】的世界"
    if message.content.lower() in ['ak', '猩猩', '李胖娃', '胖娃', '胖娃儿']:
        return "{} loves Winnie".format(message.content)
    if message.content.lower() in ['课表', 'kebiao', '课程表', '日程']:
        reply = ArticlesReply(message=message)
        article = Article(
            title="课表",
            description="3E女子商学院课表",
            img=
            '''https://github.com/Akagilnc/Landing_Page_3EWBS/blob/master/img/3e_logo.jpeg?raw=true''',
            url='''http://www.3ewbs.com/class_schedule.html''')
        reply.add_article(article)
        return reply
    if message.content.lower() in ['location', '地点', '教室']:
        reply = ImageReply(
            message=message,
            media_id='CVHC0-1CfQ0wxmPCoRJIMTg2kUalhmdPYsIfbDwBrfQ')
        return reply
    return "主人正在努力挖土烧砖盖楼 \n内容很快就来 \n不要着急 \n休息 \n休息一下"
Ejemplo n.º 9
0
def ImgReturn(key, message):
    return ImageReply(message, media_id=key['media_id'])
Ejemplo n.º 10
0
def img(message):
    #media_id = client.upload_media("image", url_img_to_fd(message.img))["media_id"]
    media_id = message.media_id
    return ImageReply(message=message, media_id=media_id)
Ejemplo n.º 11
0
def media(message):
    media_id = client.upload_permanent_media(
        'image', open(r'C:\Users\haojin\Desktop\favicon.png',
                      'rb'))['media_id']
    reply = ImageReply(message=message, media_id=media_id)
    return reply
Ejemplo n.º 12
0
 def return_single_pic(message):
     reply = ImageReply(message=message, media_id="")
     return reply
Ejemplo n.º 13
0
 def get_signal_info(message):
     reply = ImageReply(message=message,
                        media_id=media_ids["signal_media_id"])
     return reply
Ejemplo n.º 14
0
 def whitelist(message):
     reply = ImageReply(
         message=message,
         media_id="mEloyztypmjpHsAx8NnTl5A1XSyF37zbEriN81PNMxE")
     return reply
Ejemplo n.º 15
0
 def business(message):
     reply = ImageReply(
         message=message,
         media_id="mEloyztypmjpHsAx8NnTlz4c8GiuEUxnBULz135LaF0")
     return reply
Ejemplo n.º 16
0
 def communication(message):
     reply = ImageReply(
         message=message,
         media_id="mEloyztypmjpHsAx8NnTlyIcOmY2ql-PAdfs8fEJRJY")
     return reply