From e790569a27e626d4bce7c2fedbcd452f447916c6 Mon Sep 17 00:00:00 2001 From: Milka64 Date: Wed, 6 Jan 2021 20:33:16 +0100 Subject: [PATCH] =?UTF-8?q?log=20debug=20=E2=86=92=20info?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 10 +++++----- kabot/kabot/kabot.py | 26 +++++++++++++++++++++----- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 083cc20..48f615b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,12 @@ FROM alpine WORKDIR /app VOLUME /data -RUN apk add --update musl-dev python3-dev gcc python3 py3-pip git py3-lxml libxml2 libxml2-dev py3-pynacl\ +RUN apk add --update musl-dev python3-dev gcc python3 py3-pip git py3-lxml libxml2 libxml2-dev py3-pynacl ffmpeg\ && pip3 install --upgrade pip \ && pip3 install bs4 requests giphy_client discord.py python-gitlab\ && git clone https://git.0w.tf/Milka64/kabot.git WORKDIR /app/kabot -RUN python3 bootstrap-buildout.py \ -&& bin/buildout - -CMD bin/kabot +RUN pip3 install kabot/ +RUN mkdir -p /var/log/kabot/ +RUN chmod 777 /var/log/kabot +CMD kabot -c /data/config.ini diff --git a/kabot/kabot/kabot.py b/kabot/kabot/kabot.py index caf74cf..d840d2e 100644 --- a/kabot/kabot/kabot.py +++ b/kabot/kabot/kabot.py @@ -30,31 +30,40 @@ here = os.path.dirname(os.path.abspath(__file__)) ## création de l'objet logger logger = logging.getLogger() ## definition du log level -logger.setLevel(logging.DEBUG) +logger.setLevel(logging.INFO) ## format du log formatter = logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s') ## definition du fichier de log (chemin, level, etc ...) file_handler = RotatingFileHandler('/var/log/kabot/kabot.log', 'a', 1000000, 1) -file_handler.setLevel(logging.DEBUG) +file_handler.setLevel(logging.INFO) file_handler.setFormatter(formatter) logger.addHandler(file_handler) ## definition de l'affichage des logs dans la console stream_handler = logging.StreamHandler() -stream_handler.setLevel(logging.DEBUG) +stream_handler.setLevel(logging.INFO) 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, audio_path=None): + def __init__( + self, + bot, + gl_url=None, + gl_token=None, + gif_token=None, + audio_path=None, + nickname=None, + ): self.gl_url = gl_url self.audio_path = audio_path self.gl_token = gl_token self.gif_token = gif_token self.bot = bot self.sounds = [] + self.nickname = nickname self.sounds_history = [] self.play_next.start() @@ -554,6 +563,10 @@ def main(): logger.critical('config file not found') exit(1) config.read(args.config) + if "nickname" in config['DEFAULT']: + nickname = config['DEFAULT']['nickname'] + else: + nickname = None audio_path = config['DEFAULT']['audio_path'] token = config['discord']['token'] gl_url = config['gitlab']['url'] @@ -618,6 +631,8 @@ def main(): for channel in bot.get_all_channels(): if channel.name == "général": current_chan = channel + if nickname: + await bot.user.edit(nick=nickname) await current_chan.send('Le troll est dans la place !') ctx = await bot.get_context(current_chan.last_message) join = bot.get_command('join') @@ -660,7 +675,8 @@ def main(): gl_url=gl_url, gl_token=gl_token, gif_token=gif_token, - audio_path=audio_path + audio_path=audio_path, + nickname=nickname, ) ) bot.run(token)