From a8cc570aa4901f3d5f707b089c522e0c9052f746 Mon Sep 17 00:00:00 2001 From: Milka64 Date: Mon, 4 Jan 2021 18:21:02 +0100 Subject: [PATCH] add audio path in config file --- config.ini.sample | 4 ++++ kabot/kabot/kabot.py | 17 ++++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/config.ini.sample b/config.ini.sample index 2ebda8f..4c440a9 100644 --- a/config.ini.sample +++ b/config.ini.sample @@ -1,3 +1,7 @@ +[DEFAULT] + +audio_path = /tmp/ + [discord] token = diff --git a/kabot/kabot/kabot.py b/kabot/kabot/kabot.py index d49bc54..3168ffb 100644 --- a/kabot/kabot/kabot.py +++ b/kabot/kabot/kabot.py @@ -47,8 +47,9 @@ logger.addHandler(stream_handler) class Mybot(commands.Cog): #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.audio_path = audio_path self.gl_token = gl_token self.gif_token = gif_token self.bot = bot @@ -233,10 +234,10 @@ class Mybot(commands.Cog): async def joke(self, ctx, folder=None): user = ctx.message.author.name 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: 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)) @commands.command(help="optionnal args : [livre] [character]") @@ -433,10 +434,10 @@ class Mybot(commands.Cog): user = ctx.message.author.name print(user) try: - audio_file = random.choice([f for f in os.listdir(here + '/Audio/%s/' % user) if f.endswith('.mp3')]) - audio_file = here + '/Audio/%s/' % user + audio_file + audio_file = random.choice([f for f in os.listdir(audio_path + '/%s/' % user) if f.endswith('.mp3')]) + audio_file = self.audio_path + '/%s/' % user + audio_file 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)) #Fin des commandes pour faire mumuse avec Kabot. @@ -539,6 +540,7 @@ def main(): logger.info("Initialisation de Kabot") config = configparser.ConfigParser() config.read('config.ini') + audio_path = config['DEFAULT']['audio_path'] token = config['discord']['token'] gl_url = config['gitlab']['url'] gl_token = config['gitlab']['token'] @@ -643,7 +645,8 @@ def main(): bot, gl_url=gl_url, gl_token=gl_token, - gif_token=gif_token + gif_token=gif_token, + audio_path=audio_path ) ) bot.run(token)