commit d8521a621be91cd57db302f82d56161c87fe5957 Author: Jadowyne Ulve Date: Sat May 24 09:25:03 2025 -0500 first commit diff --git a/NarratorAi.py b/NarratorAi.py new file mode 100644 index 0000000..fb5582d --- /dev/null +++ b/NarratorAi.py @@ -0,0 +1,45 @@ +api_key = "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" +model = "gpt-4o-mini" +import openai + +client = openai.OpenAI(api_key=api_key) + + +async def setRollDice(person, dice, result): + messages = [ + {"role": "system", "content": "You are a helpful narration bot that can roll dice for people. You MUST use under 30 words and it should be short and descript. THERE WILL BE NO DIALOGUE OR EMOTING OF THE PRESENT PERSON. only dialogue of you presenting it if need be"}, + { + "role": "user", + "content": f"narrate a dice roll of a {dice} sided die that lands on the result of {result} like a ttrpg for {person} in under 30 words." + } + ] + response = client.chat.completions.create(model=model, messages=messages) + generated_text = response.choices[0].message.content + return generated_text + + +async def setItem(item, person): + messages = [ + {"role": "system", "content": "You are a helpful narration bot that can conjure items for people. You MUST use under 30 words and it should be short and descript. THERE WILL BE NO DIALOGUE OR EMOTING OF THE PRESENT PERSON. only dialogue of you presenting it if need be"}, + { + "role": "user", + "content": f"narrate conjuring and giving {item} to {person} in under 30 words." + } + ] + response = client.chat.completions.create(model=model, messages=messages) + generated_text = response.choices[0].message.content + return generated_text + + +async def setScene(prompt): + messages = [ + {"role": "system", "content": "You are a writer of scenes like nathaniel hawthorne or edgar allen poe. You MUST keep it under 500 characters. dont refer to the actors them selves, write it like a play scene wright but with out any reference to characters or actors only the scene itself."}, + { + "role": "user", + "content": prompt + } + ] + response = client.chat.completions.create(model=model, messages=messages) + generated_text = response.choices[0].message.content + return generated_text + diff --git a/__pycache__/NarratorAi.cpython-312.pyc b/__pycache__/NarratorAi.cpython-312.pyc new file mode 100644 index 0000000..053886a Binary files /dev/null and b/__pycache__/NarratorAi.cpython-312.pyc differ diff --git a/__pycache__/NarratorAi.cpython-313.pyc b/__pycache__/NarratorAi.cpython-313.pyc new file mode 100644 index 0000000..311cbcd Binary files /dev/null and b/__pycache__/NarratorAi.cpython-313.pyc differ diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..9164140 --- /dev/null +++ b/bot.py @@ -0,0 +1,75 @@ +import discord +from discord import app_commands +from NarratorAi import setScene, setItem, setRollDice +import random + + +guild_id = 954201387770736751 + +intents = discord.Intents.default() +intents.message_content = True + +client = discord.Client(intents=intents) +tree = app_commands.CommandTree(client) + +@tree.command(name="roll_die", + description="Ask NARC to roll dice for you with flair.", + guild=discord.Object(id=guild_id) + ) +async def roll_die(interaction, num_sides: str): + channel = client.get_channel(interaction.channel_id) + person = interaction.user.display_name + result = random.randint(1, int(num_sides)) + await interaction.response.defer(ephemeral=False, thinking=False) + scene = await setRollDice(person, num_sides, result) + await channel.send(f"*{scene}*") + await interaction.delete_original_response() + + +@tree.command(name="give_item", + description="Ask NARC for an item.", + guild=discord.Object(id=guild_id) + ) +async def give_item(interaction, item: str): + channel = client.get_channel(interaction.channel_id) + person = interaction.user.display_name + await interaction.response.defer(ephemeral=False, thinking=False) + scene = await setItem(item, person) + await channel.send(f"*{scene}*") + await interaction.delete_original_response() + +@tree.command(name="set_scene", + description="Provide a prompt for the narrator to set a scene", + guild=discord.Object(id=guild_id) + ) +async def set_scene(interaction, prompt: str): + channel = client.get_channel(interaction.channel_id) + await interaction.response.defer(ephemeral=False, thinking=False) + scene = await setScene(prompt=prompt) + await channel.send(f"*{scene}*") + await interaction.delete_original_response() + + + +@tree.command(name="narrate", description="This is a command to narrate", guild=discord.Object(id=guild_id)) +async def narrate(interaction, text: str): + channel = client.get_channel(interaction.channel_id) + await interaction.response.defer(ephemeral=False, thinking=False) + await channel.send(f"*{text}*") + await interaction.delete_original_response() + +@client.event +async def on_ready(): + await tree.sync(guild=discord.Object(id=guild_id)) + 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.startswith('$hello'): + await message.channel.send('Hello!') + +token = "MTMyNzcxNDM3MTEyMzgxMDMwNA.GwLjEd.quGP0FA5gHRe1xLyuYq-ANuJ5cRuRQ6dhJiojI" +client.run(token) \ No newline at end of file