From f9655b9f90ae4034e68bd15a9cfec01165641987 Mon Sep 17 00:00:00 2001 From: Florian SYLVAIN Date: Sun, 14 Mar 2021 01:28:54 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20-=20The=20owner=20can=20now=20re?= =?UTF-8?q?quest=20logs.txt=20with=20a=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 4 ++-- python/main.py | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index c92c62e..b5b1ac7 100644 --- a/.gitignore +++ b/.gitignore @@ -134,5 +134,5 @@ private.py # Generated JPEG File acc.jpeg -# Script for CI -.sh +# Logs +logs.txt diff --git a/python/main.py b/python/main.py index 1169cb5..18cc5a0 100644 --- a/python/main.py +++ b/python/main.py @@ -3,14 +3,25 @@ from time import time from datetime import datetime from discord.ext import commands from miscellaneous import spellchecker +import logging import os, sys import discord +print('Loading started') + bot = commands.Bot(command_prefix='$') startup_extensions = ["cmd_other", "cmd_lol", "cmd_osu", "cmd_twitch"] + +startup_date = datetime.now() time_s = time() -print('Loading started') + +formatter = logging.Formatter('%(message)s') +handler = logging.FileHandler('logs.txt') +handler.setFormatter(formatter) +logger = logging.getLogger(__name__) +logger.addHandler(handler) +logger.setLevel(logging.INFO) @bot.event @@ -23,8 +34,9 @@ async def on_ready(): @bot.event async def on_command_error(ctx, error): - print(datetime.now().strftime("[%H:%M:%S]") + ' \'' + str(error) + '\' from ' +str(ctx.author) + - ' on ' + (ctx.message.guild.name if ctx.message.guild is not None else 'DMs') + '.') + logger.info(datetime.now().strftime("[%d-%m-%y][%H:%M:%S]") + + ' \'' + str(error) + '\' from ' +str(ctx.author) + ' on ' + + (ctx.message.guild.name if ctx.message.guild is not None else 'DMs') + '.') if isinstance(error, commands.CommandNotFound): await ctx.send(spellchecker(str(ctx.message.content)[1:])) else: @@ -54,6 +66,13 @@ async def update(ctx): os.execl(sys.executable, os.path.abspath(__file__), *sys.argv) +@bot.command(hidden=True) +@commands.is_owner() +async def getlogs(ctx): + await ctx.send('Logs since ' + startup_date.strftime("``[%d-%m-%y | %H:%M:%S]``"), + file=discord.File('logs.txt')) + + if __name__ == "__main__": for extension in startup_extensions: bot.load_extension('ext.' + extension)