aboutsummaryrefslogtreecommitdiffstats
path: root/cogs/music
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--cogs/music/play.py12
-rw-r--r--cogs/music/play_utils.py7
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 @@
1import os 1import os
2import discord 2import discord
3import mutagen 3import mutagen
4from typing import List, Tuple, Optional, Callable, Awaitable, Union 4from typing import List, Tuple, Callable, Awaitable
5from os import PathLike
5 6
6from . import play_utils 7from cogs.music import play_utils
7from discord.ext import commands 8from discord.ext import commands
8from discord.commands import Option, OptionChoice 9from discord.commands import OptionChoice
9import logging 10import logging
10 11
11logger = logging.getLogger(__name__) 12logger = 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