def official( cls, id: Optional[int] = None, name: Optional[str] = None, index: Optional[int] = None, client: Optional[Client] = None, get_data: bool = True, ) -> Level: if id is not None: official_level = get(official_levels, level_id=id) elif name is not None: official_level = get(official_levels, name=name) elif index is not None: try: official_level = official_levels[index] except (IndexError, TypeError): official_level = None else: raise ValueError("Expected either of queries: level_id, name or index.") if official_level is None: raise LookupError("Could not find official level by given query.") return official_level.into_level(client, get_data=get_data)
async def update(self) -> None: """|coro| Update ``self``. """ from gd.level import Level # this is a hack because *circular imports* records = await Level(id=self.level_id, client=self.client).get_leaderboard( self.type.value) record = get(records, account_id=self.account_id) if record is not None: self.options = record.options
def get_by_name(self, name: str) -> Optional[LevelAPI]: return search.get(self, name=name)
def get(self, directive_or_id: Union[int, str]) -> Optional[ColorCollection]: final = directive_or_id if isinstance(final, str): final = get_id(_get_dir(final, "color")) return search.get(self, id=final)
def official( cls, id: Optional[int] = None, name: Optional[str] = None, index: Optional[int] = None, client: Optional[Client] = None, get_data: bool = True, server_style: bool = False, ) -> Level: """Get official level to work with. Lookup is done in the following form: ``id -> name -> index``. Parameters ---------- id: Optional[:class:`int`] ID of the official level. name: Optional[:class:`str`] Name of the official level. index: Optional[:class:`int`] Index (position) of the official level. client: Optional[:class:`.Client`] Client to attach to the level. get_data: :class:`bool` Whether to attach data to the level. Default is ``True``. server_style: :class:`bool` Indicates if server-style of official song ID should be used. Set this to ``True`` in case of uploading level to the server. Defaults to ``False``. Raises ------ :exc:`ValueError` No queries were given. :exc:`LookupError` Level was not found. Returns ------- :class:`.Level` Official level that was found. """ if id is not None: official_level = get(official_levels, level_id=id) elif name is not None: official_level = get(official_levels, name=name) elif index is not None: try: official_level = official_levels[index] except (IndexError, TypeError): official_level = None else: raise ValueError( "Expected either of queries: level_id, name or index.") if official_level is None: raise LookupError("Could not find official level by given query.") return official_level.into_level(client, get_data=get_data, server_style=server_style)