Skip to content

Commit

Permalink
3.5.2: fixed /list play numeration problem
Browse files Browse the repository at this point in the history
  • Loading branch information
at-elcapitan committed May 12, 2024
1 parent 92e79dd commit 31f2f0d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
17 changes: 8 additions & 9 deletions atlb/music.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,13 @@ async def user_list_play(self, interaction: discord.Interaction, position: str):
ephemeral=True)
return

try:
songs = strparser.parse_input(position)
except strparser.ParseException:
await interaction.response.send_message(embed=error_embed("876", "Can`t read input!", "Your input is invalid"),
ephemeral=True)
return

voice_channel = interaction.user.voice.channel

cursor = self.dbconn.cursor()
Expand All @@ -611,15 +618,7 @@ async def user_list_play(self, interaction: discord.Interaction, position: str):
await interaction.response.send_message(embed=error_embed("873.1", "Can`t read list!", "Error: your list is empty!"),
ephemeral=True)
return

""" if len(lst) < position:
await interaction.response.send_message(embed=error_embed("873.2", "Can`t read song!",
"Position out of range for your saved list!"),
ephemeral=True)
return """

songs = strparser.parse_input(position)


error_string = ""
await interaction.response.send_message("Processing...", ephemeral=True)
for song_id in songs:
Expand Down
11 changes: 9 additions & 2 deletions atlb/strparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,27 @@ def parse_input(string: str) -> set:

if (len(parsed_string) == 0):
raise ParseException("Unable to parse string")

if (len(parsed_string) == 1):
try:
result.add(int(parsed_string[0] - 1))
return result
except ValueError:
raise ValueError(f"Unable to parse token {token}")

for token in parsed_string:
if "-" in token:
parsed_token = token.split("-")
try:
parsed_token = [int(x) for x in parsed_token]
parsed_token = [(int(x) - 1) for x in parsed_token]
except ValueError:
raise ParseException(f"Unable to parse token `{token}`")

if parsed_token[0] > parsed_token[1]:
raise ParseException(f"Unable to parse token `{token}`."
" First value is bigger than the second.")

result.update(range(parsed_token[0] - 1, parsed_token[1]))
result.update(range(parsed_token[0] - 1, parsed_token[1] - 1))
continue

try:
Expand Down

0 comments on commit 31f2f0d

Please sign in to comment.