From f84cbc58385ea4638ebf5be9cc4477eb00741562 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 30 Jul 2021 14:04:57 +0200 Subject: [PATCH] adding comments and removing certain methods from class --- src/modules/commandes.py | 10 +++++----- src/utils/commands.py | 39 ++++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/modules/commandes.py b/src/modules/commandes.py index 67a610f..d7f8dc0 100644 --- a/src/modules/commandes.py +++ b/src/modules/commandes.py @@ -1,6 +1,6 @@ from twitchio.ext import commands from utils.core import load, listCommands -from utils.commands import CommandesDB +from utils.commands import CommandesDB, existeCommande, existeTouteCommande def prepare(client: commands.Bot): client.add_cog(Commandes(client)) @@ -19,7 +19,7 @@ class Commandes(commands.Cog): # Les méthodes qui ont no_global_checks de Vrai if commandName == None or commandMessage == None: return if ctx.author.is_mod: - if CommandesDB().existeTouteCommande(self.client, commandName)[0] == False: + if existeTouteCommande(self.client, commandName)[0] == False: CommandesDB().ajoutCommande(commandName, commandMessage) await ctx.send(f"@{ctx.author.name}, commande {commandName} ajoutée !") else: @@ -33,7 +33,7 @@ class Commandes(commands.Cog): # Les méthodes qui ont no_global_checks de Vrai if commandName == None: return if ctx.author.is_mod: - if CommandesDB().existeCommande(commandName)[0]: + if existeCommande(commandName)[0]: CommandesDB().suppressionCommande(commandName) await ctx.send(f"@{ctx.author.name}, commande {commandName} supprimée !") else: @@ -72,7 +72,7 @@ class Commandes(commands.Cog): # Les méthodes qui ont no_global_checks de Vrai if commandName == None or commandMessage == None: return if ctx.author.is_mod: - if CommandesDB().existeCommande(commandName)[0]: + if existeCommande(commandName)[0]: CommandesDB().suppressionCommande(commandName) CommandesDB().ajoutCommande(commandName, commandMessage) await ctx.send(f"@{ctx.author.name}, commande {commandName} modifiée !") @@ -84,6 +84,6 @@ class Commandes(commands.Cog): # Les méthodes qui ont no_global_checks de Vrai @commands.Cog.event() async def event_message(self, message): if message.content.startswith(self.keys["PREFIX"]): - command = CommandesDB().existeCommande(message.content[1:].split(" ")[0]) # récupère le nom de la commande + command = existeCommande(message.content[1:].split(" ")[0]) # récupère le nom de la commande if command[0]: # vérification si existe await message.channel.send(f"@{message.author.name}, {command[1]}") # envois le contenu de la commande diff --git a/src/utils/commands.py b/src/utils/commands.py index 877df2e..9f31741 100644 --- a/src/utils/commands.py +++ b/src/utils/commands.py @@ -39,23 +39,24 @@ class CommandesDB(Database): """Retourne la liste des commandes.""" return self.affichageResultat(self.requete("SELECT * FROM commandes;")) - def existeCommande(self, command: str): - commandes = self.listeCommande() - for commande in commandes: - if commande[0] == command: - return (True, commande[1]) - return (False,) - - def existeTouteCommande(self, client, commande: str): - commandes = [] - for command in self.listeCommande(): - commandes.append(command[0]) - for command in listCommands(client): - commandes.append(command.name) - if command.aliases: - for comm in command.aliases: - commandes.append(comm) - if commande in commandes: - return (True,) - return (False,) +def existeCommande(command: str): + """Vérifie qu'une commande existe dans la base de donnée.""" + commandes = CommandesDB().listeCommande() + for commande in commandes: + if commande[0] == command: + return (True, commande[1]) + return (False,) +def existeTouteCommande(client, commande: str): + """Vérifie qu'une commande existe dans la base de donnée et dans le bot en lui-même.""" + commandes = [] + for command in CommandesDB().listeCommande(): + commandes.append(command[0]) + for command in listCommands(client): + commandes.append(command.name) + if command.aliases: + for comm in command.aliases: + commandes.append(comm) + if commande in commandes: + return (True,) + return (False,)