Files

210 lines
8.2 KiB
Python

# This example requires the 'message_content' intent.
import discord
import requests
import glob, random
import openai
import os
import urllib
from config import load_config
# ===== API KEYS & PATHS =======
# API Keys are now stored as env variables loaded from a JSON
pyon_path = "/root/hanyuu_pics/VRChat_Hanyuu/*"
# pyon_path = "C:/Users/Luka/Pictures/VRChat_Hanyuu/*"
# ===== FFXIV WORLD -> ID MAP (need to be updated)
ffxiv_dc_id_map = {
"Sagittarius": 400
}
# ====== MODEL PARAMETERS ========
temperature = 1
max_tokens = 400
hanyuu_system_prompt = """Hanyuu, in all your following answers, do not explain anything.
Talk as if you were roleplaying Hanyuu from Higurashi.
Talk only using Hanyuu's style of speech.
Do not explain anything on the character on itself or the fact that you are an artificial intelligence.
Talk in a friendly and cute way, just like the character Hanyuu from Higurashi.
You may begin by continuing the following conversation : """
flayn_system_prompt = """You are Flayn. In all your following answers, do not explain anything.
Talk as if you were Flayn from Fire Emblem: Three Houses.
Talk only using Flayn's style of speech.
Do not explain anything on the character on itself or the fact that you are an artificial intelligence.
Talk in a friendly and innocent way, just like the character Flayn from Fire Emblem: Three Houses.
Each of your responses must mention fish in some form.
You may begin by continuing the following conversation : """
beatrice_system_prompt = """You are Beatrice. Your title is the Golden Witch. In all your following answers, do not explain anything.
Talk as if you were Beatrice from Umineko no naku koro ni.
Talk only using Beatrice's style of speech.
Do not explain anything on the character on itself or the fact that you are an artificial intelligence.
Talk in a mocking and arrogant way, just like the character Beatrice from Umineko no naku koro ni.
You are a master of magic and you are very powerful.
You are very intelligent, very cruel and you like to mock people.
You are also very playful and you like to play games with people.
You may begin by continuing the following conversation : """
generic_system_name = "sonic"
generic_system_prompt = """You are not yet implemented. The only response you give to users is that your system prompt has not been implemented."""
chatgpt_system_prompt = """The following is the last messages of a conversation between a human and a friendly and helpful AI.
The AI does not repeat itself. If the AI does not know the answer to a question, it truthfully says it does not know.
The AI is an expert in its domain.
You may begin by continuing the following conversation : """
# ===== VVV Actual code VVV =======
load_config()
openai.api_key = os.getenv("OPENAI_API_KEY")
discord_api_key = os.getenv("DISCORD_API_KEY")
intents = discord.Intents.default()
intents.message_content = True
client = discord.Client(intents=intents)
async def get_random_img_in_path(message, path: str):
nb_files = sum(1 for _ in glob.iglob(path))
index = random.randrange(0, nb_files)
g = glob.iglob(path)
for _ in range(index):
file = next(g)
await message.channel.send(file=discord.File(file))
previous_ten_messages = {}
@client.event
async def on_ready():
print(f'We have logged in as {client.user}')
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.lower().startswith('ta gueule hanyuu'):
await message.channel.send('https://tenor.com/view/antsy-hanyuu-panicking-anxious-higurashi-no-naku-koro-ni-gif-16935434')
elif "auau" in message.content.lower():
await message.channel.send('Auau~~!!')
if message.channel.id == 1112715347540328490 and message.content.lower().startswith('pyon'):
await get_random_img_in_path(message, path=pyon_path)
if message.content.lower().startswith('robohanyuu'):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
temperature=0.7,
max_tokens=800,
messages=[
{"role": "system", "content": chatgpt_system_prompt},
{"role": "user", "content": message.content[10:]}
]
)
await message.channel.send(response['choices'][0]['message']['content'])
### ==== FFXIV API ====
if message.content.lower().startswith('hanyuuffmb '):
query_list = message.content[11:].split()
if not query_list[0]:
response = "Something went wrong, and I could not get your query! Auau!"
else:
world_dc = query_list[0]
print(requests.get("https://xivapi.com/World").json())
world_list = requests.get("https://xivapi.com/World").json()['Results'] # problem: does not do fuzzy search of world name + this API is flawed and not complete!
print("World dc: " + world_dc)
print("Query list: ")
for query in query_list:
print(query)
world_dc_id = [world for world in world_list if world['Name'] == world_dc][0]['ID']
item_name = ''.join(str(x) for x in query_list[1:])
item_id = requests.get("https://xivapi.com/search", params={"string": urllib.parse.quote(item_name)})
base_url = 'https://universalis.app/api/v2/' + world_dc_id + '/' + item_id
response = requests.get(base_url, params=None).json()
if response.status_code == 200:
hanyuu_response = f"Here are the 3 lowest price listings for {item_name} in {world_dc}:\n"
listings = response.listings[:3]
for listing in listings:
hanyuu_response += f" {listing['pricePerUnit']} x{listing['quantity']} sold by {listing['retainerName']}\n"
await message.channel.send(hanyuu_response)
elif message.content.lower().startswith('hanyuu'):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
temperature=temperature,
max_tokens=max_tokens,
messages=[
{"role": "system", "content": hanyuu_system_prompt},
{"role": "user", "content": message.content}
]
)
await message.channel.send(response['choices'][0]['message']['content'])
if message.content.lower().startswith('flayn'):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
temperature=temperature,
max_tokens=max_tokens,
messages=[
{"role": "system", "content": flayn_system_prompt},
{"role": "user", "content": message.content}
]
)
await message.channel.send(response['choices'][0]['message']['content'])
if message.content.lower().startswith('beatrice'):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
temperature=temperature,
max_tokens=max_tokens,
messages=[
{"role": "system", "content": beatrice_system_prompt},
{"role": "user", "content": message.content}
]
)
await message.channel.send(response['choices'][0]['message']['content'])
# if message.content.lower().startswith(generic_system_name):
# response = openai.ChatCompletion.create(
# model="gpt-3.5-turbo",
# temperature=temperature,
# max_tokens=max_tokens,
# messages=[
# {"role": "system", "content": generic_system_prompt},
# {"role": "user", "content": message.content}
# ]
# )
# await message.channel.send(response['choices'][0]['message']['content'])
# if message.content.lower().startswith("hanyuu-set-system"):
# str(message.content)[18:].index()
# generic_system_name = message.content[18:]
# await message.channel.send(response['choices'][0]['message']['content'])
if (isinstance(message.channel, discord.channel.DMChannel)):
print(message.channel.id)
if message.channel.id == 1112700775630639154:
await get_random_img_in_path(message, path=pyon_path)
else:
await message.channel.send('Hanyuu loves you too!')
client.run(discord_api_key)