diff --git a/cord/api.py b/cord/api.py new file mode 100644 index 0000000..a6ed800 --- /dev/null +++ b/cord/api.py @@ -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() diff --git a/cord/bot.py b/cord/bot.py index 59d95b0..43017fc 100644 --- a/cord/bot.py +++ b/cord/bot.py @@ -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): diff --git a/cord/chatbot.py b/cord/chatbot.py index 2e9a749..fbad591 100644 --- a/cord/chatbot.py +++ b/cord/chatbot.py @@ -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')