Skip to content

Commit

Permalink
feat: add literal types
Browse files Browse the repository at this point in the history
  • Loading branch information
NiceAesth committed Aug 25, 2023
1 parent ddd7757 commit 237c5a3
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 35 deletions.
23 changes: 22 additions & 1 deletion aiosu/models/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from __future__ import annotations

from datetime import datetime
from typing import Literal
from typing import Optional

from pydantic import Field
Expand All @@ -14,12 +15,32 @@
__all__ = (
"ArtistTrack",
"ArtistResponse",
"ArtistSortType",
)

ArtistSortType = Literal[
"album_asc",
"album_desc",
"artist_asc",
"artist_desc",
"bpm_asc",
"bpm_desc",
"genre_asc",
"genre_desc",
"length_asc",
"length_desc",
"relevance_asc",
"relevance_desc",
"title_asc",
"title_desc",
"update_asc",
"update_desc",
]


class ArtistSearch(BaseModel):
is_default_sort: bool
sort: str
sort: ArtistSortType


class Artist(BaseModel):
Expand Down
12 changes: 6 additions & 6 deletions aiosu/models/beatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"Beatmapset",
"BeatmapsetDiscussion",
"BeatmapsetDiscussionPost",
"BeatmapsetDisscussionType",
"BeatmapsetDisscussionTypes",
"BeatmapsetEvent",
"BeatmapsetEventComment",
"BeatmapsetEventType",
"BeatmapsetEventTypes",
"BeatmapsetRequestStatus",
"BeatmapsetVoteEvent",
"BeatmapUserPlaycount",
Expand All @@ -48,7 +48,7 @@
"BeatmapsetSearchResponse",
)

BeatmapsetDisscussionType = Literal[
BeatmapsetDisscussionTypes = Literal[
"hype",
"praise",
"problem",
Expand All @@ -58,7 +58,7 @@
]


BeatmapsetEventType = Literal[
BeatmapsetEventTypes = Literal[
"approve",
"beatmap_owner_change",
"discussion_delete",
Expand Down Expand Up @@ -441,7 +441,7 @@ class BeatmapsetDiscussion(BaseModel):
id: int
beatmapset_id: int
user_id: int
message_type: BeatmapsetDisscussionType
message_type: BeatmapsetDisscussionTypes
resolved: bool
can_be_resolved: bool
can_grant_kudosu: bool
Expand Down Expand Up @@ -484,7 +484,7 @@ class BeatmapsetEventComment(BaseModel):

class BeatmapsetEvent(BaseModel):
id: int
type: BeatmapsetEventType
type: BeatmapsetEventTypes
r"""Information on types: https://github.com/ppy/osu-web/blob/master/resources/assets/lib/interfaces/beatmapset-event-json.ts"""
created_at: datetime
user_id: int
Expand Down
8 changes: 5 additions & 3 deletions aiosu/models/changelog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
"Version",
"ChangelogListing",
"ChangelogSearch",
"ChangelogMessageFormats",
"ChangelogMessageFormat",
"ChangelogEntryType",
)

ChangelogMessageFormats = Literal["markdown", "html"]
ChangelogMessageFormat = Literal["markdown", "html"]
ChangelogEntryType = Literal["add", "fix"]


class GithubUser(BaseModel):
Expand All @@ -37,7 +39,7 @@ class GithubUser(BaseModel):


class ChangelogEntry(BaseModel):
type: str
type: ChangelogEntryType
category: str
major: bool
id: Optional[int] = None
Expand Down
10 changes: 5 additions & 5 deletions aiosu/models/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
"ChatChannel",
"ChatMessage",
"ChatMessageCreateResponse",
"ChatChannelTypes",
"ChatIncludeTypes",
"ChatChannelType",
"ChatIncludeType",
"ChatUpdateResponse",
"ChatUserSilence",
"ChatChannelResponse",
)

ChatChannelTypes = Literal[
ChatChannelType = Literal[
"PM",
"PUBLIC",
"PRIVATE",
Expand All @@ -34,7 +34,7 @@
"ANNOUNCE",
]

ChatIncludeTypes = Literal[
ChatIncludeType = Literal[
"messages",
"presence",
"silences",
Expand All @@ -48,7 +48,7 @@ class ChatUserSilence(BaseModel):

class ChatChannel(BaseModel):
id: int = Field(alias="channel_id")
type: ChatChannelTypes
type: ChatChannelType
name: str
moderated: bool
message_length_limit: int
Expand Down
6 changes: 4 additions & 2 deletions aiosu/models/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
"Comment",
"CommentBundle",
"CommentSortType",
"CommentableType",
)

CommentSortType = Literal["new", "old", "top"]
CommentableType = Literal["beatmapset", "news_post", "build"]


class Commentable(BaseModel):
Expand All @@ -35,7 +37,7 @@ class Commentable(BaseModel):
class Comment(BaseModel):
id: int
commentable_id: int
commentable_type: str
commentable_type: CommentableType
created_at: datetime
updated_at: datetime
pinned: bool
Expand All @@ -56,7 +58,7 @@ class CommentBundle(CursorModel):
comments: list[Comment]
has_more: bool
included_comments: list[Comment]
sort: str
sort: CommentSortType
user_follow: bool
user_votes: list[int]
users: list[User]
Expand Down
20 changes: 17 additions & 3 deletions aiosu/models/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,26 @@
"CurrentUserAttributes",
"TimestampedCount",
"CursorModel",
"SortTypes",
"SortType",
"ScoreType",
"BeatmapScoreboardType",
"HTMLBody",
)


SortTypes = Literal["id_asc", "id_desc"]
SortType = Literal["id_asc", "id_desc"]
ScoreType = Literal[
"solo_score",
"score_best_osu",
"score_best_taiko",
"score_best_fruits",
"score_best_mania",
"score_osu",
"score_taiko",
"score_fruits",
"score_mania",
]
BeatmapScoreboardType = Literal["global", "country", "friend"]


class TimestampedCount(BaseModel):
Expand Down Expand Up @@ -78,7 +92,7 @@ class HTMLBody(BaseModel):
class PinAttributes(BaseModel):
is_pinned: bool
score_id: int
score_type: str
score_type: ScoreType


class CurrentUserAttributes(BaseModel):
Expand Down
5 changes: 4 additions & 1 deletion aiosu/models/lazer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .beatmap import Beatmap
from .beatmap import Beatmapset
from .common import CurrentUserAttributes
from .common import ScoreType
from .gamemode import Gamemode
from .score import ScoreWeight
from .user import User
Expand Down Expand Up @@ -136,12 +137,14 @@ class LazerScore(BaseModel):
total_score: int
user_id: int
replay: bool
type: str
type: ScoreType
current_user_attributes: CurrentUserAttributes
beatmap: Beatmap
beatmapset: Beatmapset
user: User
build_id: Optional[int] = None
legacy_score_id: Optional[int] = None
legacy_total_score: Optional[int] = None
started_at: Optional[datetime] = None
best_id: Optional[int] = None
legacy_perfect: Optional[bool] = None
Expand Down
18 changes: 9 additions & 9 deletions aiosu/models/multiplayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@
"MultiplayerScore",
"MultiplayerScoresAround",
"MultiplayerMatch",
"MultiplayerEventTypes",
"MultiplayerEventType",
"MultiplayerEvent",
"MultiplayerMatchResponse",
"MultiplayerMatchesResponse",
"MultiplayerRoomMode",
"MultiplayerRoom",
"MultiplayerRoomsResponse",
"MultiplayerRoomCategories",
"MultiplayerRoomTypeGroups",
"MultiplayerRoomCategorie",
"MultiplayerRoomTypeGroup",
"MultiplayerLeaderboardResponse",
"MultiplayerLeaderboardItem",
"MultiplayerQueueMode",
)

MultiplayerScoreSortType = Literal["score_asc", "score_desc"]
MultiplayerEventTypes = Literal[
MultiplayerEventType = Literal[
"match-created",
"match-disbanded",
"host-changed",
Expand All @@ -55,8 +55,8 @@
"player-kicked-no-user",
]
MultiplayerRoomMode = Literal["owned", "participated", "ended"]
MultiplayerRoomCategories = Literal["normal", "spotlight", "featured_artists"]
MultiplayerRoomTypeGroups = Literal["playlists", "realtime"]
MultiplayerRoomCategorie = Literal["normal", "spotlight", "featured_artists"]
MultiplayerRoomTypeGroup = Literal["playlists", "realtime"]
MultiplayerQueueMode = Literal["host_only", "all_players", "all_players_round_robin"]


Expand Down Expand Up @@ -99,7 +99,7 @@ class MultiplayerMatch(BaseModel):
class MultiplayerEvent(BaseModel):
id: int
timestamp: datetime
type: MultiplayerEventTypes
type: MultiplayerEventType
user_id: Optional[int] = None

@model_validator(mode="before")
Expand Down Expand Up @@ -140,8 +140,8 @@ class MultiplayerPlaylistItem(BaseModel):
class MultiplayerRoom(BaseModel):
id: int
name: str
category: MultiplayerRoomCategories
type: MultiplayerRoomTypeGroups
category: MultiplayerRoomCategorie
type: MultiplayerRoomTypeGroup
user_id: int
channel_id: int
active: bool
Expand Down
5 changes: 4 additions & 1 deletion aiosu/models/news.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
"Navigation",
"NewsListing",
"NewsSearch",
"NewsSortType",
)

NewsSortType = Literal["published_asc", "published_desc"]


class NewsSearch(BaseModel):
limit: int
sort: Literal["published_desc"]
sort: NewsSortType


class Navigation(BaseModel):
Expand Down
5 changes: 4 additions & 1 deletion aiosu/models/spotlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
from __future__ import annotations

from datetime import datetime
from typing import Literal
from typing import Optional

from .base import BaseModel

__all__ = ("Spotlight",)

SpotlightType = Literal["bestof", "monthly", "spotlight", "theme", "special"]


class Spotlight(BaseModel):
id: int
name: str
mode_specific: bool
type: str
type: SpotlightType
start_date: datetime
end_date: datetime
participant_count: Optional[int] = None
6 changes: 3 additions & 3 deletions aiosu/v2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from ..models import ChangelogListing
from ..models import ChatChannel
from ..models import ChatChannelResponse
from ..models import ChatChannelTypes
from ..models import ChatChannelType
from ..models import ChatMessage
from ..models import ChatMessageCreateResponse
from ..models import ChatUpdateResponse
Expand Down Expand Up @@ -1159,7 +1159,7 @@ async def get_beatmap_scores(self, beatmap_id: int, **kwargs: Any) -> list[Score
Optional, gamemode to search for
* *mods* (``aiosu.models.mods.Mods``) --
Optional, mods to search for
* *type* (``str``) --
* *type* (``aiosu.models.common.BeatmapScoreboardType``) --
Optional, beatmap score ranking type
:raises APIException: Contains status code and error message
Expand Down Expand Up @@ -1986,7 +1986,7 @@ async def get_channel_messages(
@requires_scope(Scopes.IDENTIFY | Scopes.DELEGATE, any_scope=True)
async def create_chat_channel(
self,
type: ChatChannelTypes,
type: ChatChannelType,
**kwargs: Any,
) -> ChatChannel:
r"""Creates a chat channel.
Expand Down

0 comments on commit 237c5a3

Please sign in to comment.