add audio path in config file

This commit is contained in:
Milka64 2021-01-04 18:21:02 +01:00
parent 21c7969b2a
commit a8cc570aa4
2 changed files with 14 additions and 7 deletions

View file

@ -1,3 +1,7 @@
[DEFAULT]
audio_path = /tmp/
[discord] [discord]
token = <discord_token> token = <discord_token>

View file

@ -47,8 +47,9 @@ logger.addHandler(stream_handler)
class Mybot(commands.Cog): class Mybot(commands.Cog):
#Fonctions necesaires pour Kabot. #Fonctions necesaires pour Kabot.
def __init__(self, bot, gl_url=None, gl_token=None, gif_token=None): def __init__(self, bot, gl_url=None, gl_token=None, gif_token=None, audio_path=None):
self.gl_url = gl_url self.gl_url = gl_url
self.audio_path = audio_path
self.gl_token = gl_token self.gl_token = gl_token
self.gif_token = gif_token self.gif_token = gif_token
self.bot = bot self.bot = bot
@ -233,10 +234,10 @@ class Mybot(commands.Cog):
async def joke(self, ctx, folder=None): async def joke(self, ctx, folder=None):
user = ctx.message.author.name user = ctx.message.author.name
if not folder or not ctx.message.content: if not folder or not ctx.message.content:
audio_file = random.choice([f"{f}" for f in Path(here + '/Audio/').glob('**/*.mp3')]) audio_file = random.choice([f"{f}" for f in Path(self.audio_path + '/').glob('**/*.mp3')])
else: else:
folder = folder.lower() folder = folder.lower()
audio_file = random.choice([f"{f}" for f in Path(here + '/Audio/').glob('**/*.mp3') if folder in str(f).lower()]) audio_file = random.choice([f"{f}" for f in Path(self.audio_path + '/').glob('**/*.mp3') if folder in str(f).lower()])
self.sounds.append((audio_file, ctx)) self.sounds.append((audio_file, ctx))
@commands.command(help="optionnal args : [livre] [character]") @commands.command(help="optionnal args : [livre] [character]")
@ -433,10 +434,10 @@ class Mybot(commands.Cog):
user = ctx.message.author.name user = ctx.message.author.name
print(user) print(user)
try: try:
audio_file = random.choice([f for f in os.listdir(here + '/Audio/%s/' % user) if f.endswith('.mp3')]) audio_file = random.choice([f for f in os.listdir(audio_path + '/%s/' % user) if f.endswith('.mp3')])
audio_file = here + '/Audio/%s/' % user + audio_file audio_file = self.audio_path + '/%s/' % user + audio_file
except: except:
audio_file = random.choice([f"{f}" for f in Path(here + '/Audio/').glob('**/*.mp3')]) audio_file = random.choice([f"{f}" for f in Path(self.audio_path + '/').glob('**/*.mp3')])
self.sounds.append((audio_file, ctx)) self.sounds.append((audio_file, ctx))
#Fin des commandes pour faire mumuse avec Kabot. #Fin des commandes pour faire mumuse avec Kabot.
@ -539,6 +540,7 @@ def main():
logger.info("Initialisation de Kabot") logger.info("Initialisation de Kabot")
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read('config.ini') config.read('config.ini')
audio_path = config['DEFAULT']['audio_path']
token = config['discord']['token'] token = config['discord']['token']
gl_url = config['gitlab']['url'] gl_url = config['gitlab']['url']
gl_token = config['gitlab']['token'] gl_token = config['gitlab']['token']
@ -643,7 +645,8 @@ def main():
bot, bot,
gl_url=gl_url, gl_url=gl_url,
gl_token=gl_token, gl_token=gl_token,
gif_token=gif_token gif_token=gif_token,
audio_path=audio_path
) )
) )
bot.run(token) bot.run(token)