From 3d690379f7373043bd397ab42bb678556060e7d4 Mon Sep 17 00:00:00 2001 From: Milka64 Date: Sat, 25 Apr 2020 21:44:18 +0200 Subject: [PATCH] fix path variable #4 --- kabot/kabot/kabot.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/kabot/kabot/kabot.py b/kabot/kabot/kabot.py index b38f62d..4e8582c 100644 --- a/kabot/kabot/kabot.py +++ b/kabot/kabot/kabot.py @@ -18,6 +18,8 @@ from pathlib import Path from giphy_client.rest import ApiException from bs4 import BeautifulSoup as bs +here = os.path.dirname(os.path.abspath(__file__)) + class Mybot(commands.Cog): def __init__(self, bot): self.bot = bot @@ -40,10 +42,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 for f in Path('/home/mika/kabot/kabot/kabot/Audio/').glob('**/*.mp3')]) + audio_file = random.choice([f for f in Path(here + '/Audio/').glob('**/*.mp3')]) else: folder = folder.lower() - audio_file = random.choice([f for f in Path('/home/mika/kabot/kabot/kabot/Audio/').glob('**/*.mp3') if folder in str(f).lower()]) + audio_file = random.choice([f for f in Path(here + '/Audio/').glob('**/*.mp3') if folder in str(f).lower()]) self.sounds.append((audio_file,ctx)) @commands.command() @@ -77,10 +79,10 @@ class Mybot(commands.Cog): user = ctx.message.author.name print(user) try: - audio_file = random.choice([f for f in os.listdir('/home/mika/kabot/kabot/kabot/Audio/%s/' % user) if f.endswith('.mp3')]) - audio_file = '/home/mika/kabot/kabot/kabot/Audio/%s/' % user + audio_file + 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 except: - audio_file = random.choice([f for f in Path('/home/mika/kabot/kabot/kabot/Audio/').glob('**/*.mp3')]) + audio_file = random.choice([f for f in Path(here + '/Audio/').glob('**/*.mp3')]) self.sounds.append((audio_file,ctx)) @commands.command(help='Update local repo') @@ -102,7 +104,7 @@ class Mybot(commands.Cog): @commands.command(help='count lines numbers in quote file') async def lines(self, ctx): - path = '/home/mika/.kabot/%s.log' % ctx.channel + path = here + '/' + ctx.channel with open(path, 'r') as f: lines = f.read().splitlines() nb_lines = len(lines) @@ -201,7 +203,7 @@ class Mybot(commands.Cog): @commands.command(help="optionnal args : ") async def contrepeterie(self, ctx, *args): response = None - path = '/home/mika/kabot/kabot/kabot/ressources/contrepeteries.txt' + path = here + '/ressources/contrepeteries.txt' lines = open(path).read().splitlines() myline =random.choice(lines) @@ -336,7 +338,7 @@ class Mybot(commands.Cog): def get_word(word_type): content = [] - with open("/home/mika/kabot/kabot/kabot/ressources/base_kml.xml", "r", encoding="ISO-8859-1") as file: + with open(here + "/ressources/base_kml.xml", "r", encoding="ISO-8859-1") as file: content = file.readlines() content = "".join(content) bs_content = bs(content, 'lxml') @@ -459,7 +461,7 @@ def main(): if bot.user in message.mentions \ and len(message.mentions) < 3 \ and len(message.content.splitlines()) == 1: - path = '/home/mika/.kabot/%s.log' % message.channel + path = '/data/log/%s.log' % message.channel with open(path, 'r') as f : lines = f.read().splitlines() if not message.content in lines: