45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
from config.config_types import factory
|
|
import config.config_types as c_t
|
|
import discord
|
|
from mod_base import BasePython
|
|
|
|
import traceback
|
|
|
|
|
|
class Logging(BasePython):
|
|
def __init__(self, client):
|
|
super().__init__(client)
|
|
self.config.register("log_channel", factory(c_t.discord_types.Channel, client))
|
|
self.config.load()
|
|
|
|
async def on_log_error(self, error, *args, **kwargs):
|
|
try:
|
|
channel = self.config["log_channel"]
|
|
error = error.splitlines(keepends=True)
|
|
errors = []
|
|
for e in error:
|
|
if len(e) < 1900:
|
|
errors.append(e)
|
|
a = e
|
|
while len(a) > 1900:
|
|
errors.append(a[:1900])
|
|
a = a[1900:]
|
|
errors.append(a)
|
|
|
|
error_contents = []
|
|
while len(errors):
|
|
error_contents.append("")
|
|
while len(errors) and len(errors[0]) < 2000 - len(error_contents[-1]):
|
|
error_contents[-1] += errors.pop(0)
|
|
await channel.send("There was an error:")
|
|
for i, content in enumerate(error_contents):
|
|
embed = discord.Embed(title=f"Error {i+1}/{len(error_contents)}",
|
|
description=f"```py\n{content}\n```")
|
|
await channel.send(embed=embed)
|
|
except: # TODO: C'est pas beau mais il ne faut absolument pas que on_log_error lève une exception pour éviter
|
|
# TODO: les récursions infinies
|
|
print(traceback.format_exc())
|
|
|
|
|
|
__main_class__ = Logging
|