impr: Enforce menu view, vote improvement and bug fixes.

This commit is contained in:
Lemon4ksan
2025-02-21 17:03:39 +03:00
parent 617a7a6de9
commit 12f7c96c93
9 changed files with 457 additions and 505 deletions

View File

@@ -80,12 +80,9 @@ class BaseGuildsDatabase:
current_menu=None,
is_stopped=True,
always_allow_menu=False,
allow_connect=True,
vote_next_track=True,
vote_add_track=True,
vote_add_album=True,
vote_add_artist=True,
vote_add_playlist=True,
allow_change_connect=True,
vote_switch_track=True,
vote_add=True,
shuffle=False,
repeat=False,
votes={},

View File

@@ -19,28 +19,29 @@ class VoiceGuildsDatabase(BaseGuildsDatabase):
if list_type not in ('next', 'previous', 'current'):
raise ValueError("list_type must be either 'next' or 'previous'")
if list_type == 'current':
return (await self.get_guild(gid, projection={'current_track': 1}))['current_track']
field = f'{list_type}_tracks'
update = {'$pop': {field: -1}}
guild = await self.get_guild(gid, projection={'current_track': 1, field: 1})
if list_type == 'current':
return guild['current_track']
result = await guilds.find_one_and_update(
{'_id': gid},
update,
{'$pop': {field: -1}},
projection={field: 1},
return_document=ReturnDocument.BEFORE
)
res = result.get(field, [])[0] if result and result.get(field) else None
res = result.get(field, []) if result else None
if field == 'previous_tracks' and res:
await guilds.find_one_and_update(
{'_id': gid},
{'$push': {'next_tracks': {'$each': [res], '$position': 0}}},
{'$push': {'next_tracks': {'$each': [guild['current_track']], '$position': 0}}},
projection={'next_tracks': 1}
)
return res
return res[0] if res else None
async def modify_track(
self,

View File

@@ -4,8 +4,8 @@ class MessageVotes(TypedDict):
positive_votes: list[int]
negative_votes: list[int]
total_members: int
action: Literal['next', 'add_track', 'add_album', 'add_artist', 'add_playlist']
vote_content: dict[str, Any] | list[dict[str, Any]] | None
action: Literal['next', 'play/pause', 'repeat', 'shuffle', 'previous', 'add_track', 'add_album', 'add_artist', 'add_playlist']
vote_content: Any | None
class Guild(TypedDict, total=False):
next_tracks: list[dict[str, Any]]
@@ -14,12 +14,9 @@ class Guild(TypedDict, total=False):
current_menu: int | None
is_stopped: bool
always_allow_menu: bool
allow_connect: bool
vote_next_track: bool
vote_add_track: bool
vote_add_album: bool
vote_add_artist: bool
vote_add_playlist: bool
allow_change_connect: bool
vote_switch_track: bool
vote_add: bool
shuffle: bool
repeat: bool
votes: dict[str, MessageVotes]
@@ -34,12 +31,9 @@ class ExplicitGuild(TypedDict):
current_menu: int | None
is_stopped: bool # Prevents the `after` callback of play_track
always_allow_menu: bool
allow_connect: bool
vote_next_track: bool
vote_add_track: bool
vote_add_album: bool
vote_add_artist: bool
vote_add_playlist: bool
allow_change_connect: bool
vote_switch_track: bool
vote_add: bool
shuffle: bool
repeat: bool
votes: dict[str, MessageVotes]