Ajout des warns et des infos
This commit is contained in:
parent
2f1dc1f4dc
commit
ed56e5ee3a
63
__init__.py
63
__init__.py
@ -9,36 +9,51 @@ import traceback
|
|||||||
class Logging(BasePython):
|
class Logging(BasePython):
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
super().__init__(client)
|
super().__init__(client)
|
||||||
self.config.register("log_channel", factory(c_t.discord_types.Channel, client))
|
self.config.register("error_channels", factory(c_t.List, factory(c_t.discord_types.Channel, client)))
|
||||||
|
self.config.register("info_channels", factory(c_t.List, factory(c_t.discord_types.Channel, client)))
|
||||||
|
self.config.register("warning_channels", factory(c_t.List, factory(c_t.discord_types.Channel, client)))
|
||||||
self.config.load()
|
self.config.load()
|
||||||
|
|
||||||
async def on_log_error(self, error, *args, **kwargs):
|
async def send_splited_embed(self, content, channels, title):
|
||||||
try:
|
h = hex(abs(hash(content)))
|
||||||
channel = self.config["log_channel"]
|
content = content.splitlines(keepends=True)
|
||||||
error = error.splitlines(keepends=True)
|
contents = []
|
||||||
errors = []
|
for c in content:
|
||||||
for e in error:
|
while len(c) > 1900:
|
||||||
if len(e) < 1900:
|
contents.append(c[:1900])
|
||||||
errors.append(e)
|
c = c[1900:]
|
||||||
a = e
|
contents.append(c)
|
||||||
while len(a) > 1900:
|
|
||||||
errors.append(a[:1900])
|
|
||||||
a = a[1900:]
|
|
||||||
errors.append(a)
|
|
||||||
|
|
||||||
error_contents = []
|
contents_list = []
|
||||||
while len(errors):
|
while len(contents):
|
||||||
error_contents.append("")
|
contents_list.append("")
|
||||||
while len(errors) and len(errors[0]) < 2000 - len(error_contents[-1]):
|
while len(contents) and len(contents[0]) < 2000 - len(contents_list[-1]):
|
||||||
error_contents[-1] += errors.pop(0)
|
contents_list[-1] += contents.pop(0)
|
||||||
await channel.send("There was an error:")
|
embeds = []
|
||||||
for i, content in enumerate(error_contents):
|
for i, content in enumerate(contents_list):
|
||||||
embed = discord.Embed(title=f"Error {i+1}/{len(error_contents)}",
|
embed = discord.Embed(title=f"{title.title()} - {h[2:8]} - {i + 1}/{len(contents_list)}",
|
||||||
description=f"```py\n{content}\n```")
|
description=f"```py\n{content}\n```")
|
||||||
|
embed.set_footer(text=h[2:])
|
||||||
|
embeds.append(embed)
|
||||||
|
for channel in channels:
|
||||||
|
try:
|
||||||
|
await channel.send(f"New {title.lower()} - {h[2:8]}:")
|
||||||
|
for embed in embeds:
|
||||||
await channel.send(embed=embed)
|
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
|
except: # TODO: C'est pas beau mais il ne faut absolument pas lever une exception pour éviter les récursions infinies
|
||||||
# TODO: les récursions infinies
|
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
|
|
||||||
|
async def on_log_info(self, info, *args, **kwargs):
|
||||||
|
channels = self.config["info_channels"]
|
||||||
|
await self.send_splited_embed(info, channels, "info")
|
||||||
|
|
||||||
|
async def on_log_error(self, error, *args, **kwargs):
|
||||||
|
channels = self.config["error_channels"]
|
||||||
|
await self.send_splited_embed(error, channels, "error")
|
||||||
|
|
||||||
|
async def on_log_warning(self, warning, *args, **kwargs):
|
||||||
|
channels = self.config["warning_channels"]
|
||||||
|
await self.send_splited_embed(warning, channels, "warning")
|
||||||
|
|
||||||
|
|
||||||
__main_class__ = Logging
|
__main_class__ = Logging
|
||||||
|
Loading…
Reference in New Issue
Block a user