setting.py 12 KB
#-*-coding: utf-8 -*-
import os
import sys
from flask import request
import datetime

import random

sys.path.append(os.path.dirname(os.path.dirname("main")))
from Functions.getInstance import *
from Functions.checkFunction import *
from Functions.updateDatabase import *
from Functions.messageTypes import *
from Functions import pyjosa

# 환경설정 시작
def get_startSetting_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)
    petId = getPetId(kakaoUserKey)
    petName = getPetName(petId)
    nickname = getUserNickname(kakaoUserKey)
    accountId = getAccountIdusingUserKey(kakaoUserKey)
    myFonts = getUserProfileFonts(kakaoUserKey)
    myDogiPoint = getUserDogiPoint(kakaoUserKey)
    myBadges = getUserProfileBadges(kakaoUserKey)

    # 프로필 리스트
    outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname)

    # setting button window
    qrList += settingButtonWindow(kakaoUserKey, petName)

    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]메인', datetime.datetime.now(), 'none')

    return ordinaryMessageType(contextList, outputList, qrList)

def get_quitSetting_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)
    petId = getPetId(kakaoUserKey)
    petName = getPetName(petId)

    outputList.append(simpleText('[시스템] 설정이 완료되었습니다'))

    # 챗봇 노란버튼
    qrList = basicButtonWindow(petName)

    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]종료', datetime.datetime.now(), 'none')
    return ordinaryMessageType(contextList, outputList, qrList)

def get_tryConnectAfterRegister_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)

    outputList.append(simpleText('스마트폰 공기계를 구하셨나보네요😃!'))
    outputList.append(simpleText('기기연동을 바로 진행하겠습니다'))
    qrList.append(blockQuickReply('생각해볼게요↩️', '생각해볼게요↩️', '5e576884ffa7480001ef080b'))
    qrList.append(blockQuickReply('진행합니다', '진행합니다', '5d3fa9d48192ac0001fc4ed1'))

    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]기기연동시도', datetime.datetime.now(), 'none')
    return ordinaryMessageType(contextList, outputList, qrList)

def get_quitConnectAfterRegister_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)
    petId = getPetId(kakaoUserKey)
    petName = getPetName(petId)
    nickname = getUserNickname(kakaoUserKey)
    accountId = getAccountIdusingUserKey(kakaoUserKey)
    myFonts = getUserProfileFonts(kakaoUserKey)
    myDogiPoint = getUserDogiPoint(kakaoUserKey)
    myBadges = getUserProfileBadges(kakaoUserKey)

    outputList.append(simpleText('준비가 되면 다시 찾아와주세요'))

    # 프로필 리스트
    outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname)

    # setting button window
    qrList = settingButtonWindow(kakaoUserKey, petName)

    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]기기연동취소', datetime.datetime.now(), 'none')
    return ordinaryMessageType(contextList, outputList, qrList)

# 해당 챗봇과 연동된 모든 사용자데이터를 삭제 시도
def get_tryRemoveUser_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)

    outputList.append(simpleText('[시스템] 기기 연동을 해제하시겠습니까?'))
    outputList.append(simpleText('⚠️계속 진행할 시 카카오톡 내의 사용자 정보가 모두 삭제됩니다'))
    outputList.append(simpleText('(어플리케이션의 계정정보는 삭제되지 않으며, 다시 이용하려면 기기연동을 다시 진행해야합니다.)'))
    qrList.append(blockQuickReply('생각해볼게요↩️', '생각해볼게요↩️', '5dc0040fb617ea000165f420'))
    qrList.append(blockQuickReply('계속하겠습니다⚠️', '계속하겠습니다⚠️', '5dc00419b617ea000165f422'))

    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]유저삭제시도', datetime.datetime.now(), 'none')

    return ordinaryMessageType(contextList, outputList, qrList)

# 유저 삭제 과정 철회
def get_quitRemoveUser_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)
    petId = getPetId(kakaoUserKey)
    petName = getPetName(petId)
    nickname = getUserNickname(kakaoUserKey)
    accountId = getAccountIdusingUserKey(kakaoUserKey)
    myFonts = getUserProfileFonts(kakaoUserKey)
    myDogiPoint = getUserDogiPoint(kakaoUserKey)
    myBadges = getUserProfileBadges(kakaoUserKey)

    outputList.append(simpleText('[시스템] 취소되었습니다'))

    # 프로필 리스트
    outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname)

    # setting button window
    qrList = settingButtonWindow(kakaoUserKey, petName)

    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]유저삭제취소', datetime.datetime.now(), 'none')

    return ordinaryMessageType(contextList, outputList, qrList)

# kakaoUserKey로 특정 유저 찾아서 삭제
def get_removeUser_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)

    # 유저의 모든 게시물 삭제
    removeUserAllPost(kakaoUserKey)
    # S3에서 유저가 등록한 이미지 삭제
    deleteUserImageInStorage(kakaoUserKey)
    # 유저 db 삭제
    removeUser(kakaoUserKey)

    outputList.append(simpleText('[시스템] 기기 연동이 해제되었습니다'))
    outputList.append(simpleText('다시 연동하려면 인사를 건네주세요'))
    outputList.append(simpleText('(그만)'))

    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]유저삭제성공', datetime.datetime.now(), 'none')

    return ordinaryMessageType(contextList, outputList, qrList)

# 반려동물 말투 변경 시도
def get_tryChangeFont_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)
    petId = getPetId(kakaoUserKey)
    petName = getPetName(petId)

    outputList.append(simpleText('[시스템] ' + petName + '의 말투를 재설정합니다'))
    outputList.append(simpleText('말투를 골라주세요'))
    qrList.append(blockQuickReply('생각해볼게요↩️', '생각해볼게요↩️', '5dc0040fb617ea000165f420'))
    fonts = getUserFonts(kakaoUserKey)
    fontList = []
    for font in fonts:
        fontList.append(getFontFromVar(font['font']))
    qrList = fontSettingWindow(fontList)
    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]말투변경시도', datetime.datetime.now(), 'none')

    return ordinaryMessageType(contextList, outputList, qrList)

# 말투 변경 과정 철회
def get_quitChangeFont_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)
    petId = getPetId(kakaoUserKey)
    petName = getPetName(petId)
    nickname = getUserNickname(kakaoUserKey)
    accountId = getAccountIdusingUserKey(kakaoUserKey)
    myFonts = getUserProfileFonts(kakaoUserKey)
    myDogiPoint = getUserDogiPoint(kakaoUserKey)
    myBadges = getUserProfileBadges(kakaoUserKey)

    outputList.append(simpleText('[시스템] 취소되었습니다'))

    # 프로필 리스트
    outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname)

    # setting button window
    qrList = settingButtonWindow(kakaoUserKey, petName)

    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]말투변경취소', datetime.datetime.now(), 'none')

    return ordinaryMessageType(contextList, outputList, qrList)

# 반려동물과의 관계(relation) 변경 시도
def get_tryChangeRelation_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)
    petId = getPetId(kakaoUserKey)
    petName = getPetName(petId)

    outputList.append(simpleText('[시스템] ' + petName + '가 앞으로 당신을 뭐라고 불러주면 좋을까요?'))
    qrList.append(blockQuickReply('생각해볼게요↩️', '생각해볼게요↩️', '5dc0040fb617ea000165f420'))
    qrList = relationSettingWindow()

    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]호칭변경시도', datetime.datetime.now(), 'none')

    return ordinaryMessageType(contextList, outputList, qrList)

# 반려동물과의 관계(relation) 변경 과정 철회
def get_quitChangeRelation_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)
    petId = getPetId(kakaoUserKey)
    petName = getPetName(petId)
    nickname = getUserNickname(kakaoUserKey)
    accountId = getAccountIdusingUserKey(kakaoUserKey)
    myFonts = getUserProfileFonts(kakaoUserKey)
    myDogiPoint = getUserDogiPoint(kakaoUserKey)
    myBadges = getUserProfileBadges(kakaoUserKey)

    outputList.append(simpleText('[시스템] 취소되었습니다'))

    # 프로필 리스트
    outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname)

    # setting button window
    qrList = settingButtonWindow(kakaoUserKey, petName)

    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]호칭변경취소', datetime.datetime.now(), 'none')

    return ordinaryMessageType(contextList, outputList, qrList)

# 닉네임 변경 시도
def get_tryChangeNickname_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)

    outputList.append(simpleText('[시스템] 새로운 닉네임을 입력해주세요'))

    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]닉네임변경시도', datetime.datetime.now(), 'none')
    contextList.append(contextValue('nickname', 1, {'change_nickname': 'alive'}))
    return ordinaryMessageType(contextList, outputList, qrList)

# 닉네임 변경 과정 철회
def get_quitChangeNickname_message():
    contextList = []
    outputList = []
    qrList = []

    payload = request.get_json()
    kakaoUserKey = getKakaoUserKeyFromPayload(payload)
    petId = getPetId(kakaoUserKey)
    petName = getPetName(petId)
    nickname = getUserNickname(kakaoUserKey)
    accountId = getAccountIdusingUserKey(kakaoUserKey)
    myFonts = getUserProfileFonts(kakaoUserKey)
    myDogiPoint = getUserDogiPoint(kakaoUserKey)
    myBadges = getUserProfileBadges(kakaoUserKey)

    outputList.append(simpleText('[시스템] 취소되었습니다'))

    # 프로필 리스트
    outputList += userProfileList(accountId, myFonts, myDogiPoint, myBadges, nickname)

    # setting button window
    qrList = settingButtonWindow(kakaoUserKey, petName)

    # 메시지 로그 저장 sender: bot, receiver: user
    addMessageLogs('bot', kakaoUserKey, '[환경설정]닉네임변경취소', datetime.datetime.now(), 'none')

    return ordinaryMessageType(contextList, outputList, qrList)