コード例 #1
0
ファイル: girl.py プロジェクト: sscst/sistsuer
def message(xml):
    dom = minidom.parseString(xml)
    root = dom.firstChild 
    children = [node for node in root.childNodes if node.nodeType == 1]

    mes_type = children[3].childNodes[0].data
    uid = children[1].childNodes[0].data
    me = children[0].childNodes[0].data
    status = user_status(uid,1,g)

    mes = "想跟我聊天?直接输入文字就好了"
    
    if mes_type == 'text':
        text = children[4].childNodes[0].data
        if text == 'Hello2BizUser':
            mes = "欢迎您关注中大信科学生会的微信!\n\n您可以通过#加吐嘈内容向我们提任何意见,我们将会及时回复。十分欢迎您对信科学生会的工作提出质疑与建议。此外,您可以输入任何文字跟我聊天,打发闲暇时间。\n\n信科女生节「逸仙传说」微信游戏正式上线!一个信科女神的奇幻故事,一段尘封许久的逸仙传说,一次精彩绝伦的冒险之旅!回复“女神冒险”开始一次伟大的冒险旅程!\n\n你的希望,我的可能!\nYour will, we will!"
        elif text[0] == '#':
            mes = advise(text[1:])
        elif text == '女神冒险' or not status == 'new' :
            mes = game(uid,text,g)
        else :
            mes = get_response(text)

    word_list = mes.split('#e#')
    if len(word_list) == 2 :
        return replypic % (uid,me,'%d' % (int(time.time())),word_list[1],word_list[0],word_list[0])
    return replytext % (uid,me,'%d' % (int(time.time())),word_list[0])
コード例 #2
0
ファイル: server.py プロジェクト: amiller/chitchat
    def post(userkey, **kwargs):
        status = game.user_status(userkey)
        if status['status'] == 'uninvited':
            flask.abort(403)

        # Check if we should be considering the form
        events = json.loads(flask.request.form['events'])
        for event in events:
            # Deal with the event
            game.process_user_event(userkey, event)
        return 'OK'
コード例 #3
0
ファイル: server.py プロジェクト: amiller/chitchat
    def quest(userkey):
        if userkey == ADMIN_KEY:
            return "Wow! You are an admin"

        # Return an error if they are not a valid user
        if not db.sismember('invited_userkeys', userkey):
            return 'This user key is not invited', 403

        # Go immediately to questover if we already have their survey 
        if db.exists('survey_user:%s' % userkey):
            return flask.redirect('/questover/%s/' % userkey)

        # Render the main page
        status = game.user_status(userkey)
        with open(os.path.join(base, 'static', 'quest.htm'), 'r') as fp:
            return fp.read().replace('{{userkey}}', userkey)\
                   .replace('{{role}}', status['role'])
コード例 #4
0
ファイル: server.py プロジェクト: amiller/chitchat
    def events(userkey):
        def response(events):
            rv = flask.make_response()
            rv.mimetype = 'text/json'
            rv.data = json.dumps(events)
            return rv
            
        status = game.user_status(userkey)
        if status['status'] == 'uninvited':
            return response([status])

        if status['status'] == 'queued':
            # try to avoid a race condition here
            with db.pipeline() as pipe:
                pipe.watch('user_status:%s' % userkey)
                status = json.loads(pipe.get('user_status:%s' % userkey))
                pipe.multi()
                assert status['status'] == 'queued'
                status['lastseen'] = repr(time())
                pipe['user_status:%s' % userkey] = json.dumps(status)
                pipe.execute()
                print 'refreshed!'

        for i in range(30):
            since = None
            if 'since' in flask.request.form:
                since = flask.request.form['since']
            events = game.events_for_user(userkey, since)

            # Return if there are some events
            if events:
                # Add a time event to help sync the alarms
                events.append({'name': 'time',
                               'time': repr(time()), 'data': {}})
                return response(events)

            # Otherwise wait and poll
            gevent.sleep(1)

        return response([])