mirror of
https://github.com/Floriansylvain/Risitas_BOT.git
synced 2026-08-19 11:43:16 +02:00
🎨 - The owner can now request logs.txt with a command
This commit is contained in:
+2
-2
@@ -134,5 +134,5 @@ private.py
|
|||||||
# Generated JPEG File
|
# Generated JPEG File
|
||||||
acc.jpeg
|
acc.jpeg
|
||||||
|
|
||||||
# Script for CI
|
# Logs
|
||||||
.sh
|
logs.txt
|
||||||
|
|||||||
+22
-3
@@ -3,14 +3,25 @@ from time import time
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from miscellaneous import spellchecker
|
from miscellaneous import spellchecker
|
||||||
|
import logging
|
||||||
import os, sys
|
import os, sys
|
||||||
import discord
|
import discord
|
||||||
|
|
||||||
|
|
||||||
|
print('Loading started')
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix='$')
|
bot = commands.Bot(command_prefix='$')
|
||||||
startup_extensions = ["cmd_other", "cmd_lol", "cmd_osu", "cmd_twitch"]
|
startup_extensions = ["cmd_other", "cmd_lol", "cmd_osu", "cmd_twitch"]
|
||||||
|
|
||||||
|
startup_date = datetime.now()
|
||||||
time_s = time()
|
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
|
@bot.event
|
||||||
@@ -23,8 +34,9 @@ async def on_ready():
|
|||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_command_error(ctx, error):
|
async def on_command_error(ctx, error):
|
||||||
print(datetime.now().strftime("[%H:%M:%S]") + ' \'' + str(error) + '\' from ' +str(ctx.author) +
|
logger.info(datetime.now().strftime("[%d-%m-%y][%H:%M:%S]") +
|
||||||
' on ' + (ctx.message.guild.name if ctx.message.guild is not None else 'DMs') + '.')
|
' \'' + 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):
|
if isinstance(error, commands.CommandNotFound):
|
||||||
await ctx.send(spellchecker(str(ctx.message.content)[1:]))
|
await ctx.send(spellchecker(str(ctx.message.content)[1:]))
|
||||||
else:
|
else:
|
||||||
@@ -54,6 +66,13 @@ async def update(ctx):
|
|||||||
os.execl(sys.executable, os.path.abspath(__file__), *sys.argv)
|
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__":
|
if __name__ == "__main__":
|
||||||
for extension in startup_extensions:
|
for extension in startup_extensions:
|
||||||
bot.load_extension('ext.' + extension)
|
bot.load_extension('ext.' + extension)
|
||||||
|
|||||||
Reference in New Issue
Block a user