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