def generateAnswer(self, userId, userText): userText = str(userText) if (commandProcess.isCommand(userText)): return commandProcess.process(userId, userText) if (self.getUserModule(userId) == "game"): status, answer = gameModule.nextStep(userId, userText) if (status == 'END'): self.setUserModule(userId, None) return answer if (self.getUserModule(userId) == "lackof"): status, answer = absenceModule.nextStep(userId, userText) if (status == 'END'): self.setUserModule(userId, None) return answer #FAQS botFAQS = faqs.get(userText) if botFAQS != None: return self.getAnswer([botFAQS], None) if (len(userText) > self.MAX_ALLOW_SENTENCES_LEN): botAnswer = [self.err_max_len()] botQuickAnswers = None return self.getAnswer(botAnswer, botQuickAnswers) classType = findClass.get(userText) classType = classType[:-1] bugReporter.updateHistory(userId, userText, "", classType) if (classType == 'game'): activeUsers.get(userId).choosingGame() self.setUserModule(userId, classType) return self.getAnswer(["Choose game"], None) if (classType == 'lackof'): self.setUserModule(userId, classType) status, answer = absenceModule.nextStep(userId, userText) if (status == 'END'): self.setUserModule(userId, None) return answer if (classType == 'other'): botAnswer = [govorilka.get(userText)] botQuickAnswers = [bugReporter.botBugReportPhrase] bugReporter.updateHistory(userId, userText, botAnswer, classType) return self.getAnswer(botAnswer, botQuickAnswers) curQuery = {} curQuery['answered'] = False curQuery['class'] = classType curQuery['date'] = findDate.get(userText) curQuery['subject'] = findSubject.get(userText) return [curQuery]
def endGame(self, userId): activeUsers.get(userId).detachGame() userGameData = self.userSessionId.get(userId) if (userGameData == None): return gameName, sessionId = userGameData gameAnswer = self.gameByName[gameName].closeSession(sessionId) self.userSessionId[userId] = None
def startGame(self, userId, gameName): generatedSessionKey = secrets.token_hex(16) self.userSessionId[userId] = (gameName, generatedSessionKey) try: gameAnswer, gameHelpMes = self.gameByName[gameName].startSession( generatedSessionKey) activeUsers.get(userId).attachGame() return (status.RESUME_GAME, gameAnswer, gameHelpMes) except: self.userSessionId[userId] = None activeUsers.get(userId).continueGame() return (status.RESUME_GAME, [ph.messNoSuchGame, ph.messTryAgain], [ph.buttonBreak])
def get(self, userId, userText): if (activeUsers.get(userId) == None): activeUsers.add(userId) if (activeUsers.get(userId).routines.get(userText) != None): routinesActions = activeUsers.get(userId).routines.get(userText) resultAnswer = list() for action in routinesActions: curAns = self.generateAnswer(userId, action) for answer in curAns: resultAnswer.append(answer) return resultAnswer return self.generateAnswer(userId, userText)
def nextStep(self, userId, tranferData): if (tranferData.lower() in ph.askEndGamePhrases): self.endGame(userId) return (status.END_GAME, [ph.messEndGame], None) userGameData = self.userSessionId.get(userId) if (userGameData == None): activeUsers.get(userId).detachGame() return (["Incorrect Session Key! Try to reboot game!"], None) gameName, sessionId = userGameData gameStatus, gameAnswer, gameHelpMes = self.gameByName[ gameName].nextStep(sessionId, tranferData) if (gameStatus == status.END_GAME): self.endGame(userId) return (gameStatus, gameAnswer, gameHelpMes)
def startGameByName(self, userId, gameName): gameName = gameName.lower() if (gameName in ph.askEndGamePhrases): self.endGame(userId) return (status.END_GAME, [ph.messEndGame], None) gameId = None for word in gameName.split(): if (self.gamesName.get(word) != None): gameId = self.gamesName[word] if (gameId == None): activeUsers.get(userId).choosingGame() return (status.RESUME_GAME, [ph.messNoSuchTitleGame, ph.messTryAgain], [ph.buttonBreak]) #activeUsers.get(userId).attachGame() return self.startGame(userId, gameId)
def process(self, userId, userText): command = userText.split(" ")[0] #print(command) if (userText == '/version'): resText = 'speechKit ' + __speechKit__ + '\n' resText += 'classifierKit ' + __classKit__ + '\n' resText += 'textKit ' + __textKit__ + '\n' resText += 'gameKit ' + __gameKit__ + '\n' resText += 'faqsKit ' + __faqsKit__ + '\n' resText += 'Build ' + __build__ + '\n' return self.getAnswer([resText], None) if (command == '/addRoutines'): return activeUsers.get(userId).routines.add(userText) if (command == '/myRoutines'): #print(activeUsers.get(userId).routines.get(userText)) return self.getAnswer(["DEBUG"], None) if (command == '/bug'): bugReporter.saveReport(userId) bugReporter.clearHistory(userId) botAnswer, botQuickAnswers = bugReporter.apologyPharse return self.getAnswer(botAnswer, botQuickAnswers)
def setUserModule(self, userId, moduleName): if (activeUsers.get(userId) != None): activeUsers.get(userId).activeModule = moduleName
def getUserModule(self, userId): if (activeUsers.get(userId) != None): return activeUsers.get(userId).activeModule return None
def isUserChooseGame(self, userId): if (activeUsers.get(userId) != None): return activeUsers.get(userId).isChoosingGame return False
def isUserInGame(self, userId): if (activeUsers.get(userId) != None): return activeUsers.get(userId).isInGame return False