Removed sql stuff completly

dev
supopur 2 years ago
parent 9c38cf4923
commit 9ed2c050b7

@ -54,72 +54,6 @@ bot = commands.Bot(command_prefix='!', intents=discord.Intents.all())
logger.debug("Loaded the client.")
class DatabaseAPI:
def __init__(self, db_file):
self.db_file = db_file
self.connection = None
self.cursor = None
def __enter__(self):
try:
self.connection = sqlite3.connect(self.db_file)
self.cursor = self.connection.cursor()
except sqlite3.Error as e:
raise e
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if self.cursor is not None:
self.cursor.close()
if self.connection is not None:
self.connection.close()
def create_table(self, table_name, columns):
columns_str = ", ".join(columns)
query = f"CREATE TABLE IF NOT EXISTS {table_name} ({columns_str})"
self.cursor.execute(query)
self.connection.commit()
def insert_values(self, table_name, values):
placeholders = ",".join(["?" for _ in range(len(values))])
query = f"INSERT INTO {table_name} VALUES ({placeholders})"
self.cursor.execute(query, values)
self.connection.commit()
def get_table(self, table_name):
query = f"SELECT * FROM {table_name}"
self.cursor.execute(query)
return self.cursor.fetchall()
def modify_value(self, table_name, column_name, new_value):
query = f"UPDATE {table_name} SET {column_name} = ?"
self.cursor.execute(query, (new_value,))
self.connection.commit()
def del_column(self, table_name, column_name):
query = f"ALTER TABLE {table_name} DROP COLUMN {column_name}"
self.cursor.execute(query)
self.connection.commit()
def plugin_register(self, plugin_name, guild_id=None):
general_table_query = f"CREATE TABLE IF NOT EXISTS {plugin_name}_general (key TEXT PRIMARY KEY, value TEXT)"
self.cursor.execute(general_table_query)
self.connection.commit()
if guild_id is not None:
guild_table_query = f"CREATE TABLE IF NOT EXISTS {plugin_name}_server_{guild_id} (key TEXT PRIMARY KEY, value TEXT)"
self.cursor.execute(guild_table_query)
self.connection.commit()
def get_all_tables(self):
query = "SELECT name FROM sqlite_master WHERE type='table'"
self.cursor.execute(query)
tables = self.cursor.fetchall()
table_names = [table[0] for table in tables]
return table_names
#Api used mainly for plugins so getting uptime, loading, unloading, reloading plugins, getting status of plugins, get plugin info, stopping the bot, getting bot name and tag, getting cpm/commands per minute, get if there is web plugin, if there is web plugin register api, get if plugin supports web and so on..
class API:
@ -158,7 +92,7 @@ class API:
self.logger = log
self.token = token
self.guild_ids = config["bot"]["guild_ids"]
self.db_api = dbapi
#This is the most basic interface CLI wich is basically a comand line that appears when you launch the app it will have commands like stop, help, commands, cogs, load, unload and so on..
@ -280,9 +214,7 @@ async def stop(ctx):
if __name__ == "__main__":
dbapi = DatabaseAPI("storage.db")
dbapi.__enter__()
api = API(config, bot, log, token, dbapi)
api = API(config, bot, log, token)
cli = CLI(api)
bot.api = api
@ -383,19 +315,6 @@ if __name__ == "__main__":
cli.register_command("unload", cli_unload, "Unloads a cog takes a cog name as a arg example: unload cogs.example")
#Get a table
def cli_table_get(self, table: str):
print(f"Getting {table} data...")
try:
table_data = self.api.db_api.get_table(table)
except Exception as e:
print(f"Table {table} doesn't exist or it couldn't be reached. {e}")
return 1
print(table_data)
cli.register_command("table_get", cli_table_get, "Gets a table by name from the storage.db file.")
for x in config["bot"]["cogs"]:
log("inf", f"Loading {x}...")

Loading…
Cancel
Save