Added API and chat

This commit is contained in:
nsde 2023-08-06 23:20:38 +02:00
parent 738352a063
commit 8cfd5b62ac
3 changed files with 36 additions and 6 deletions

26
cord/api.py Normal file
View file

@ -0,0 +1,26 @@
import os
import aiohttp.web
from dotenv import load_dotenv
load_dotenv()
app = aiohttp.web.Application()
async def start(client):
async def get_userinfo():
guild = client.get_guild(int(os.getenv('DISCORD_GUILD')))
members = guild.members
user_roles = {member.id: [role.name for role in member.roles] for member in members}
return user_roles
async def get_roles(request):
return aiohttp.web.json_response(await get_userinfo())
app.router.add_get('/get_roles', get_roles)
runner = aiohttp.web.AppRunner(app)
await runner.setup()
site = aiohttp.web.TCPSite(runner, '0.0.0.0', 3224)
await site.start()

View file

@ -3,6 +3,7 @@
import os
import nextcord
import api
import chatbot
import embedder
import autochat
@ -27,6 +28,9 @@ bot = commands.Bot(
@bot.event
async def on_ready():
print(f'Online as {bot.user} (ID: {bot.user.id})')
await api.start(bot)
await bot.change_presence(activity=nextcord.Game(name='with fire'))
@bot.event
@ -37,11 +41,11 @@ async def on_message(message):
await autochat.process(message)
await bot.process_commands(message)
# @bot.slash_command(description='Chat with AI')
# async def chat(interaction: nextcord.Interaction,
# prompt: str = SlashOption(description='AI Prompt', required=True)
# ):
# await chatbot.respond(interaction, prompt)
@bot.slash_command(description='Chat with AI')
async def chat(interaction: nextcord.Interaction,
prompt: str = SlashOption(description='AI Prompt', required=True)
):
await chatbot.respond(interaction, prompt)
@bot.slash_command(description='Sets your DMs up, so you can write the bot.')
async def dm_setup(interaction: nextcord.Interaction):

View file

@ -11,7 +11,7 @@ async def respond(interaction, prompt):
partial_message = await interaction.send('') # send an empty message
message = await partial_message.fetch() # gets the message that was send
openai.api_base = 'https://nova-oss.com'
openai.api_base = os.getenv('OPENAI_BASE')
openai.api_key = os.getenv('OPENAI_KEY')
model = os.getenv('OPENAI_MODEL')