[apero] J'ai apéro pour l'aniv de ma maman
This commit is contained in:
parent
50aced7c5d
commit
bca15ac34d
@ -87,7 +87,7 @@ class Config:
|
||||
with open(self.path, 'w') as file:
|
||||
toml.dump({k: v.to_save() for k, v in self.fields.items()}, file)
|
||||
|
||||
def load(self) -> None:
|
||||
def load(self, create: bool = False) -> None:
|
||||
"""
|
||||
Load config from ``self.file``
|
||||
|
||||
@ -105,10 +105,14 @@ class Config:
|
||||
3
|
||||
|
||||
|
||||
:param create: Create config file if not exists
|
||||
:return: None
|
||||
"""
|
||||
try:
|
||||
with open(self.path, 'r') as file:
|
||||
self.set(toml.load(file))
|
||||
except FileNotFoundError:
|
||||
self.save()
|
||||
|
||||
def __getitem__(self, item: str) -> Any:
|
||||
"""
|
||||
|
2
main.py
2
main.py
@ -8,6 +8,7 @@ import locale
|
||||
import logging
|
||||
import logging.config
|
||||
import os
|
||||
import traceback
|
||||
from typing import Dict
|
||||
|
||||
import discord
|
||||
@ -369,6 +370,7 @@ class LBI(discord.Client):
|
||||
# @async_event
|
||||
async def on_error(self, event_method, *args, **kwargs):
|
||||
# This event is special because it is call directly
|
||||
self.error(traceback.format_exc())
|
||||
for module in self.modules.values():
|
||||
await module["initialized_class"].on_error(event_method, *args, **kwargs)
|
||||
|
||||
|
@ -41,18 +41,20 @@ class BaseClass:
|
||||
self.config.register("command_text", factory(config_types.Str))
|
||||
self.config.register("configured", factory(config_types.Bool))
|
||||
self.config.set({"help_active": True, "color": 0x000000, "auth_everyone": False, "authorized_roles": [],
|
||||
"authorized_users": [], "command_text": self.name.lower(), "configured": False})
|
||||
"authorized_users": [], "command_text": self.name.lower(), "configured": True})
|
||||
self.config.load(create=True)
|
||||
|
||||
async def send_help(self, channel):
|
||||
embed = discord.Embed(
|
||||
title="[{nom}] - Aide".format(nom=self.name),
|
||||
description="*" + self.help["description"].format(prefix=self.client.config['prefix']) + "*",
|
||||
color=self.config.color
|
||||
color=self.config["color"]
|
||||
)
|
||||
for command, description in self.help["commands"].items():
|
||||
embed.add_field(name=command.format(prefix=self.client.config['prefix'], command=self.config.command_text),
|
||||
embed.add_field(
|
||||
name=command.format(prefix=self.client.config['prefix'], command=self.config["command_text"]),
|
||||
value="-> " + description.format(prefix=self.client.config['prefix'],
|
||||
command=self.config.command_text),
|
||||
command=self.config["command_text"]),
|
||||
inline=False)
|
||||
await channel.send(embed=embed)
|
||||
|
||||
@ -70,14 +72,14 @@ class BaseClass:
|
||||
:type guild: Int
|
||||
:type user: discord.User
|
||||
"""
|
||||
if self.config.auth_everyone:
|
||||
if self.config["auth_everyone"]:
|
||||
return True
|
||||
if user_list is None:
|
||||
user_list = self.config.authorized_users + self.client.config.admin_users
|
||||
user_list = self.config["authorized_users"] + self.client.config['admin_users']
|
||||
if user.id in user_list:
|
||||
return True
|
||||
if role_list is None:
|
||||
role_list = self.config.authorized_roles + self.client.config.admin_roles
|
||||
role_list = self.config["authorized_roles"] + self.client.config['admin_roles']
|
||||
if guild is None:
|
||||
guilds = self.client.guilds
|
||||
else:
|
||||
@ -95,7 +97,7 @@ class BaseClass:
|
||||
|
||||
:param message: message to parse
|
||||
:type message: discord.Message"""
|
||||
command = self.client.config["prefix"] + (self.config.command_text if self.config.command_text else "")
|
||||
command = self.client.config["prefix"] + (self.config["command_text"] if self.config["command_text"] else "")
|
||||
if message.content.startswith(command):
|
||||
content = message.content.split(" ", 1)[1 if " " in message.content else 0]
|
||||
sub_command, args, kwargs = self._parse_command_content(content)
|
||||
|
@ -72,21 +72,21 @@ class MainClass(BaseClassPython):
|
||||
embed = discord.Embed(
|
||||
title="[Erreur] Aïe :/",
|
||||
description="```python\n{0}```".format(traceback.format_exc()),
|
||||
color=self.config.color)
|
||||
embed.set_image(url=random.choice(self.config.memes))
|
||||
color=self.config["color"])
|
||||
embed.set_image(url=random.choice(self.config["memes"]))
|
||||
message_list = None
|
||||
|
||||
# Send message to dev channels
|
||||
for chanid in self.config.dev_chan:
|
||||
for chanid in self.config["dev_chan"]:
|
||||
try:
|
||||
await self.client.get_channel(chanid).send(
|
||||
embed=embed.set_footer(text="Ce message ne s'autodétruira pas.", icon_url=self.config.icon))
|
||||
embed=embed.set_footer(text="Ce message ne s'autodétruira pas.", icon_url=self.config["icon"]))
|
||||
except BaseException as e:
|
||||
raise e
|
||||
# Send message to current channel if exists
|
||||
if channel is not None:
|
||||
message = await channel.send(embed=embed.set_footer(text="Ce message va s'autodétruire dans une minute",
|
||||
icon_url=self.config.icon))
|
||||
icon_url=self.config["icon"]))
|
||||
msg_id = {"channel_id": message.channel.id, "msg_id": message.id}
|
||||
self.errorsList.append(msg_id)
|
||||
# Save message in errorsList now to keep them if a reboot happend during next 60 seconds
|
||||
|
Loading…
Reference in New Issue
Block a user