[base-config] Ajout de la config configured
pour ne pas executer des modules qui ne sont pas configurés (il faut donc manuellement passer cette coniguration à true dans les fichiers de config)
[mod-readrules] Ajout de la vérification de l'auteur du message [base] Ajout de la vérification de l'auteur du message
This commit is contained in:
parent
4c5820b19e
commit
a898a48393
13
main.py
13
main.py
@ -195,8 +195,10 @@ def event(func):
|
|||||||
return lambda: None
|
return lambda: None
|
||||||
else:
|
else:
|
||||||
return func(self, *args, **kwargs)
|
return func(self, *args, **kwargs)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
"""def async_event(func):
|
"""def async_event(func):
|
||||||
async def wrapper(self, *args, **kwargs):
|
async def wrapper(self, *args, **kwargs):
|
||||||
if self.reloading:
|
if self.reloading:
|
||||||
@ -205,7 +207,6 @@ def event(func):
|
|||||||
return func(self, *args, **kwargs)
|
return func(self, *args, **kwargs)
|
||||||
return wrapper"""
|
return wrapper"""
|
||||||
|
|
||||||
|
|
||||||
setup_logging()
|
setup_logging()
|
||||||
|
|
||||||
log_discord = logging.getLogger('discord')
|
log_discord = logging.getLogger('discord')
|
||||||
@ -337,9 +338,12 @@ class LBI(discord.Client):
|
|||||||
super().dispatch(event, *args, **kwargs)
|
super().dispatch(event, *args, **kwargs)
|
||||||
# Dispatch to modules
|
# Dispatch to modules
|
||||||
for module in self.modules.values():
|
for module in self.modules.values():
|
||||||
module["initialized_class"].dispatch(event, *args, **kwargs)
|
if module["initialized_class"].config.configured:
|
||||||
|
module["initialized_class"].dispatch(event, *args, **kwargs)
|
||||||
|
else:
|
||||||
|
self.warning(f"Module {module['initialized_class'].name} is not configured.")
|
||||||
|
|
||||||
#@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
|
||||||
for module in self.modules.values():
|
for module in self.modules.values():
|
||||||
@ -414,7 +418,7 @@ class ClientById:
|
|||||||
else:
|
else:
|
||||||
name = name.lower()
|
name = name.lower()
|
||||||
role = None
|
role = None
|
||||||
|
|
||||||
for guild in guilds:
|
for guild in guilds:
|
||||||
for role_ in guild.roles:
|
for role_ in guild.roles:
|
||||||
if role_.name.lower() == name:
|
if role_.name.lower() == name:
|
||||||
@ -461,6 +465,7 @@ communication = Communication(client1)
|
|||||||
async def start_bot():
|
async def start_bot():
|
||||||
await client1.start(os.environ.get("DISCORD_TOKEN"))
|
await client1.start(os.environ.get("DISCORD_TOKEN"))
|
||||||
|
|
||||||
|
|
||||||
print(os.path.join("/tmp", os.path.dirname(os.path.realpath(__file__))) + ".sock")
|
print(os.path.join("/tmp", os.path.dirname(os.path.realpath(__file__))) + ".sock")
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
@ -30,7 +30,7 @@ class BaseClass:
|
|||||||
self.objects = Objects(path=os.path.join("data", self.name.lower()))
|
self.objects = Objects(path=os.path.join("data", self.name.lower()))
|
||||||
self.config = Config(parent=self.client.config, name="mod-" + self.name.lower())
|
self.config = Config(parent=self.client.config, name="mod-" + self.name.lower())
|
||||||
self.config.init({"help_active": True, "color": 0x000000, "auth_everyone": False, "authorized_roles": [],
|
self.config.init({"help_active": True, "color": 0x000000, "auth_everyone": False, "authorized_roles": [],
|
||||||
"authorized_users": [], "command_text": self.name.lower()})
|
"authorized_users": [], "command_text": self.name.lower(), "configured": False})
|
||||||
|
|
||||||
async def send_help(self, channel):
|
async def send_help(self, channel):
|
||||||
embed = discord.Embed(
|
embed = discord.Embed(
|
||||||
@ -160,6 +160,8 @@ class BaseClass:
|
|||||||
|
|
||||||
async def on_message(self, message: discord.Message):
|
async def on_message(self, message: discord.Message):
|
||||||
"""Override this function to deactivate command_text parsing"""
|
"""Override this function to deactivate command_text parsing"""
|
||||||
|
if message.author.bot:
|
||||||
|
return
|
||||||
await self.parse_command(message)
|
await self.parse_command(message)
|
||||||
|
|
||||||
async def command(self, message, args, kwargs):
|
async def command(self, message, args, kwargs):
|
||||||
|
@ -22,13 +22,15 @@ class MainClass(BaseClassPython):
|
|||||||
"succes": "{user} a désormais accepté."})
|
"succes": "{user} a désormais accepté."})
|
||||||
|
|
||||||
async def on_message(self, message):
|
async def on_message(self, message):
|
||||||
|
if message.author.bot:
|
||||||
|
return
|
||||||
if message.channel.id == self.config.listen_chan:
|
if message.channel.id == self.config.listen_chan:
|
||||||
if message.content.lower() in self.config.passwords:
|
if message.content.lower() in self.config.passwords:
|
||||||
new_role = await self.client.id.get_role(id_=self.config.new_role, guild=message.channel.guild)
|
new_role = await self.client.id.get_role(id_=self.config.new_role, guild=message.channel.guild)
|
||||||
if new_role in message.author.roles:
|
if new_role in message.author.roles:
|
||||||
await message.author.remove_roles(new_role)
|
await message.author.remove_roles(new_role)
|
||||||
await message.author.add_roles(await self.client.id.get_role(id_=self.config.accepted_role,
|
await message.author.add_roles(await self.client.id.get_role(id_=self.config.accepted_role,
|
||||||
guild=message.channel.guild))
|
guild=message.channel.guild))
|
||||||
await message.author.send(self.config.succes_pm)
|
await message.author.send(self.config.succes_pm)
|
||||||
await message.channel.guild.get_channel(self.config.log_chan).send(
|
await message.channel.guild.get_channel(self.config.log_chan).send(
|
||||||
self.config.succes.format(user=message.author.mention))
|
self.config.succes.format(user=message.author.mention))
|
||||||
|
Loading…
Reference in New Issue
Block a user