less repetitions and detect command even with useless args

This commit is contained in:
Mylloon 2021-07-29 01:50:11 +02:00
parent 3faf06b62f
commit 1932635db1

View file

@ -9,6 +9,9 @@ class Commandes(commands.Cog):
def __init__(self, client: commands.Bot): def __init__(self, client: commands.Bot):
self.client = client self.client = client
self.keys = load(["PREFIX"]) self.keys = load(["PREFIX"])
self.notModo = "tu n'es pas modérateur"
self.notExistingCommand = "cette commande n'existe pas"
self.alreadyExistingCommand = "cette commande existe déjà"
@commands.command() @commands.command()
async def add(self, ctx: commands.Context, commandName = None, commandMessage = None): async def add(self, ctx: commands.Context, commandName = None, commandMessage = None):
@ -20,9 +23,9 @@ class Commandes(commands.Cog):
CommandesDB().ajoutCommande(commandName, commandMessage) CommandesDB().ajoutCommande(commandName, commandMessage)
await ctx.send(f"{ctx.author.name}, commande {commandName} ajoutée !") await ctx.send(f"{ctx.author.name}, commande {commandName} ajoutée !")
else: else:
await ctx.send(f"{ctx.author.name}, cette commande existe déjà.") await ctx.send(f"{ctx.author.name}, {self.alreadyExistingCommand}.")
else: else:
await ctx.send(f"{ctx.author.name}, tu n'es pas modérateur.") await ctx.send(f"{ctx.author.name}, {self.notModo}.")
@commands.command() @commands.command()
async def remove(self, ctx: commands.Context, commandName = None): async def remove(self, ctx: commands.Context, commandName = None):
@ -34,9 +37,9 @@ class Commandes(commands.Cog):
CommandesDB().suppressionCommande(commandName) CommandesDB().suppressionCommande(commandName)
await ctx.send(f"{ctx.author.name}, commande {commandName} supprimée !") await ctx.send(f"{ctx.author.name}, commande {commandName} supprimée !")
else: else:
await ctx.send(f"{ctx.author.name}, cette commande n'existe pas.") await ctx.send(f"{ctx.author.name}, {self.notExistingCommand}.")
else: else:
await ctx.send(f"{ctx.author.name}, tu n'es pas modérateur.") await ctx.send(f"{ctx.author.name}, {self.notModo}.")
@commands.command() @commands.command()
async def list(self, ctx: commands.Context): async def list(self, ctx: commands.Context):
@ -59,13 +62,13 @@ class Commandes(commands.Cog):
CommandesDB().ajoutCommande(commandName, commandMessage) CommandesDB().ajoutCommande(commandName, commandMessage)
await ctx.send(f"{ctx.author.name}, commande {commandName} modifiée !") await ctx.send(f"{ctx.author.name}, commande {commandName} modifiée !")
else: else:
await ctx.send(f"{ctx.author.name}, cette commande n'existe pas.") await ctx.send(f"{ctx.author.name}, {self.notExistingCommand}.")
else: else:
await ctx.send(f"{ctx.author.name}, tu n'es pas modérateur.") await ctx.send(f"{ctx.author.name}, {self.notModo}.")
@commands.Cog.event() @commands.Cog.event()
async def event_message(self, message): async def event_message(self, message):
if message.content.startswith(self.keys["PREFIX"]): if message.content.startswith(self.keys["PREFIX"]):
command = CommandesDB().existeCommande(message.content[1:]) command = CommandesDB().existeCommande(message.content[1:].split(" ")[0])
if command[0]: # vérification si existe if command[0]: # vérification si existe
await message.channel.send(command[1]) # envois le contenu de la commande await message.channel.send(command[1]) # envois le contenu de la commande