Modifications

* stderr
* Refactor
* Rename db from sqlite3 to sqlite extension
This commit is contained in:
Mylloon 2024-02-06 12:04:55 +01:00
parent 1a630d73dc
commit f979b8c4c1
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 6 additions and 8 deletions

2
.gitignore vendored
View file

@ -6,4 +6,4 @@ __pycache__
.vscode/ .vscode/
.env .env
*.sqlite3 *.sqlite

View file

@ -21,9 +21,6 @@ class Commandes(Cog):
self.prefix = load(["PREFIX"])["PREFIX"] self.prefix = load(["PREFIX"])["PREFIX"]
self.not_a_mod = "tu n'es pas modérateur" self.not_a_mod = "tu n'es pas modérateur"
self.unknown_command = "cette commande n'existe pas" self.unknown_command = "cette commande n'existe pas"
self.existing_command = (
f"cette commande existe déjà, {self.prefix}edit <name> <msg> pour l'éditer"
)
@new(name="add", aliases=["ajout", "ajouter"], no_global_checks=True) @new(name="add", aliases=["ajout", "ajouter"], no_global_checks=True)
async def _add( async def _add(
@ -43,7 +40,7 @@ class Commandes(Cog):
CommandesDB().ajoutCommande(name, message) CommandesDB().ajoutCommande(name, message)
await ctx.send(f"@{ctx.author.name}, commande {name} ajoutée !") await ctx.send(f"@{ctx.author.name}, commande {name} ajoutée !")
else: else:
await ctx.send(f"@{ctx.author.name}, {self.existing_command}.") await ctx.send(f"@{ctx.author.name}, cette commande existe déjà.")
else: else:
await ctx.send(f"@{ctx.author.name}, {self.not_a_mod}.") await ctx.send(f"@{ctx.author.name}, {self.not_a_mod}.")

View file

@ -5,7 +5,7 @@ from utils.db import Database
class CommandesDB(Database): class CommandesDB(Database):
def __init__(self): def __init__(self):
super().__init__(r"db/bot.sqlite3") super().__init__(r"db/bot.sqlite")
def creationTable(self) -> None: def creationTable(self) -> None:
"""Créer la table qui stocker les commandes.""" """Créer la table qui stocker les commandes."""

View file

@ -1,4 +1,5 @@
from sqlite3 import Connection, Cursor, Error, connect from sqlite3 import Connection, Cursor, Error, connect
from sys import stderr
class Database: class Database:
@ -18,7 +19,7 @@ class Database:
try: try:
connnexion = connect(path) connnexion = connect(path)
except Error as e: except Error as e:
print(e) print(e, file=stderr)
return connnexion return connnexion
def _fileExists(self, path: str) -> bool: def _fileExists(self, path: str) -> bool:
@ -45,7 +46,7 @@ class Database:
self.connexion.commit() self.connexion.commit()
return (curseur, curseur.lastrowid) return (curseur, curseur.lastrowid)
except Error as e: except Error as e:
print(e) print(e, file=stderr)
def getResults(self, curseur: _cursor) -> list[tuple]: def getResults(self, curseur: _cursor) -> list[tuple]:
"""Affiche le résultat d'une requête""" """Affiche le résultat d'une requête"""