Files
Botator/code/config.py

56 lines
3.1 KiB
Python
Raw Normal View History

2022-12-08 22:21:53 +01:00
import logging
import sqlite3
2023-02-02 21:44:40 +01:00
from dotenv import load_dotenv
import os
import openai
2023-02-02 21:44:40 +01:00
load_dotenv()
perspective_api_key = os.getenv("PERSPECTIVE_API_KEY")
discord_token = os.getenv("DISCORD_TOKEN")
2023-03-09 16:22:15 +01:00
webhook_url = os.getenv("WEBHOOK_URL")
2022-12-10 01:32:50 +01:00
max_uses: int = 400
2022-12-08 22:21:53 +01:00
logging.basicConfig(level=logging.INFO)
2023-03-15 22:30:54 +01:00
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./../database/google-vision/botator.json"
2022-12-08 22:21:53 +01:00
def debug(message):
logging.info(message)
conn = sqlite3.connect('../database/data.db')
c = conn.cursor()
2022-12-10 01:03:34 +01:00
connp = sqlite3.connect('../database/premium.db')
2022-12-10 01:27:14 +01:00
cp = connp.cursor()
2022-12-08 22:21:53 +01:00
async def moderate(api_key, text):
openai.api_key = api_key
response = await openai.Moderation.acreate(
input=text,
)
return response["results"][0]["flagged"]
2022-12-10 01:03:34 +01:00
c.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)''')
2023-02-03 20:05:49 +01:00
#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
2023-02-02 22:05:03 +01:00
#we delete the moderation table and create a new one
2023-02-03 20:05:49 +01:00
c.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)''')
c.execute("PRAGMA table_info(moderation)")
result = c.fetchall()
actual_columns = len(result)
if actual_columns != expected_columns:
#we add the new columns
c.execute("ALTER TABLE moderation ADD COLUMN toxicity real")
c.execute("ALTER TABLE moderation ADD COLUMN severe_toxicity real")
c.execute("ALTER TABLE moderation ADD COLUMN identity_attack real")
c.execute("ALTER TABLE moderation ADD COLUMN insult real")
c.execute("ALTER TABLE moderation ADD COLUMN profanity real")
c.execute("ALTER TABLE moderation ADD COLUMN threat real")
c.execute("ALTER TABLE moderation ADD COLUMN sexually_explicit real")
c.execute("ALTER TABLE moderation ADD COLUMN flirtation real")
c.execute("ALTER TABLE moderation ADD COLUMN obscene real")
c.execute("ALTER TABLE moderation ADD COLUMN spam real")
else:
print("Table already has the correct number of columns")
pass
2023-03-01 21:30:16 +01:00
c.execute('''CREATE TABLE IF NOT EXISTS model (guild_id text, model_name text)''')
2023-03-15 22:30:54 +01:00
c.execute('''CREATE TABLE IF NOT EXISTS images (guild_id text, usage_count integer, is_enabled boolean)''')
2022-12-15 18:59:21 +01:00
cp.execute('''CREATE TABLE IF NOT EXISTS data (user_id text, guild_id text, premium boolean)''')
2022-12-15 19:56:15 +01:00
cp.execute('''CREATE TABLE IF NOT EXISTS channels (guild_id text, channel0 text, channel1 text, channel2 text, channel3 text, channel4 text)''')