def _addRandomWord(self): if 'randomPlayers' not in self._roundSettings or not self._roundSettings[ 'randomPlayers']: return if 'randomWordsLimit' not in self._roundSettings or not self._roundSettings[ 'randomWordsLimit']: return randomPlayersProcessed = 0 for randomPlayer in self._RANDOM_PLAYER: if randomPlayersProcessed >= self._roundSettings['randomPlayers']: break if not Player.get(telegram_id=randomPlayer['id']): Player.add(telegram_id=randomPlayer['id'], name=randomPlayer['first_name']) randomPlayersProcessed += 1 if Word.getListByRoundId(telegram_id=randomPlayer['id'], **self._gameState['query']): continue randomWordsCount = 0 wordsAdded = 0 while wordsAdded <= self._roundSettings['randomWordsLimit']: if randomWordsCount > 20: break randomWordsCount += 1 word = self._getRandom( "ushakov", wordMinLength=self._roundSettings['minWordsPerPlayer']) if not word: continue Word.add(word=word, player_id=Player.getId(randomPlayer), wordsLimit=self._roundSettings['randomWordsLimit'], wordMinLength=self._roundSettings['minWordLength'], **self._gameState['query']) wordsAdded += 1
def addWord(self, update): """ Adds word into current round of the game :param update: dict with update info :return: str text response """ self._refreshGameState(checkGameStatus=True) if self._gameState['roundStatus'] != Round.STATUS_PREPARATION: return "Слишком поздно вертеть задом. Раунд уже началася. Дождись окончания раунда" return Word.add(word=update.message.text, player_id=self._playerState['id'], wordsLimit=self._roundSettings['minWordsPerPlayer'], wordMinLength=self._roundSettings['minWordLength'], **self._gameState['query'])[1]