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()
ifguild_idisnotNone:
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()
defget_all_tables(self):
query="SELECT name FROM sqlite_master WHERE type='table'"
self.cursor.execute(query)
tables=self.cursor.fetchall()
table_names=[table[0]fortableintables]
returntable_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..
classAPI:
@ -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
defcli_table_get(self,table:str):
print(f"Getting {table} data...")
try:
table_data=self.api.db_api.get_table(table)
exceptExceptionase:
print(f"Table {table} doesn't exist or it couldn't be reached. {e}")
return1
print(table_data)
cli.register_command("table_get",cli_table_get,"Gets a table by name from the storage.db file.")