Finished audio list generator
This commit is contained in:
@@ -21,7 +21,6 @@ class Audio(commands.Cog, name='Audio'):
|
||||
# todo: complete check activity
|
||||
@commands.Cog.listener()
|
||||
async def on_voice_state_update(self, member, before, after):
|
||||
print(type(member.roles))
|
||||
if before.channel is None and not member.bot:
|
||||
if any('Escape from Tarkov' in str(user.activity) for user in after.channel.members):
|
||||
logger.info('Skip playing by Game')
|
||||
@@ -46,12 +45,12 @@ class Audio(commands.Cog, name='Audio'):
|
||||
if audio_db is None: audio_db = []
|
||||
logger.info(f'Play audio from DB')
|
||||
full_audio = def_audio_db + audio_db
|
||||
await play_audio(random.choice(full_audio), self.bot, after.channel)
|
||||
await play_audio(f'audio/{random.choice(full_audio)}', self.bot, after.channel)
|
||||
elif len(member.roles) == 1 or _role is None:
|
||||
logger.info(f'Skip playing by role')
|
||||
elif any(str(role.id) in _role for role in member.roles):
|
||||
logger.info(f'Play audio from list by role')
|
||||
await play_audio(random.choice(def_audio_ls), self.bot, after.channel)
|
||||
await play_audio(f'audio/{random.choice(def_audio_ls)}', self.bot, after.channel)
|
||||
else:
|
||||
logger.info(f'Skip playing by any else')
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ class Bot_info(commands.Cog, name='Bot Info'):
|
||||
@commands.Cog.listener() # this is a decorator for events/listeners
|
||||
async def on_ready(self):
|
||||
logger.info(f'Cog {__name__.split(".")[1]} is ready!.')
|
||||
logger.info(f'{[names.name for names in self.bot.users]}')
|
||||
|
||||
@commands.slash_command(name="info_bot",
|
||||
description='Shows general info about bot') # this is for making a command
|
||||
|
||||
33
cogs/test.py
33
cogs/test.py
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user