From 5fc4534d665ba3513695f22a8a2f2c73278af57a Mon Sep 17 00:00:00 2001 From: Louis Chauvet Date: Mon, 6 Apr 2020 10:10:30 +0200 Subject: [PATCH] =?UTF-8?q?[mod-base]=20R=C3=A9paration=20du=20parser=20[m?= =?UTF-8?q?od-newmember]=20J'avais=20oubli=C3=A9=20de=20supprimer=20des=20?= =?UTF-8?q?awaits=20pour=20self.client.id.get=5Frole=20[mod-newmember]=20J?= =?UTF-8?q?'avais=20oubli=C3=A9=20de=20supprimer=20des=20awaits=20pour=20s?= =?UTF-8?q?elf.client.id.get=5Frole?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/base/Base.py | 22 ++++++++++------------ modules/newmember/__init__.py | 12 ++++++------ modules/readrules/__init__.py | 6 +++--- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/modules/base/Base.py b/modules/base/Base.py index 9401fa0..37aedd2 100644 --- a/modules/base/Base.py +++ b/modules/base/Base.py @@ -80,24 +80,20 @@ class BaseClass: async def parse_command(self, message): """Parse a command_text from received message and execute function - %git update - com_update(m..) Parse message like `{prefix}{command_text} subcommand` and call class method `com_{subcommand}`. :param message: message to parse :type message: discord.Message""" - if message.content.startswith( - self.client.config["prefix"] + (self.config.command_text if self.config.command_text else "")): - - content = message.content.lstrip( - 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] sub_command, args, kwargs = self._parse_command_content(content) sub_command = "com_" + sub_command if self.auth(message.author): if sub_command in dir(self): await self.__getattribute__(sub_command)(message, args, kwargs) else: - await self.command(message, [sub_command[4:]] + args, kwargs) + await self.command(message, args, kwargs) else: await self.unauthorized(message) @@ -112,19 +108,21 @@ class BaseClass: :type content: str :return: parsed arguments: [subcommand, [arg1, arg2, ...], [(option1, arg1), (option2, arg2), ...]] - :rtype: list[str, list, list]""" + :rtype: tuple[str, list, list]""" if not len(content.split()): return "", [], [] # Sub_command sub_command = content.split()[0] - args_ = [] + args_ = [sub_command] kwargs = [] if len(content.split()) > 1: + # Remove subcommand + content = content.lstrip(sub_command) # Take the other part of command_text - content = content.split(" ", 1)[1].replace("\"", "\"\"") + content = content.lstrip().replace("\"", "\"\"") # Splitting around quotes quotes = [element.split("\" ") for element in content.split(" \"")] - # Split all sub chains but brute chains and flat the resulting list + # Split all sub chains but raw chains and flat the resulting list args = [item.split() if item[0] != "\"" else [item, ] for sublist in quotes for item in sublist] # Second plating args = [item for sublist in args for item in sublist] diff --git a/modules/newmember/__init__.py b/modules/newmember/__init__.py index 6274494..7a9f133 100644 --- a/modules/newmember/__init__.py +++ b/modules/newmember/__init__.py @@ -18,14 +18,14 @@ class MainClass(BaseClassPython): guild = self.client.get_guild(self.client.config.main_guild) for i, member in enumerate(guild.members): if len(member.roles) == 1: - await member.add_roles(await self.client.id.get_role(id_=self.config.new_role, - guilds=[self.client.get_guild( - self.client.config.main_guild)])) + await member.add_roles(self.client.id.get_role(id_=self.config.new_role, + guilds=[self.client.get_guild( + self.client.config.main_guild)])) if i % 50 == 0: self.client.log(f"Attribution des roles automatique manqués... {i}/{len(guild.members)}") async def on_member_join(self, member): - await member.add_roles(await self.client.id.get_role(id_=self.config.new_role, - guilds=[self.client.get_guild( - self.client.config.main_guild)])) + await member.add_roles(self.client.id.get_role(id_=self.config.new_role, + guilds=[self.client.get_guild( + self.client.config.main_guild)])) await member.send(self.config.motd) diff --git a/modules/readrules/__init__.py b/modules/readrules/__init__.py index d867413..be2c401 100644 --- a/modules/readrules/__init__.py +++ b/modules/readrules/__init__.py @@ -26,11 +26,11 @@ class MainClass(BaseClassPython): 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, guilds=[message.channel.guild]) + new_role = self.client.id.get_role(id_=self.config.new_role, guilds=[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])) + await message.author.add_roles(self.client.id.get_role(id_=self.config.accepted_role, + 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))