This commit is contained in:
Milka64 2021-02-18 21:54:01 +01:00
parent 7031a76b06
commit abb7f34d9f

View file

@ -43,11 +43,11 @@ logger.addHandler(stream_handler)
class Mybot(commands.Cog): class Mybot(commands.Cog):
#Fonctions necesaires pour Kabot. #Fonctions necesaires pour Kabot.
def __init__( def __init__(
self, self,
bot, bot,
gl_url=None, gl_url=None,
gl_token=None, gl_token=None,
gif_token=None, gif_token=None,
audio_path=None, audio_path=None,
nickname=None, nickname=None,
voice_channel=None, voice_channel=None,
@ -237,18 +237,24 @@ class Mybot(commands.Cog):
await ctx.channel.send("Exception when calling DefaultApi->gifs_search_get: %s\n" % e) await ctx.channel.send("Exception when calling DefaultApi->gifs_search_get: %s\n" % e)
else: else:
await ctx.channel.send("Exception : No api key found") await ctx.channel.send("Exception : No api key found")
@commands.guild_only() @commands.guild_only()
@commands.command() @commands.command()
async def joke(self, ctx, folder=None): async def joke(self, ctx, folder=None):
user = ctx.message.author.name try:
if not folder or not ctx.message.content: user = ctx.message.author.name
audio_file = random.choice([f"{f}" for f in Path(self.audio_path + '/').glob('**/*.mp3')]) if not folder or not ctx.message.content:
else: audio_file = random.choice([f"{f}" for f in Path(self.audio_path + '/').glob('**/*.mp3')])
folder = folder.lower() else:
audio_file = random.choice([f"{f}" for f in Path(self.audio_path + '/').glob('**/*.mp3') if folder in str(f).lower()]) folder = folder.lower()
self.sounds.append((audio_file, ctx)) audio_file = random.choice([f"{f}" for f in Path(self.audio_path + '/').glob('**/*.mp3') if folder in str(f).lower()])
if not audio_file:
ctx.channel.send("%s not found" % folder)
self.sounds.append((audio_file, ctx))
except:
e = sys.exc_info()[0]
await ctx.channel.send("Exception when calling joke: %s\n" % e)
@commands.command(help="optionnal args : [livre] [character]") @commands.command(help="optionnal args : [livre] [character]")
async def kaamelott(self, ctx, *args): async def kaamelott(self, ctx, *args):
@ -550,8 +556,8 @@ def main():
logger.info("Initialisation de Kabot") logger.info("Initialisation de Kabot")
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument( parser.add_argument(
"-c", "-c",
"--config", "--config",
help="config file", help="config file",
default="config.ini" default="config.ini"
) )
@ -587,7 +593,7 @@ def main():
gl_token = config['gitlab']['token'] gl_token = config['gitlab']['token']
gif_token = config['giphy']['token'] gif_token = config['giphy']['token']
bot = commands.Bot( bot = commands.Bot(
command_prefix='!', command_prefix='!',
) )
test = False test = False