コード例 #1
0
    def save(self):
        results = self.db().search(Query().command == self.command)
        doc_ids_to_delete = [sfx.doc_id for sfx in results]
        if doc_ids_to_delete:

            with transaction(self.db()) as tr:
                tr.remove(doc_ids=doc_ids_to_delete)

        print(f"Creating New SFX Request: {self.doc()}")

        with transaction(self.db()) as tr:
            tr.insert(self.doc())
        return self.doc()
コード例 #2
0
ファイル: the_fed.py プロジェクト: whatsinmyopsec/chat_thief
    def update_value(self, field, amount=1):
        def _update_that_value():
            def transform(doc):
                doc[field] = doc[field] + amount

            return transform

        with transaction(self.db()) as tr:
            tr.update(_update_that_value(), Query().version == self.version)
コード例 #3
0
    def set_value(self, field: str, value: Any) -> None:
        def _update_that_value() -> Callable[[Dict], None]:
            def transform(doc: Dict) -> None:
                doc[field] = value

            return transform

        with transaction(self.db()) as tr:
            tr.update(_update_that_value(), Query().name == self.name)
コード例 #4
0
    def set_value_by_id(cls, doc_id: int, field: str, value: Any) -> None:
        def _update_that_value() -> Callable[[Dict], None]:
            def transform(doc: Dict) -> None:
                doc[field] = value

            return transform

        with transaction(cls.db()) as tr:
            tr.update(_update_that_value(), doc_ids=[doc_id])
コード例 #5
0
    def pop_all_off(self):
        all_effects = self.all()

        doc_ids_to_delete = [sfx.doc_id for sfx in all_effects]
        if doc_ids_to_delete:
            with transaction(self.db()) as tr:
                tr.remove(doc_ids=doc_ids_to_delete)
            return all_effects
        else:
            return []
コード例 #6
0
ファイル: user.py プロジェクト: whatsinmyopsec/chat_thief
    def _find_or_create_user(self) -> Dict:
        user_result = self.db().get(Query().name == self.name)
        if user_result:
            return user_result
        else:
            success(f"Creating New User: {self.doc()}")

            with transaction(self.db()) as tr:
                tr.insert(self.doc())
            return self.doc()
コード例 #7
0
    def update_value(self, field: str, amount: int = 1) -> None:
        def _update_that_value() -> Callable[[Dict], None]:
            def transform(doc: Dict) -> None:
                if field in doc:
                    doc[field] = doc[field] + amount
                else:
                    doc[field] = amount

            return transform

        with transaction(self.db()) as tr:
            tr.update(_update_that_value(), Query().name == self.name)
コード例 #8
0
    def _save_samples(cls, results, approver):
        if results:
            print(f"\nResults: {results}")

        doc_ids_to_delete = [sfx.doc_id for sfx in results]
        if doc_ids_to_delete:
            print(f"Deleting the following IDs: {doc_ids_to_delete}")

            with transaction(cls.db()) as tr:
                tr.remove(doc_ids=doc_ids_to_delete)

        for sfx in results:
            cls._save_sample(sfx, approver)
コード例 #9
0
ファイル: vote.py プロジェクト: whatsinmyopsec/chat_thief
    def vote(self, vote: str) -> Dict["str", int]:
        user = self._find_user()

        def user_vote(new_vote: str) -> Callable[[Dict], None]:
            def transform(doc: Dict) -> None:
                doc["vote"] = new_vote

            return transform

        if user:
            print(f"Previous Vote for User {self.user}!")
            self.db().update(user_vote(vote), Query().user == self.user)
        else:
            warning(f"NO Previous Vote for User {self.user}!")

            self._vote = vote
            with transaction(self.db()) as tr:
                tr.insert(self.doc())

        return {
            "Revolution": self.revolution_count(),
            "Peace": self.peace_count()
        }
コード例 #10
0
        self.is_theme_song = self.name in SoundeffectsLibrary.fetch_theme_songs()

    def doc(self) -> Dict:
        return {
            "name": self.name,
            "user": "******",
            "permitted_users": self.permitted_users,
            "health": self.inital_health,
            "cost": self.inital_cost,
        }

    def command(self) -> Dict:
        if command_result := self.db().search(Query().name == self.name):
            return command_result[0]
        else:
            with transaction(self.db()) as tr:
                tr.insert(self.doc())
            return self.doc()

    def health(self) -> int:
        return self._fetch_field("health", 0)

    def cost(self) -> int:
        return self._fetch_field("cost", 1)

    def users(self) -> List[str]:
        return self._fetch_field("permitted_users", [])

    @classmethod
    def available_sounds(cls) -> Optional[List[Dict]]:
        def test_func(val: List[str]) -> bool:
コード例 #11
0
 def save(self) -> "BaseDbModel":
     with transaction(self.db()) as tr:
         tr.insert(self.doc())
     return self
コード例 #12
0
 def update(
         self, update_func: Callable[[], Callable[[Dict],
                                                  None]]) -> "BaseDbModel":
     with transaction(self.db()) as tr:
         return tr.update(update_func(), Query().name == self.name)
     return self