[CONFIG] Cleaned up code

This commit is contained in:
Alexis LEBEL
2023-03-31 14:20:43 +02:00
parent dd21536864
commit 330e732802

View File

@@ -22,10 +22,11 @@ def debug(message):
logging.info(message) logging.info(message)
conn = sqlite3.connect("../database/data.db") # connect to the database
c = conn.cursor() con_data = sqlite3.connect("../database/data.db")
connp = sqlite3.connect("../database/premium.db") curs_data = con_data.cursor()
cp = connp.cursor() con_premium = sqlite3.connect("../database/premium.db")
curs_premium = con_premium.cursor()
async def moderate(api_key, text): async def moderate(api_key, text):
@@ -36,41 +37,53 @@ async def moderate(api_key, text):
return response["results"][0]["flagged"] return response["results"][0]["flagged"]
c.execute( curs_data.execute(
"""CREATE TABLE IF NOT EXISTS data (guild_id text, channel_id text, api_key text, is_active boolean, max_tokens integer, temperature real, frequency_penalty real, presence_penalty real, uses_count_today integer, prompt_size integer, prompt_prefix text, tts boolean, pretend_to_be text, pretend_enabled boolean)""" """CREATE TABLE IF NOT EXISTS data (guild_id text, channel_id text, api_key text, is_active boolean, max_tokens integer, temperature real, frequency_penalty real, presence_penalty real, uses_count_today integer, prompt_size integer, prompt_prefix text, tts boolean, pretend_to_be text, pretend_enabled boolean)"""
) )
# we delete the moderation table and create a new one, with all theese parameters as floats: TOXICITY: {result[0]}; SEVERE_TOXICITY: {result[1]}; IDENTITY ATTACK: {result[2]}; INSULT: {result[3]}; PROFANITY: {result[4]}; THREAT: {result[5]}; SEXUALLY EXPLICIT: {result[6]}; FLIRTATION: {result[7]}; OBSCENE: {result[8]}; SPAM: {result[9]} # we delete the moderation table and create a new one, with all theese parameters as floats: TOXICITY: {result[0]}; SEVERE_TOXICITY: {result[1]}; IDENTITY ATTACK: {result[2]}; INSULT: {result[3]}; PROFANITY: {result[4]}; THREAT: {result[5]}; SEXUALLY EXPLICIT: {result[6]}; FLIRTATION: {result[7]}; OBSCENE: {result[8]}; SPAM: {result[9]}
expected_columns = 14 expected_columns = 14
# we delete the moderation table and create a new one # we delete the moderation table and create a new one
c.execute( curs_data.execute(
"""CREATE TABLE IF NOT EXISTS moderation (guild_id text, logs_channel_id text, is_enabled boolean, mod_role_id text, toxicity real, severe_toxicity real, identity_attack real, insult real, profanity real, threat real, sexually_explicit real, flirtation real, obscene real, spam real)""" """CREATE TABLE IF NOT EXISTS moderation (guild_id text, logs_channel_id text, is_enabled boolean, mod_role_id text, toxicity real, severe_toxicity real, identity_attack real, insult real, profanity real, threat real, sexually_explicit real, flirtation real, obscene real, spam real)"""
) )
c.execute("PRAGMA table_info(moderation)")
result = c.fetchall() # This code returns the number of columns in the table "moderation" in the database "data.db".
curs_data.execute("PRAGMA table_info(moderation)")
result = curs_data.fetchall()
actual_columns = len(result) actual_columns = len(result)
if actual_columns != expected_columns: if actual_columns != expected_columns:
# we add the new columns # we add the new columns
c.execute("ALTER TABLE moderation ADD COLUMN toxicity real") curs_data.execute("ALTER TABLE moderation ADD COLUMN toxicity real")
c.execute("ALTER TABLE moderation ADD COLUMN severe_toxicity real") curs_data.execute("ALTER TABLE moderation ADD COLUMN severe_toxicity real")
c.execute("ALTER TABLE moderation ADD COLUMN identity_attack real") curs_data.execute("ALTER TABLE moderation ADD COLUMN identity_attack real")
c.execute("ALTER TABLE moderation ADD COLUMN insult real") curs_data.execute("ALTER TABLE moderation ADD COLUMN insult real")
c.execute("ALTER TABLE moderation ADD COLUMN profanity real") curs_data.execute("ALTER TABLE moderation ADD COLUMN profanity real")
c.execute("ALTER TABLE moderation ADD COLUMN threat real") curs_data.execute("ALTER TABLE moderation ADD COLUMN threat real")
c.execute("ALTER TABLE moderation ADD COLUMN sexually_explicit real") curs_data.execute("ALTER TABLE moderation ADD COLUMN sexually_explicit real")
c.execute("ALTER TABLE moderation ADD COLUMN flirtation real") curs_data.execute("ALTER TABLE moderation ADD COLUMN flirtation real")
c.execute("ALTER TABLE moderation ADD COLUMN obscene real") curs_data.execute("ALTER TABLE moderation ADD COLUMN obscene real")
c.execute("ALTER TABLE moderation ADD COLUMN spam real") curs_data.execute("ALTER TABLE moderation ADD COLUMN spam real")
else: else:
print("Table already has the correct number of columns") print("Table already has the correct number of columns")
pass
c.execute("""CREATE TABLE IF NOT EXISTS model (guild_id text, model_name text)""") # This code creates the model table if it does not exist
c.execute( curs_data.execute(
"""CREATE TABLE IF NOT EXISTS model (guild_id text, model_name text)"""
)
# This code creates the images table if it does not exist
curs_data.execute(
"""CREATE TABLE IF NOT EXISTS images (guild_id text, usage_count integer, is_enabled boolean)""" """CREATE TABLE IF NOT EXISTS images (guild_id text, usage_count integer, is_enabled boolean)"""
) )
cp.execute(
# This code creates the data table if it does not exist
curs_premium.execute(
"""CREATE TABLE IF NOT EXISTS data (user_id text, guild_id text, premium boolean)""" """CREATE TABLE IF NOT EXISTS data (user_id text, guild_id text, premium boolean)"""
) )
cp.execute(
# This code creates the channels table if it does not exist
curs_premium.execute(
"""CREATE TABLE IF NOT EXISTS channels (guild_id text, channel0 text, channel1 text, channel2 text, channel3 text, channel4 text)""" """CREATE TABLE IF NOT EXISTS channels (guild_id text, channel0 text, channel1 text, channel2 text, channel3 text, channel4 text)"""
) )