2022-12-08 22:21:53 +01:00
|
|
|
import logging
|
|
|
|
|
import sqlite3
|
2023-07-15 12:20:38 +02:00
|
|
|
import json
|
2023-02-02 21:44:40 +01:00
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
import os
|
2023-03-31 14:09:06 +02:00
|
|
|
|
2023-07-18 21:53:07 +02:00
|
|
|
# Loading environement variables
|
2023-02-02 21:44:40 +01:00
|
|
|
load_dotenv()
|
2023-07-18 21:53:07 +02:00
|
|
|
|
2023-02-02 21:44:40 +01:00
|
|
|
perspective_api_key = os.getenv("PERSPECTIVE_API_KEY")
|
2023-02-28 15:28:14 +01:00
|
|
|
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
|
2023-07-18 21:53:07 +02:00
|
|
|
tenor_api_key = os.getenv("TENOR_API_KEY")
|
|
|
|
|
|
|
|
|
|
# Logging
|
2022-12-08 22:21:53 +01:00
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
|
|
2023-07-18 21:53:07 +02:00
|
|
|
# Setting up the google vision api
|
2023-03-31 14:09:06 +02:00
|
|
|
os.environ[
|
|
|
|
|
"GOOGLE_APPLICATION_CREDENTIALS"
|
|
|
|
|
] = "./../database/google-vision/botator.json"
|
|
|
|
|
|
2023-07-18 21:53:07 +02:00
|
|
|
# Defining a debug function
|
2023-07-18 17:51:13 +02:00
|
|
|
|
2023-07-18 23:23:47 +02:00
|
|
|
|
2022-12-08 22:21:53 +01:00
|
|
|
def debug(message):
|
2023-03-17 11:27:25 +01:00
|
|
|
if os.name == "nt":
|
|
|
|
|
logging.info(message)
|
2023-04-02 14:23:12 +02:00
|
|
|
else:
|
2023-04-02 16:34:48 +02:00
|
|
|
print(message)
|
2023-03-17 11:27:25 +01:00
|
|
|
|
2023-07-18 17:51:13 +02:00
|
|
|
|
2023-05-05 12:38:02 +02:00
|
|
|
def ctx_to_guid(ctx):
|
|
|
|
|
if ctx.guild is None:
|
|
|
|
|
return ctx.author.id
|
|
|
|
|
else:
|
|
|
|
|
return ctx.guild.id
|
|
|
|
|
|
2023-07-18 17:51:13 +02:00
|
|
|
|
2023-05-05 12:38:02 +02:00
|
|
|
def mg_to_guid(mg):
|
|
|
|
|
if mg.guild is None:
|
|
|
|
|
return mg.author.id
|
|
|
|
|
else:
|
|
|
|
|
return mg.guild.id
|
2023-03-31 14:09:06 +02:00
|
|
|
|
2023-07-18 17:51:13 +02:00
|
|
|
|
2023-07-15 12:20:38 +02:00
|
|
|
con_data = sqlite3.connect("./database/data.db")
|
2023-03-31 14:20:43 +02:00
|
|
|
curs_data = con_data.cursor()
|
2023-07-15 12:20:38 +02:00
|
|
|
con_premium = sqlite3.connect("./database/premium.db")
|
2023-03-31 14:20:43 +02:00
|
|
|
curs_premium = con_premium.cursor()
|
2022-12-08 22:21:53 +01:00
|
|
|
|
2023-03-31 14:20:43 +02:00
|
|
|
curs_data.execute(
|
2023-03-31 14:09:06 +02:00
|
|
|
"""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
|
|
|
|
2023-08-19 14:17:16 +02:00
|
|
|
con_data.execute(
|
|
|
|
|
"CREATE TABLE IF NOT EXISTS setup_data (guild_id text, guild_settings text)"
|
|
|
|
|
)
|
2023-03-31 14:20:43 +02:00
|
|
|
|
|
|
|
|
# This code creates the model table if it does not exist
|
|
|
|
|
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(
|
2023-03-31 14:09:06 +02:00
|
|
|
"""CREATE TABLE IF NOT EXISTS images (guild_id text, usage_count integer, is_enabled boolean)"""
|
|
|
|
|
)
|
2023-03-31 14:20:43 +02:00
|
|
|
|
|
|
|
|
# This code creates the data table if it does not exist
|
|
|
|
|
curs_premium.execute(
|
2023-03-31 14:09:06 +02:00
|
|
|
"""CREATE TABLE IF NOT EXISTS data (user_id text, guild_id text, premium boolean)"""
|
|
|
|
|
)
|
2023-03-31 14:20:43 +02:00
|
|
|
|
|
|
|
|
# This code creates the channels table if it does not exist
|
|
|
|
|
curs_premium.execute(
|
2023-03-31 14:09:06 +02:00
|
|
|
"""CREATE TABLE IF NOT EXISTS channels (guild_id text, channel0 text, channel1 text, channel2 text, channel3 text, channel4 text)"""
|
|
|
|
|
)
|
2023-08-15 10:44:13 +02:00
|
|
|
|
2023-08-15 11:04:33 +02:00
|
|
|
with open(
|
2023-08-15 12:38:47 +02:00
|
|
|
os.path.abspath(
|
|
|
|
|
os.path.join(os.path.dirname(__file__), "./prompts/gpt-3.5-turbo.txt")
|
|
|
|
|
),
|
2023-08-15 11:04:33 +02:00
|
|
|
"r",
|
|
|
|
|
encoding="utf-8",
|
|
|
|
|
) as file:
|
|
|
|
|
gpt_3_5_turbo_prompt = file.read()
|