From edff41f3468996dad5e66d34ac8ab1f5a238751f Mon Sep 17 00:00:00 2001 From: salmonik Date: Thu, 15 Jan 2026 14:37:22 +0100 Subject: minor improvements --- cogs/music/play.py | 12 +++++++----- cogs/music/play_utils.py | 7 ++++++- 2 files changed, 13 insertions(+), 6 deletions(-) (limited to 'cogs/music') 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 @@ import os import discord import mutagen -from typing import List, Tuple, Optional, Callable, Awaitable, Union +from typing import List, Tuple, Callable, Awaitable +from os import PathLike -from . import play_utils +from cogs.music import play_utils from discord.ext import commands -from discord.commands import Option, OptionChoice +from discord.commands import OptionChoice import logging logger = logging.getLogger(__name__) @@ -16,7 +17,8 @@ class Play(commands.Cog): self.temp_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "temp") self.path_mapping = {} # Maps display names to full paths - async def _create_search_embed(self, candidates: List[str]) -> Tuple[discord.Embed, discord.ui.View]: + @staticmethod + async def _create_search_embed(candidates: List[str]) -> Tuple[discord.Embed, discord.ui.View]: """Create an embed and view for search results.""" embed = discord.Embed( title="Wyniki wyszukiwania", @@ -204,7 +206,7 @@ class Play(commands.Cog): @discord.slash_command(name="grajcuj_plik", description="grajcuj plik") async def play_file(self, ctx: discord.ApplicationContext, attachment: discord.Attachment = discord.Option(discord.Attachment, "co zagrać??", required=True)): await ctx.defer() - file_path = os.path.join(self.temp_dir, attachment.filename) + file_path: PathLike[str] | str = os.path.join(self.temp_dir, attachment.filename) await attachment.save(file_path) await play_utils.PlayUtils(self.bot).play(ctx, file_path) 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: # Boost score based on word ratio score = score * (0.7 + (0.3 * word_ratio)) - + + score = int(score) + # Ensure score is within bounds return min(100, max(0, score)) @@ -410,6 +412,9 @@ class PlayUtils: async def search_local_autocomplete(cls, query: str = None, max_results: int = 10): """Wrapper for autocomplete searches that returns more results and allows empty query.""" # For autocomplete, we want to show more options and allow empty queries + if not query: + return [] + return await cls.search_local(query, max_results=max_results, autocomplete=True) -- cgit v1.2.3