feat: Add the ability to use the bot with single YM token.

This commit is contained in:
Lemon4ksan
2025-03-15 17:30:42 +03:00
parent a9c938b736
commit 7fe9d699b1
8 changed files with 171 additions and 100 deletions

View File

@@ -8,6 +8,9 @@ from .user import User, ExplicitUser
from .guild import Guild, ExplicitGuild, MessageVotes
mongo_server = os.getenv('MONGO_URI')
if not mongo_server:
raise ValueError('MONGO_URI environment variable is not set')
client: AsyncMongoClient = AsyncMongoClient(mongo_server)
db = client.YandexMusicBot
@@ -67,12 +70,6 @@ class BaseUsersDatabase:
)
return cast(str | None, user.get('ym_token') if user else None)
async def add_playlist(self, uid: int, playlist_data: dict) -> UpdateResult:
return await users.update_one(
{'_id': uid},
{'$push': {'playlists': playlist_data}}
)
class BaseGuildsDatabase:
DEFAULT_GUILD = Guild(
@@ -81,7 +78,6 @@ class BaseGuildsDatabase:
current_track=None,
current_menu=None,
is_stopped=True,
always_allow_menu=False,
allow_change_connect=True,
vote_switch_track=True,
vote_add=True,
@@ -89,7 +85,9 @@ class BaseGuildsDatabase:
repeat=False,
votes={},
vibing=False,
current_viber_id=None
current_viber_id=None,
use_single_token=False,
single_token_uid=None
)
async def update(self, gid: int, data: Guild | dict[str, Any]) -> UpdateResult:
@@ -127,9 +125,3 @@ class BaseGuildsDatabase:
{'_id': gid},
{'$set': {f'votes.{mid}': data}}
)
async def clear_queue(self, gid: int) -> UpdateResult:
return await guilds.update_one(
{'_id': gid},
{'$set': {'next_tracks': []}}
)

View File

@@ -10,13 +10,12 @@ class MessageVotes(TypedDict):
]
vote_content: Any | None
class Guild(TypedDict, total=False):
class Guild(TypedDict, total=False): # Don't forget to change base.py if you add a new field
next_tracks: list[dict[str, Any]]
previous_tracks: list[dict[str, Any]]
current_track: dict[str, Any] | None
current_menu: int | None
is_stopped: bool
always_allow_menu: bool
is_stopped: bool # Prevents the `after` callback of play_track
allow_change_connect: bool
vote_switch_track: bool
vote_add: bool
@@ -25,6 +24,8 @@ class Guild(TypedDict, total=False):
votes: dict[str, MessageVotes]
vibing: bool
current_viber_id: int | None
use_single_token: bool
single_token_uid: int | None
class ExplicitGuild(TypedDict):
_id: int
@@ -32,8 +33,7 @@ class ExplicitGuild(TypedDict):
previous_tracks: list[dict[str, Any]]
current_track: dict[str, Any] | None
current_menu: int | None
is_stopped: bool # Prevents the `after` callback of play_track
always_allow_menu: bool
is_stopped: bool
allow_change_connect: bool
vote_switch_track: bool
vote_add: bool
@@ -42,3 +42,5 @@ class ExplicitGuild(TypedDict):
votes: dict[str, MessageVotes]
vibing: bool
current_viber_id: int | None
use_single_token: bool
single_token_uid: int | None

View File

@@ -6,7 +6,7 @@ VibeSettingsOptions: TypeAlias = Literal[
'russian', 'not-russian', 'without-words', 'any',
]
class User(TypedDict, total=False):
class User(TypedDict, total=False): # Don't forget to change base.py if you add a new field
ym_token: str | None
playlists: list[tuple[str, int]]
playlists_page: int