Example #1
0
    def reset_user_words(user_telegram_id):
        """
        Change all user word status to unused

        :param user_telegram_id:
        :return:
        """
        user = UserService.filter(telegram_id=user_telegram_id)
        if user:
            user = user[0]
        else:
            return None

        user_words = UserWordService.filter(user_id=user.id)

        for word in user_words:
            UserWordService.update(user_word_id=word.id, status=True)

        return True
Example #2
0
    def add_user_word(user_telegram_id, word):
        """
        add word to user word list

        :param user_telegram_id:
        :param word:
        :return:
        """

        user = UserService.filter(telegram_id=user_telegram_id)

        if not user:  # if no such word
            return None

        user = user[0]

        # if user already has this word
        if user_word := UserWordService.filter(user_id=user.id,
                                               word_id=word.id):
            return user_word[0]
Example #3
0
    def get_user_word(user_telegram_id):
        """
        Return one of user`s unseen word

        :param user_telegram_id:
        :return:
        """
        user = UserService.filter(telegram_id=user_telegram_id)

        if not user:
            return None

        user = user[0]

        user_word = UserWordService.pick_random_word(user.id)

        if not user_word:
            return None

        UserWordService.update(user_word.id, status=False)  # mark word as used
        word = WordService.get_by_id(user_word.word_id)

        return word