From a898a48393a2cc09c38c10314a554ab30f35dd87 Mon Sep 17 00:00:00 2001 From: Louis Chauvet Date: Sun, 5 Apr 2020 14:30:10 +0200 Subject: [PATCH] =?UTF-8?q?[base-config]=20Ajout=20de=20la=20config=20`con?= =?UTF-8?q?figured`=20pour=20ne=20pas=20executer=20des=20modules=20qui=20n?= =?UTF-8?q?e=20sont=20pas=20configur=C3=A9s=20(il=20faut=20donc=20manuelle?= =?UTF-8?q?ment=20passer=20cette=20coniguration=20=C3=A0=20true=20dans=20l?= =?UTF-8?q?es=20fichiers=20de=20config)=20[mod-readrules]=20Ajout=20de=20l?= =?UTF-8?q?a=20v=C3=A9rification=20de=20l'auteur=20du=20message=20[base]?= =?UTF-8?q?=20Ajout=20de=20la=20v=C3=A9rification=20de=20l'auteur=20du=20m?= =?UTF-8?q?essage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 13 +++++++++---- modules/base/Base.py | 4 +++- modules/readrules/__init__.py | 4 +++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index fb8210a..271a58a 100644 --- a/main.py +++ b/main.py @@ -195,8 +195,10 @@ def event(func): return lambda: None else: return func(self, *args, **kwargs) + return wrapper + """def async_event(func): async def wrapper(self, *args, **kwargs): if self.reloading: @@ -205,7 +207,6 @@ def event(func): return func(self, *args, **kwargs) return wrapper""" - setup_logging() log_discord = logging.getLogger('discord') @@ -337,9 +338,12 @@ class LBI(discord.Client): super().dispatch(event, *args, **kwargs) # Dispatch to modules 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): # This event is special because it is call directly for module in self.modules.values(): @@ -414,7 +418,7 @@ class ClientById: else: name = name.lower() role = None - + for guild in guilds: for role_ in guild.roles: if role_.name.lower() == name: @@ -461,6 +465,7 @@ communication = Communication(client1) async def start_bot(): await client1.start(os.environ.get("DISCORD_TOKEN")) + print(os.path.join("/tmp", os.path.dirname(os.path.realpath(__file__))) + ".sock") loop = asyncio.get_event_loop() diff --git a/modules/base/Base.py b/modules/base/Base.py index 6d75f33..0afa54f 100644 --- a/modules/base/Base.py +++ b/modules/base/Base.py @@ -30,7 +30,7 @@ class BaseClass: 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.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): embed = discord.Embed( @@ -160,6 +160,8 @@ class BaseClass: async def on_message(self, message: discord.Message): """Override this function to deactivate command_text parsing""" + if message.author.bot: + return await self.parse_command(message) async def command(self, message, args, kwargs): diff --git a/modules/readrules/__init__.py b/modules/readrules/__init__.py index 3e5a21c..d54fbd2 100644 --- a/modules/readrules/__init__.py +++ b/modules/readrules/__init__.py @@ -22,13 +22,15 @@ class MainClass(BaseClassPython): "succes": "{user} a désormais accepté."}) async def on_message(self, message): + if message.author.bot: + return if message.channel.id == self.config.listen_chan: 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) if new_role in message.author.roles: await message.author.remove_roles(new_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.channel.guild.get_channel(self.config.log_chan).send( self.config.succes.format(user=message.author.mention))