diff options
Diffstat (limited to 'cogs/music')
| -rw-r--r-- | cogs/music/play.py | 12 | ||||
| -rw-r--r-- | cogs/music/play_utils.py | 7 |
2 files changed, 13 insertions, 6 deletions
diff --git a/cogs/music/play.py b/cogs/music/play.py index 2c5b641..d77d772 100644 --- a/cogs/music/play.py +++ b/cogs/music/play.py | |||
| @@ -1,11 +1,12 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import discord | 2 | import discord |
| 3 | import mutagen | 3 | import mutagen |
| 4 | from typing import List, Tuple, Optional, Callable, Awaitable, Union | 4 | from typing import List, Tuple, Callable, Awaitable |
| 5 | from os import PathLike | ||
| 5 | 6 | ||
| 6 | from . import play_utils | 7 | from cogs.music import play_utils |
| 7 | from discord.ext import commands | 8 | from discord.ext import commands |
| 8 | from discord.commands import Option, OptionChoice | 9 | from discord.commands import OptionChoice |
| 9 | import logging | 10 | import logging |
| 10 | 11 | ||
| 11 | logger = logging.getLogger(__name__) | 12 | logger = logging.getLogger(__name__) |
| @@ -16,7 +17,8 @@ class Play(commands.Cog): | |||
| 16 | self.temp_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "temp") | 17 | self.temp_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "temp") |
| 17 | self.path_mapping = {} # Maps display names to full paths | 18 | self.path_mapping = {} # Maps display names to full paths |
| 18 | 19 | ||
| 19 | async def _create_search_embed(self, candidates: List[str]) -> Tuple[discord.Embed, discord.ui.View]: | 20 | @staticmethod |
| 21 | async def _create_search_embed(candidates: List[str]) -> Tuple[discord.Embed, discord.ui.View]: | ||
| 20 | """Create an embed and view for search results.""" | 22 | """Create an embed and view for search results.""" |
| 21 | embed = discord.Embed( | 23 | embed = discord.Embed( |
| 22 | title="Wyniki wyszukiwania", | 24 | title="Wyniki wyszukiwania", |
| @@ -204,7 +206,7 @@ class Play(commands.Cog): | |||
| 204 | @discord.slash_command(name="grajcuj_plik", description="grajcuj plik") | 206 | @discord.slash_command(name="grajcuj_plik", description="grajcuj plik") |
| 205 | async def play_file(self, ctx: discord.ApplicationContext, attachment: discord.Attachment = discord.Option(discord.Attachment, "co zagrać??", required=True)): | 207 | async def play_file(self, ctx: discord.ApplicationContext, attachment: discord.Attachment = discord.Option(discord.Attachment, "co zagrać??", required=True)): |
| 206 | await ctx.defer() | 208 | await ctx.defer() |
| 207 | file_path = os.path.join(self.temp_dir, attachment.filename) | 209 | file_path: PathLike[str] | str = os.path.join(self.temp_dir, attachment.filename) |
| 208 | await attachment.save(file_path) | 210 | await attachment.save(file_path) |
| 209 | await play_utils.PlayUtils(self.bot).play(ctx, file_path) | 211 | await play_utils.PlayUtils(self.bot).play(ctx, file_path) |
| 210 | 212 | ||
diff --git a/cogs/music/play_utils.py b/cogs/music/play_utils.py index 0614157..044bd1d 100644 --- a/cogs/music/play_utils.py +++ b/cogs/music/play_utils.py | |||
| @@ -113,7 +113,9 @@ class Utils: | |||
| 113 | 113 | ||
| 114 | # Boost score based on word ratio | 114 | # Boost score based on word ratio |
| 115 | score = score * (0.7 + (0.3 * word_ratio)) | 115 | score = score * (0.7 + (0.3 * word_ratio)) |
| 116 | 116 | ||
| 117 | score = int(score) | ||
| 118 | |||
| 117 | # Ensure score is within bounds | 119 | # Ensure score is within bounds |
| 118 | return min(100, max(0, score)) | 120 | return min(100, max(0, score)) |
| 119 | 121 | ||
| @@ -410,6 +412,9 @@ class PlayUtils: | |||
| 410 | async def search_local_autocomplete(cls, query: str = None, max_results: int = 10): | 412 | async def search_local_autocomplete(cls, query: str = None, max_results: int = 10): |
| 411 | """Wrapper for autocomplete searches that returns more results and allows empty query.""" | 413 | """Wrapper for autocomplete searches that returns more results and allows empty query.""" |
| 412 | # For autocomplete, we want to show more options and allow empty queries | 414 | # For autocomplete, we want to show more options and allow empty queries |
| 415 | if not query: | ||
| 416 | return [] | ||
| 417 | |||
| 413 | return await cls.search_local(query, max_results=max_results, autocomplete=True) | 418 | return await cls.search_local(query, max_results=max_results, autocomplete=True) |
| 414 | 419 | ||
| 415 | 420 | ||
