Finished audio list generator

This commit is contained in:
2022-09-01 15:15:30 +03:00
parent 5b134e6446
commit 3c0851102d
7 changed files with 139 additions and 67 deletions

View File

@@ -4,7 +4,7 @@ import disnake
from disnake import Option, OptionType, OptionChoice
from disnake.ext import commands
from lib import list_files
from lib import ListGenerator
from lib import logger
from lib import play_audio
@@ -18,38 +18,49 @@ class Testing(commands.Cog, name='Testing'):
logger.info(f'Cog {__name__.split(".")[1]} is ready!.')
@commands.slash_command(name="play_audio",
description="Make possible playing audio by command",
options=[
Option(name="audio",
type=OptionType.string,
required=True
# choices=OptionChoice(list_to_play)
)
])
async def playaudio(self, inter: disnake.ApplicationCommandInteraction,
audio: str
):
if inter.author.voice is not None:
await inter.response.send_message(f'Played {audio}')
await inter.response.send_message(f'Played {audio}', ephemeral=True)
await play_audio(audio, self.bot, inter.author.voice.channel)
else:
await inter.response.send_message('You`re not in voice')
await inter.response.send_message('You`re not in voice', ephemeral=True)
@playaudio.autocomplete('audio')
async def list_to_play(self, inter: disnake.ApplicationCommandInteraction, current: str) -> List[OptionChoice]:
def_list = await list_files()
_def_iter = ListGenerator('audio')
_def_dict: dict = {}
for f in _def_iter:
_def_dict[f.name] = f'{f.path}/{f.name}'
_user_dict: dict = {}
try:
user_list = await list_files(str(inter.author.id))
_user_iter = ListGenerator(f'audio/{inter.author.id}')
for f in _user_iter:
_user_dict[f.name] = f'{f.path}/{f.name}'
# user_dict = []
# for _track in user_list:
except IndexError:
user_list = []
pass
_list = def_list + user_list
_dict = {}
_dict.update(_def_dict)
_dict.update(_user_dict)
return [
OptionChoice(name=choice, value=choice)
for choice in def_list if current.lower() in choice.lower()
]
OptionChoice(name=choice, value=f'{_dict[choice]}')
for choice in _dict if current.lower() in choice.lower()
]
def setup(bot): # an extension must have a setup function