feat: Basic "My Vibe" implementation.

This commit is contained in:
Lemon4ksan
2025-01-26 22:07:47 +03:00
parent 85f7ee6c6c
commit c49ff949cf
11 changed files with 350 additions and 116 deletions

View File

@@ -26,7 +26,10 @@ class BaseUsersDatabase:
ym_token=None,
playlists=[],
playlists_page=0,
queue_page=0
queue_page=0,
vibe_batch_id=None,
vibe_type=None,
vibe_id=None
))
def update(self, uid: int, data: User) -> None:
@@ -54,14 +57,18 @@ class BaseUsersDatabase:
user = users.find_one({'_id': uid})
user = cast(ExplicitUser, user)
existing_fields = user.keys()
fields: User = User(
fields: ExplicitUser = ExplicitUser(
_id=0,
ym_token=None,
playlists=[],
playlists_page=0,
queue_page=0
queue_page=0,
vibe_batch_id=None,
vibe_type=None,
vibe_id=None
)
for field, default_value in fields.items():
if field not in existing_fields and field != '_id':
if field not in existing_fields:
user[field] = default_value
users.update_one({'_id': uid}, {"$set": {field: default_value}})
@@ -87,7 +94,7 @@ class BaseGuildsDatabase:
next_tracks=[],
previous_tracks=[],
current_track=None,
current_player=None,
current_menu=None,
is_stopped=True,
allow_explicit=True,
always_allow_menu=False,
@@ -98,7 +105,8 @@ class BaseGuildsDatabase:
vote_add_playlist=True,
shuffle=False,
repeat=False,
votes={}
votes={},
vibing=False
))
def update(self, gid: int, data: Guild) -> None:
@@ -127,11 +135,12 @@ class BaseGuildsDatabase:
guild = cast(ExplicitGuild, guild)
existing_fields = guild.keys()
fields = Guild(
fields = ExplicitGuild(
_id=0,
next_tracks=[],
previous_tracks=[],
current_track=None,
current_player=None,
current_menu=None,
is_stopped=True,
allow_explicit=True,
always_allow_menu=False,
@@ -142,10 +151,11 @@ class BaseGuildsDatabase:
vote_add_playlist=True,
shuffle=False,
repeat=False,
votes={}
votes={},
vibing=False
)
for field, default_value in fields.items():
if field not in existing_fields and field != '_id':
if field not in existing_fields:
guild[field] = default_value
guilds.update_one({'_id': gid}, {"$set": {field: default_value}})

View File

@@ -144,7 +144,7 @@ class VoiceGuildsDatabase(BaseGuildsDatabase):
track = track.to_dict()
self.update(gid, {'current_track': track})
def get_current_player(self, gid: int) -> int | None:
def get_current_menu(self, gid: int) -> int | None:
"""Get current player.
Args:
@@ -153,4 +153,4 @@ class VoiceGuildsDatabase(BaseGuildsDatabase):
Returns: int | None: Player message id or None if not present.
"""
guild = self.get_guild(gid)
return guild['current_player']
return guild['current_menu']

View File

@@ -11,7 +11,7 @@ class Guild(TypedDict, total=False):
next_tracks: list[dict[str, Any]]
previous_tracks: list[dict[str, Any]]
current_track: dict[str, Any] | None
current_player: int | None
current_menu: int | None
is_stopped: bool
allow_explicit: bool
always_allow_menu: bool
@@ -23,13 +23,14 @@ class Guild(TypedDict, total=False):
shuffle: bool
repeat: bool
votes: dict[str, MessageVotes]
vibing: bool
class ExplicitGuild(TypedDict):
_id: int
next_tracks: list[dict[str, Any]]
previous_tracks: list[dict[str, Any]]
current_track: dict[str, Any] | None
current_player: int | None
current_menu: int | None
is_stopped: bool # Prevents the `after` callback of play_track
allow_explicit: bool
always_allow_menu: bool
@@ -40,4 +41,5 @@ class ExplicitGuild(TypedDict):
vote_add_playlist: bool
shuffle: bool
repeat: bool
votes: dict[str, MessageVotes]
votes: dict[str, MessageVotes]
vibing: bool

View File

@@ -1,10 +1,13 @@
from typing import TypedDict
from typing import TypedDict, Literal
class User(TypedDict, total=False):
ym_token: str | None
playlists: list[tuple[str, int]]
playlists_page: int
queue_page: int
vibe_batch_id: str | None
vibe_type: Literal['track', 'album', 'artist', 'playlist', 'user'] | None
vibe_id: str | int | None
class ExplicitUser(TypedDict):
_id: int
@@ -12,3 +15,6 @@ class ExplicitUser(TypedDict):
playlists: list[tuple[str, int]] # name / tracks count
playlists_page: int
queue_page: int
vibe_batch_id: str | None
vibe_type: Literal['track', 'album', 'artist', 'playlist', 'user'] | None
vibe_id: str | int | None