mirror of
https://github.com/deadcxap/YandexMusicDiscordBot.git
synced 2026-01-10 09:41:46 +03:00
feat: MyVibe settings and memory leak fix.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""This documents initialises databse and contains methods to access it."""
|
||||
|
||||
from typing import cast
|
||||
from typing import Any, cast
|
||||
|
||||
from pymongo import MongoClient
|
||||
from pymongo.collection import Collection
|
||||
@@ -29,15 +29,20 @@ class BaseUsersDatabase:
|
||||
queue_page=0,
|
||||
vibe_batch_id=None,
|
||||
vibe_type=None,
|
||||
vibe_id=None
|
||||
vibe_id=None,
|
||||
vibe_settings={
|
||||
'mood': 'all',
|
||||
'diversity': 'default',
|
||||
'lang': 'any'
|
||||
}
|
||||
))
|
||||
|
||||
def update(self, uid: int, data: User) -> None:
|
||||
def update(self, uid: int, data: User | dict[Any, Any]) -> None:
|
||||
"""Update user record.
|
||||
|
||||
Args:
|
||||
uid (int): User id.
|
||||
data (dict[Any, Any]): Updated data.
|
||||
data (User | dict[Any, Any]): Updated data.
|
||||
"""
|
||||
self.get_user(uid)
|
||||
users.update_one({'_id': uid}, {"$set": data})
|
||||
@@ -65,7 +70,12 @@ class BaseUsersDatabase:
|
||||
queue_page=0,
|
||||
vibe_batch_id=None,
|
||||
vibe_type=None,
|
||||
vibe_id=None
|
||||
vibe_id=None,
|
||||
vibe_settings={
|
||||
'mood': 'all',
|
||||
'diversity': 'default',
|
||||
'lang': 'any'
|
||||
}
|
||||
)
|
||||
for field, default_value in fields.items():
|
||||
if field not in existing_fields:
|
||||
|
||||
@@ -133,24 +133,13 @@ class VoiceGuildsDatabase(BaseGuildsDatabase):
|
||||
self.update(gid, {'next_tracks': tracks})
|
||||
return track
|
||||
|
||||
def set_current_track(self, gid: int, track: Track | dict[str, Any]) -> None:
|
||||
"""Set current track.
|
||||
|
||||
Args:
|
||||
gid (int): Guild id.
|
||||
track (Track | dict[str, Any]): Track or dictionary covertable to yandex_music.Track.
|
||||
"""
|
||||
if isinstance(track, Track):
|
||||
track = track.to_dict()
|
||||
self.update(gid, {'current_track': track})
|
||||
|
||||
def get_current_menu(self, gid: int) -> int | None:
|
||||
"""Get current player.
|
||||
"""Get current menu.
|
||||
|
||||
Args:
|
||||
gid (int): Guild id.
|
||||
|
||||
Returns: int | None: Player message id or None if not present.
|
||||
Returns: int | None: Menu message id or None if not present.
|
||||
"""
|
||||
guild = self.get_guild(gid)
|
||||
return guild['current_menu']
|
||||
@@ -1,4 +1,10 @@
|
||||
from typing import TypedDict, Literal
|
||||
from typing import TypedDict, TypeAlias, Literal
|
||||
|
||||
VibeSettingsOptions: TypeAlias = Literal[
|
||||
'active', 'fun', 'calm', 'sad', 'all',
|
||||
'favorite', 'discover', 'popular', 'default',
|
||||
'russian', 'not-russian', 'without-words', 'any',
|
||||
]
|
||||
|
||||
class User(TypedDict, total=False):
|
||||
ym_token: str | None
|
||||
@@ -8,6 +14,7 @@ class User(TypedDict, total=False):
|
||||
vibe_batch_id: str | None
|
||||
vibe_type: Literal['track', 'album', 'artist', 'playlist', 'user'] | None
|
||||
vibe_id: str | int | None
|
||||
vibe_settings: dict[Literal['mood', 'diversity', 'lang'], VibeSettingsOptions]
|
||||
|
||||
class ExplicitUser(TypedDict):
|
||||
_id: int
|
||||
@@ -18,3 +25,4 @@ class ExplicitUser(TypedDict):
|
||||
vibe_batch_id: str | None
|
||||
vibe_type: Literal['track', 'album', 'artist', 'playlist', 'user'] | None
|
||||
vibe_id: str | int | None
|
||||
vibe_settings: dict[Literal['mood', 'diversity', 'lang'], VibeSettingsOptions]
|
||||
|
||||
Reference in New Issue
Block a user