Esempio n. 1
0
 def continueQuestion(self):
     senderId = self.senderId
     self.newFavorite = getInDB(senderId, "response")
     self.newFavoriteType = getInDB(senderId, "type")
     if self.acceptNewFavorite() and self.newFavorite and self.newFavorite != "None":
         messageToSend = self.setNewFavoriteInDb()
     elif (
         self.newFavoriteType
         and self.newFavoriteType != "None"
         and self.categories.get("favorite")
     ):
         self.newFavorite = self.categories.get("favorite")
         messageToSend = self.setNewFavoriteInDb()
     elif (
         self.newFavoriteType
         and self.newFavoriteType != "None"
         and self.categories.get("response")
         and "oui" not in self.getCategoryValue("response")
         and "correct" not in self.getCategoryValue("response")
         and "bien sûr" not in self.getCategoryValue("response")
         and "non" not in self.getCategoryValue("response")
     ):
         self.newFavorite = self.categories.get("response")
         messageToSend = self.setNewFavoriteInDb()
     elif self.acceptNewFavorite():
         messageToSend = self.askNewFavorite()
     else:
         messageToSend = "Ah, ok. Donc on ne change pas"
         setInDB(senderId, {"response": None, "question": None, "type": None})
     return messageToSend
Esempio n. 2
0
 def __init__(self, senderId, bot, categories, payload):
     super().__init__(senderId, bot, categories)
     self.payload = payload
     if getInDB(self.senderId, "state"):
         self.state = getInDB(self.senderId, "state")
     else:
         self.state = {}
Esempio n. 3
0
 def test_deleteFromDB(self):
     """
     tests setInDB, deleteFromDB and getInDB
     """
     setInDB(0, {"name": "Joe"})
     self.assertTrue(getInDB(0, "name"), "is in db")
     deleteFromDB(0)
     self.assertFalse(getInDB(0, "name"), "is not in db anymore")
Esempio n. 4
0
 def getResponseContinueWithQuestion(self):
     getInDB(self.senderId, "question")
     if "response" in self.categories:
         setInDB(self.senderId, {"question": None})
         messageToSend = self.getContinueHowAreYouQuestion()
     else:
         setInDB(self.senderId, {"question": None})
         messageToSend = {"RICKROLL": ["hmm, ok", "voici ce que je pense"]}
     return messageToSend
Esempio n. 5
0
 def getMessageToSend(self):
     categories = self.categories
     senderId = self.senderId
     question = []
     if getInDB(senderId, "question"):
         question = getInDB(senderId, "question")
     setInDB(senderId, {"question": None})
     if "location" in question:
         messageToSend = self.continueQuestion()
     else:
         self.newLocation = str(categories["location"])
         if getInDB(senderId, "location") != self.newLocation:
             messageToSend = self.askToChangeLocation()
         else:
             messageToSend = self.setNewLocationInDb()
     return messageToSend
Esempio n. 6
0
 def setResponse(self):
     if not (getInDB(self.senderId, "question")):
         response = self.getCoronaNewsElements()
     else:
         response = self.setNewsRecurrence()
     self.messageToSend = response["message"]
     self.messageType = response["type"]
Esempio n. 7
0
 def nextLyrics(self):
     lyricFromUser = self.categories.get("rickSong")
     nextLyrics = "We're no strangers to love"
     lyricIndice = 0
     if getInDB(self.senderId, "rickPartLastLyrics"):
         if int(getInDB(self.senderId, "rickPartLastLyrics") +
                2) < len(neverGonnaGiveYouUp):
             nextLyrics = neverGonnaGiveYouUp[int(
                 getInDB(self.senderId, "rickPartLastLyrics") + 2)]
             lyricIndice = getInDB(self.senderId, "rickPartLastLyrics")
     for i in range(lyricIndice, len(neverGonnaGiveYouUp)):
         if neverGonnaGiveYouUp[i] == lyricFromUser:
             nextLyrics = neverGonnaGiveYouUp[i + 1]
             setInDB(self.senderId, {"rickPartLastLyrics": i + 1})
             break
     return nextLyrics
Esempio n. 8
0
 def continueQuestion(self):
     senderId = self.senderId
     self.newLocation = getInDB(senderId, "response")
     if self.acceptNewLocation():
         messageToSend = self.setNewLocationInDb()
     else:
         messageToSend = "Ah, ok. Donc on ne change pas"
     setInDB(senderId, {"response": None})
     return messageToSend
Esempio n. 9
0
 def test_TicTacToeResponse(self):
     categories = {"response": "oui"}
     functionality = GameFunctionality(self.SENDER_ID, self.bot, categories,
                                       self.payload)
     deleteFromDB(self.SENDER_ID)
     setInDB(self.SENDER_ID, {"game": "ticTacToe"})
     response = functionality.getResponse()
     self.assertEqual("text_message", response["type"])
     self.assertIsInstance(response["message"], str)
     self.assertIsNotNone(getInDB(self.SENDER_ID, "grid"))
Esempio n. 10
0
 def askToChangeLocation(self):
     newLocation = self.newLocation
     senderId = self.senderId
     oldLocation = getInDB(senderId, "location")
     if not oldLocation:
         oldLocation = "inconnue"
     messageToSend = (
         "Ton endroit préféré jusqu'à maintenant était {0}"
         ", est-ce que tu veux le changer?".format(oldLocation))
     setInDB(senderId, {"question": "location", "response": newLocation})
     return messageToSend
 def test_getMessageToSendIfQuestion(self):
     setInDB(self.SENDER_ID, {"question": "howAreYou"})
     messageToSend = self.functionality.getMessageToSend()
     self.assertFalse(getInDB(self.SENDER_ID, "question"))
     self.assertIn(
         messageToSend,
         [
             "Tant mieux!",
             "Et ben. Ça va bien aller" + emojis.RAINBOW + ", comme on dit",
             "Tout va bien alors " + emojis.HAPPY_FACE + "!",
         ],
     )
Esempio n. 12
0
 def getMessageToSend(self):
     categories = self.categories
     senderId = self.senderId
     question = []
     if getInDB(senderId, "question"):
         question = getInDB(senderId, "question")
     setInDB(senderId, {"question": None})
     if "favorite" in question:
         messageToSend = self.continueQuestion()
     else:
         self.newFavorite = str(categories.get("favorite"))
         self.newFavoriteType = str(categories.get("favoriteType"))
         if (type(getInDB(senderId, "favorite")) == dict) and (
             getInDB(senderId, "favorite").get(self.newFavoriteType)
             != self.newFavorite
         ):
             messageToSend = self.askToChangeFavorite()
         elif "favorite" in categories and "favoriteType" in categories:
             messageToSend = self.setNewFavoriteInDb()
         else:
             messageToSend = self.continueQuestion()
     return messageToSend
Esempio n. 13
0
 def askToChangeFavorite(self):
     newFavorite = self.newFavorite
     newFavoriteType = self.newFavoriteType
     senderId = self.senderId
     if (type(getInDB(senderId, "favorite")) == dict) and (
         getInDB(senderId, "favorite").get(self.newFavoriteType)
     ):
         oldFavorite = getInDB(senderId, "favorite").get(self.newFavoriteType)
     else:
         oldFavorite = "inconnue"
     messageToSend = str(
         "Hmmm...si je me souviens bien...{0} préféré(e) pour l'instant est {1}! "
         "Est-ce que tu veux changer?"
     ).format(newFavoriteType, oldFavorite)
     if newFavorite:
         setInDB(
             senderId,
             {
                 "question": "favorite",
                 "type": newFavoriteType,
                 "response": newFavorite,
             },
         )
     return messageToSend
Esempio n. 14
0
 def getMessageToSend(self):
     messageToSend = ""
     categories = self.categories
     if getInDB(self.senderId,
                "question") or ("response" in self.categories
                                and self.categories["response"]
                                in ("correct", "bof", "je ne sais pas",
                                    "non", "pas bien", "mal")):
         messageToSend = self.getResponseContinueWithQuestion()
         if (getInDB(self.senderId, "question") == "howAreYou2"
                 and "question" in categories):
             messageToSend += random.choice([
                 "Ça va, merci",
                 "Je sais pas trop, il y a rien de facile ces temps-ci. ",
                 "Je vais bien. Ça va bien aller.",
                 "Ça va correct, merci",
             ])
     elif "lifeIsDead" in categories:
         messageToSend = "Tout à fait d'accord avec toi"
     elif "greetings" in categories:
         messageToSend = self.getGreetingsResponse()
     elif "response" in categories:
         messageToSend = self.getContinueHowAreYouQuestion()
     if "whatCanYouDo" in categories:
         messageToSend = ""
         if ("es-tu" in categories["whatCanYouDo"]
                 or "es tu" in categories["whatCanYouDo"]):
             messageToSend = "Je suis RickBot! "
         if random.choice([True, False]):
             messageToSend = {
                 "RICKROLL": ["Voici ce que je peux faire: ", "Clique ici"]
             }
         else:
             messageToSend += getWhatCanYouDoResponse()
     elif getInDB(self.senderId,
                  "question2") and "response" in self.categories:
         setInDB(self.senderId, {"question": "howAreYou"})
         messageToSend = self.getResponseContinueWithQuestion()
         if "question" in categories:
             messageToSend += ". De mon côté, "
             messageToSend += random.choice([
                 "ça va, merci",
                 "je sais pas trop, il y a rien de facile ces temps-ci. ",
                 "je vais bien. Ça va bien aller.",
                 "ça va correct, merci",
             ])
         setInDB(self.senderId, {"question2": None})
     elif "question" in categories:
         if ("?" in categories.get("question")
                 and len(categories.get("question")) == 1):
             messageToSend = random.choice(
                 ["oui", "non", "je sais pas", "peut-être"])
         elif "vie" in categories.get("question"):
             messageToSend = "la vie est morte, voilà la vérité"
         else:
             messageToSend += random.choice([
                 "Ça va, toi?",
                 "Je sais pas trop, il y a rien de facile ces temps-ci" +
                 emojis.SWEAT_SMILE + ". Toi?",
                 "Je vais bien. Ça va bien aller" + emojis.RAINBOW +
                 ". Toi, comment tu "
                 "vas?",
                 "Ça va correct, toi?",
             ])
             setInDB(self.senderId, {"question": "howAreYou"})
     elif not messageToSend:
         messageToSend = random.choice([
             "ah, ok",
             "hahaha, quoi!?" + emojis.SURPRISED_MONKEY,
             "je comprends pas ce que tu veux dire" + emojis.SWEAT_SMILE,
             "ah ben là là" + emojis.SWEAT_SMILE,
             emojis.THUMBS_UP,
         ])
     return messageToSend
Esempio n. 15
0
 def test_getNonExistentValue(self):
     """
     tests getInDB to see if it returns false for non existent key
     """
     self.assertFalse(getInDB(0, "nonExistentKey"), "key doesn't exist")
Esempio n. 16
0
 def test_setValueInDB(self):
     """
     tests getInDB
     """
     setInDB(0, {"name": "Joe"})
     self.assertEqual("Joe", getInDB(0, "name"), "Should be Joe")
Esempio n. 17
0
 def continuePlayingTicTacToe(self):
     messageToSend = "À toi de jouer"
     grid = [["0", "1", "2"], ["3", "4", "5"], ["6", "7", "8"]]
     if not getInDB(self.senderId, "play"):
         messageToSend = "Tu as les x, j'ai les o. Donne un chiffre entre 8 et 0"
         if not getInDB(self.senderId, "IStart"):
             setInDB(self.senderId, {"IStart": True})
         else:
             setInDB(self.senderId, {"IStart": False})
             messageToSend += ". Je commence "
             move = computerPlayTicTacToe(grid)
             grid = self.makeTicTacToeMove(grid, move, "o")
             setInDB(self.senderId, {"play": True, "grid": grid})
     else:
         if getInDB(self.senderId, "grid"):
             grid = getInDB(self.senderId, "grid")
         move = self.getTicTacToeMove(grid)
         if move not in listTicTacToeMovesAvailable(grid):
             messageToSend = "Tu ne peux pas faire ça! Je joue quand même là"
         else:
             grid = self.makeTicTacToeMove(grid, move, "x")
             setInDB(self.senderId, {"play": True, "grid": grid})
         if checkIfTicTacToeWin(grid):
             messageToSend = "Tu as gagné!! Bravo" + emojis.PARTY_POPPER + " !"
             setInDB(
                 self.senderId,
                 {
                     "state": None,
                     "play": False,
                     "game": None,
                     "grid": None
                 },
             )
         elif len(listTicTacToeMovesAvailable(grid)) == 0:
             messageToSend = "Égalité! Bonne partie"
             setInDB(
                 self.senderId,
                 {
                     "state": None,
                     "play": False,
                     "game": None,
                     "grid": None
                 },
             )
         else:
             move = computerPlayTicTacToe(grid)
             grid = self.makeTicTacToeMove(grid, move, "o")
             setInDB(self.senderId, {"play": True, "grid": grid})
             if checkIfTicTacToeWin(grid):
                 messageToSend = "J'ai gagné!! Haha!" + emojis.PARTY_FACE
                 setInDB(
                     self.senderId,
                     {
                         "state": None,
                         "play": False,
                         "game": None,
                         "grid": None
                     },
                 )
             elif len(listTicTacToeMovesAvailable(grid)) == 0:
                 messageToSend = "Égalité! Bonne partie" + emojis.THUMBS_UP
                 setInDB(
                     self.senderId,
                     {
                         "state": None,
                         "play": False,
                         "game": None,
                         "grid": None
                     },
                 )
     textGrid = "\n"
     for i in grid:
         textGrid += "|"
         for j in i:
             textGrid += j + "|"
         textGrid += "\n"
     messageToSend += textGrid
     return messageToSend
Esempio n. 18
0
 def getMessageToSend(self):
     if self.state.get("game") or ("game" in self.categories and
                                   ("rematch" in self.categories["game"] or
                                    "rejouer" in self.categories["game"])):
         if getInDB(self.senderId, "play"):
             setInDB(
                 self.senderId,
                 {
                     "state": {
                         "game": "tic-tac-toe"
                     },
                     "game": "tic-tac-toe",
                     "play": True,
                 },
             )
             messageToSend = self.continuePlayingTicTacToe()
         elif self.gotResponse() or (
                 "game" in self.categories and
             ("rematch" in self.categories["game"]
              or "rejouer" in self.categories["game"])):
             setInDB(
                 self.senderId,
                 {
                     "state": {
                         "game": "tic-tac-toe"
                     },
                     "game": "tic-tac-toe",
                     "play": False,
                 },
             )
             messageToSend = self.continuePlayingTicTacToe()
             setInDB(
                 self.senderId,
                 {
                     "play": True,
                 },
             )
         else:
             setInDB(self.senderId, {
                 "state": None,
                 "play": False,
                 "game": None
             })
             messageToSend = "Non? okidoki"
     elif "game" in self.categories:
         print(self.state)
         messageToSend = "Tu veux jouer au tic-tac-toe?"
         setInDB(
             self.senderId,
             {
                 "state": {
                     "game": "tic-tac-toe"
                 },
                 "game": "tic-tac-toe",
                 "play": False,
             },
         )
     else:
         setInDB(self.senderId, {
             "state": None,
             "play": False,
             "game": None
         })
         messageToSend = "nuh"
     return messageToSend