adding comments and removing certain methods from class
This commit is contained in:
parent
c50cc204d9
commit
f84cbc5838
2 changed files with 25 additions and 24 deletions
|
@ -1,6 +1,6 @@
|
||||||
from twitchio.ext import commands
|
from twitchio.ext import commands
|
||||||
from utils.core import load, listCommands
|
from utils.core import load, listCommands
|
||||||
from utils.commands import CommandesDB
|
from utils.commands import CommandesDB, existeCommande, existeTouteCommande
|
||||||
|
|
||||||
def prepare(client: commands.Bot):
|
def prepare(client: commands.Bot):
|
||||||
client.add_cog(Commandes(client))
|
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:
|
if commandName == None or commandMessage == None:
|
||||||
return
|
return
|
||||||
if ctx.author.is_mod:
|
if ctx.author.is_mod:
|
||||||
if CommandesDB().existeTouteCommande(self.client, commandName)[0] == False:
|
if existeTouteCommande(self.client, commandName)[0] == False:
|
||||||
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:
|
||||||
|
@ -33,7 +33,7 @@ class Commandes(commands.Cog): # Les méthodes qui ont no_global_checks de Vrai
|
||||||
if commandName == None:
|
if commandName == None:
|
||||||
return
|
return
|
||||||
if ctx.author.is_mod:
|
if ctx.author.is_mod:
|
||||||
if CommandesDB().existeCommande(commandName)[0]:
|
if existeCommande(commandName)[0]:
|
||||||
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:
|
||||||
|
@ -72,7 +72,7 @@ class Commandes(commands.Cog): # Les méthodes qui ont no_global_checks de Vrai
|
||||||
if commandName == None or commandMessage == None:
|
if commandName == None or commandMessage == None:
|
||||||
return
|
return
|
||||||
if ctx.author.is_mod:
|
if ctx.author.is_mod:
|
||||||
if CommandesDB().existeCommande(commandName)[0]:
|
if existeCommande(commandName)[0]:
|
||||||
CommandesDB().suppressionCommande(commandName)
|
CommandesDB().suppressionCommande(commandName)
|
||||||
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 !")
|
||||||
|
@ -84,6 +84,6 @@ class Commandes(commands.Cog): # Les méthodes qui ont no_global_checks de Vrai
|
||||||
@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:].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
|
if command[0]: # vérification si existe
|
||||||
await message.channel.send(f"@{message.author.name}, {command[1]}") # envois le contenu de la commande
|
await message.channel.send(f"@{message.author.name}, {command[1]}") # envois le contenu de la commande
|
||||||
|
|
|
@ -39,23 +39,24 @@ class CommandesDB(Database):
|
||||||
"""Retourne la liste des commandes."""
|
"""Retourne la liste des commandes."""
|
||||||
return self.affichageResultat(self.requete("SELECT * FROM commandes;"))
|
return self.affichageResultat(self.requete("SELECT * FROM commandes;"))
|
||||||
|
|
||||||
def existeCommande(self, command: str):
|
def existeCommande(command: str):
|
||||||
commandes = self.listeCommande()
|
"""Vérifie qu'une commande existe dans la base de donnée."""
|
||||||
for commande in commandes:
|
commandes = CommandesDB().listeCommande()
|
||||||
if commande[0] == command:
|
for commande in commandes:
|
||||||
return (True, commande[1])
|
if commande[0] == command:
|
||||||
return (False,)
|
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 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,)
|
||||||
|
|
Loading…
Reference in a new issue