예제 #1
0
def getDBQT(text):
    if getDataIsNoneDistinction(text):
        return {
            'message': {
                'text':
                '오늘의 큐티가 없습니다.\n' + '매일 12시 2~3분부터 이용 가능합니다. \n' +
                '이용에 문제가 있는경우 관리자에게 연락바랍니다.'
            },
            'keyboard': {
                'type':
                'buttons',
                'buttons':
                [kw.getDBQTBasicTitle(),
                 kw.getDBQTSoonTitle(),
                 kw.getHome()]
            }
        }
    else:
        return {
            'message': {
                'text': text
            },
            'keyboard': {
                'type':
                'buttons',
                'buttons':
                [kw.getDBQTBasicTitle(),
                 kw.getDBQTSoonTitle(),
                 kw.getHome()]
            }
        }
예제 #2
0
def getApproveUserList(text):
    if getDataIsNoneDistinction(text):
        return {
            'message': {
                'text': u'사용중인 유저가 없습니다.'
            },
            'keyboard': {
                'type':
                'buttons',
                'buttons': [
                    kw.getWaitList(),
                    kw.getChangeUserState(),
                    kw.getApproveList(),
                    kw.getHome()
                ]
            }
        }
    else:
        return {
            'message': {
                'text': text
            },
            'keyboard': {
                'type':
                'buttons',
                'buttons': [
                    kw.getWaitList(),
                    kw.getChangeUserState(),
                    kw.getApproveList(),
                    kw.getHome()
                ]
            }
        }
예제 #3
0
def getApplyQuietTime():
    return {
        'message': {
            'text': '감사합니다. 관리자의 확인 작업 이후부터 서비스 사용이 가능해집니다.'
        },
        'keyboard': {
            'type': 'buttons',
            'buttons': [kw.getHome()]
        }
    }
예제 #4
0
def getUnappliedUserCase():
    return {
        'message': {
            'text': '서비스를 이용하기 위해서는 서비스 사용 신청을 진행해 주시기 바랍니다.'
        },
        'keyboard': {
            'type': 'buttons',
            'buttons': [kw.getApply(), kw.getHome()]
        }
    }
예제 #5
0
def getDisapprovedUserCase():
    return {
        'message': {
            'text':
            '관리자의 확인이 되지 않은 상태입니다.\n' + '관리자의 확인 작업 이후부터 서비스 사용이 가능해집니다.'
        },
        'keyboard': {
            'type': 'buttons',
            'buttons': [kw.getHome()]
        }
    }
예제 #6
0
def getLLQTChoice():
    return {
        'message': {
            'text': '항목을 선택해주세요.'
        },
        'keyboard': {
            'type': 'buttons',
            'buttons':
            [kw.getLLQTSubTitle(),
             kw.getLLQTCommentary(),
             kw.getHome()]
        }
    }
예제 #7
0
def getQTChoice():
    return {
        'message': {
            'text': '항목을 선택해주세요.'
        },
        'keyboard': {
            'type': 'buttons',
            'buttons':
            [kw.getLLQTMainTitle(),
             kw.getDBQTMainTitle(),
             kw.getHome()]
        }
    }
예제 #8
0
def getEnterIncorrectlyWord():
    return {
        'message': {
            'text': u'잘못 입력하셨습니다.'
        },
        'keyboard': {
            'type':
            'buttons',
            'buttons': [
                kw.getWaitList(),
                kw.getChangeUserState(),
                kw.getApproveList(),
                kw.getHome()
            ]
        }
    }
예제 #9
0
def getAdminMode():
    return {
        'message': {
            'text': u'관리자 모드입니다.'
        },
        'keyboard': {
            'type':
            'buttons',
            'buttons': [
                kw.getWaitList(),
                kw.getChangeUserState(),
                kw.getApproveList(),
                kw.getHome()
            ]
        }
    }
예제 #10
0
def getAdmin():
    return {
        'message': {
            'text': u'관리자로 확인되었습니다.'
        },
        'keyboard': {
            'type':
            'buttons',
            'buttons': [
                kw.getLLQTMainTitle(),
                kw.getDBQTMainTitle(),
                kw.getAdminFunction(),
                kw.getHome()
            ]
        }
    }
예제 #11
0
def handle(response, context):
    if response:
        content = response['content']
        user_key = response['user_key']

        if content == kw.getTodaysQTMainTitle():
            user_table = dynamodb.get_user_table()
            user_data = dynamodb.query_target_user(user_table, user_key)

            if user_data:
                if const.KEY_USER_ADMIN in user_data:
                    admin = user_data[const.KEY_USER_ADMIN]
                    if admin == 'TRUE':
                        return answer.getAdmin()

                admission = user_data[const.KEY_USER_ADMISSION]
                if admission == 'TRUE':
                    return answer.getQTChoice()
                else:
                    return answer.getDisapprovedUserCase()
            else:
                return answer.getUnappliedUserCase()

        elif content == kw.getAdminFunction():
            return answer.getAdminMode()

        elif content == kw.getLLQTMainTitle():
            return answer.getLLQTChoice()

        elif content == kw.getDBQTMainTitle():
            return answer.getDBQTChoice()

        elif content == kw.getLLQTSubTitle():
            living_life_qt_table = dynamodb.get_living_life_qt_table()
            data = dynamodb.query_living_life_qt(living_life_qt_table)
            if data is None:
                return answer.getLLQT(data)
            else:
                return answer.getLLQT(data[const.KEY_LIVING_LIFE_DATA])

        elif content == kw.getLLQTCommentary():
            living_life_qt_table = dynamodb.get_living_life_qt_table()
            data = dynamodb.query_living_life_qt(living_life_qt_table)
            if data is None:
                return answer.getLLQT(data)
            else:
                return answer.getLLQT(data[const.KEY_LIVING_LIFE_COMM])

        elif content == kw.getDBQTBasicTitle():
            daily_bible_qt_table = dynamodb.get_daily_bible_qt_table()
            data = dynamodb.query_daily_bible_qt(daily_bible_qt_table)
            if data is None:
                return answer.getDBQT(data)
            else:
                return answer.getDBQT(data[const.KEY_DAILY_BIBLE_DATA])

        elif content == kw.getDBQTSoonTitle():
            daily_bible_qt_table = dynamodb.get_daily_bible_qt_table()
            data = dynamodb.query_daily_bible_qt(daily_bible_qt_table)
            return answer.getDBQT(data[const.KEY_DAILY_BIBLE_SOON])

        elif content == kw.getHome():
            return answer.getMain()

        elif content == kw.getApply():
            return answer.getApplyManual()

        elif content == kw.getChangeUserState():
            return answer.getUserStateChangeMode()

        elif content == kw.getWaitList():
            user_table = dynamodb.get_user_table()
            waitList = dynamodb.query_wait_user(user_table)
            if waitList is not None:
                userList = list()
                for target in waitList:
                    userList.append(target[const.KEY_USER_KEY] + ' : ' +
                                    target[const.KEY_USER_INFO] + '\n')
                waitString = '\n'.join(userList)
                return answer.getWaitUserList(waitString)
            else:
                return answer.getWaitUserList(None)
        elif content == kw.getApproveList():
            user_table = dynamodb.get_user_table()
            approveList = dynamodb.query_approve_user(user_table)
            if approveList is not None:
                userList = list()
                for target in approveList:
                    userList.append(target[const.KEY_USER_KEY] + ' : ' +
                                    target[const.KEY_USER_INFO] + '\n')
                approveString = '\n'.join(userList)
                return answer.getApproveUserList(approveString)
            else:
                return answer.getApproveUserList(None)
        else:
            user_table = dynamodb.get_user_table()
            user_data = dynamodb.query_target_user(user_table, user_key)

            if user_data:
                if const.KEY_USER_ADMIN in user_data:
                    admin = user_data[const.KEY_USER_ADMIN]
                    if admin == 'TRUE':
                        target_user_data = dynamodb.query_target_user(
                            user_table, content)
                        if target_user_data:
                            admission = target_user_data[
                                const.KEY_USER_ADMISSION]
                            if admission == 'FALSE':
                                dynamodb.update_user(user_table, content,
                                                     'TRUE')
                                return answer.getUserStateChangeResult(
                                    content + ' : FALSE -> TRUE')
                            else:
                                dynamodb.update_user(user_table, content,
                                                     'FALSE')
                                return answer.getUserStateChangeResult(
                                    content + ' : TRUE -> FALSE')
                        else:
                            return answer.getEnterIncorrectlyWord()
                else:
                    return answer.getWrongAccess()
            else:
                dynamodb.insert_user(user_table, user_key, content)
                slack.send_message(os.environ['CHANNEL_ID'],
                                   '%s : %s' % (user_key, content))
                return answer.getApplyQuietTime()

    return {'status': 200}