コード例 #1
0
ファイル: run.py プロジェクト: superdun/mywebsite
def randomChat():

    waitingRoom = redis_store.get('waitingRoom')

    if not waitingRoom or waitingRoom == '':

        room = makeRoomNumber()
        session['room'] = room
        session['name'] = 'A'
        redis_store.set('waitingRoom', '%s:A' % room)
        return render_template('randomchat/chat.html', room=room, name='A')

    else:

        roomInform = waitingRoom.split(':')
        room = roomInform[0]
        if roomInform[1] == 'B':
            name = 'A'
        else:
            name = 'B'
        session['room'] = room
        session['name'] = name
        redis_store.set('waitingRoom', '')
        redis_store.set(room, "{\"A\":{\"count\":0,\"detail\":\"\"},\"B\":{\"count\":0,\"detail\":\"\"}}")
        return render_template('randomchat/chat.html', room=room, name=name)
コード例 #2
0
def date(message):
    room = session.get('room')
    name = session.get('name')
    rawChatRecord = redis_store.get(room)
    if rawChatRecord:
        chatRecord = json.loads(rawChatRecord)
        ACount = chatRecord['A']['count']
        BCount = chatRecord['B']['count']

        if ACount > 10 and BCount > 10:

            if chatRecord[name]['detail'] == '':
                chatRecord[name]['detail'] = {
                    'realName': message['realName'],
                    'phone': message['phone']
                }
                redis_store.set(room, json.dumps(chatRecord))
                if chatRecord['A']['detail'] != '' and chatRecord['B'][
                        'detail'] != '':
                    emit('dateResult', {
                        'msg':
                        u'你们成功交换了联系方式,对方的',
                        'A':
                        u'名字:%s,电话:%s' %
                        (chatRecord['A']['detail']['realName'],
                         chatRecord['A']['detail']['phone']),
                        'B':
                        u'名字:%s,电话:%s' %
                        (chatRecord['B']['detail']['realName'],
                         chatRecord['B']['detail']['phone']),
                        'status':
                        'ok'
                    },
                         room=room)
                else:
                    emit(
                        'dateResult', {
                            'msg': u'发送成功,在对方也决意交换联系方式之前,你的联系方式不会显示给对方',
                            'status': 'waiting'
                        })
            else:
                emit('dateResult', {
                    'msg': u'您已经发送过,不要重复发送',
                    'status': 'failed'
                })
        else:
            emit('dateResult', {'msg': u'再聊聊才能交换联系方式哦', 'status': 'failed'})
    else:
        emit('dateResult', {
            'msg': u'现在就你自己,和谁交换联系方式?请耐心等待',
            'status': 'failed'
        })
コード例 #3
0
def text(message):
    """Sent by a client when the user entered a new message.
    The message is sent to all people in the room."""
    room = session.get('room')
    name = session.get('name')
    msg = message['msg']
    filter = moduleTextFilter.Filter()
    filter.parse('static/keywords.txt')
    msg = filter.filter(msg)
    rawChatRecord = redis_store.get(room)
    if rawChatRecord:
        chatRecord = json.loads(rawChatRecord)
        chatRecord[name]['count'] = chatRecord[name]['count'] + 1
        redis_store.set(room, json.dumps(chatRecord))

    emit('message', {'msg': msg, 'name': name}, room=room)
コード例 #4
0
ファイル: run.py プロジェクト: superdun/mywebsite
def getChatInform():
    if request.args.get('room', '')==redis_store.get('waitingRoom').split(':')[0]:
        redis_store.set('waitingRoom', '')
    return redirect(url_for('randomChat'))