Add on_log_error
This commit is contained in:
parent
2e5fe1a7e0
commit
2a073309e7
37
__init__.py
37
__init__.py
@ -1,14 +1,45 @@
|
||||
from config.config_types import factory
|
||||
import config.config_types as c_t
|
||||
import config
|
||||
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)
|
||||
print(error_contents)
|
||||
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())
|
||||
|
||||
def __dispatch__(self, event, *args, **kwargs):
|
||||
pass
|
||||
|
||||
__main_class__ = Logging
|
||||
|
Loading…
Reference in New Issue
Block a user