Add NPC interaction system with memory and quest generation

- Introduced a new NPC system with dynamic NPCs and conversation handling.
- Implemented NPC memory using SQLite to log conversations and manage relationships.
- Added commands for talking to NPCs, listing available NPCs, and generating quests.
- Updated database schema to support NPC conversations and relationships.
- Refactored code structure to separate concerns into cogs and handlers.
This commit is contained in:
2025-09-30 14:12:22 +02:00
parent c8980f785f
commit 7e76353c6a
24 changed files with 7468 additions and 14 deletions
Executable
+62
View File
@@ -0,0 +1,62 @@
# main.py
import discord
from discord.ext import commands
import os
from dotenv import load_dotenv
import threading
import itertools
from npc_memory import NPCMemory
from npc_handler import NPCHandler
from cogs.npc import NPCCog
class MyNewHelp(commands.MinimalHelpCommand):
async def send_pages(self):
destination = self.get_destination()
for page in self.paginator.pages:
emby = discord.Embed(description=page)
await destination.send(embed=emby)
class Client(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=self.iterate_prefix("py"),
strip_after_prefix=True,
case_insensitive=True,
intents=discord.Intents.all(),
help_command=MyNewHelp(),
)
def iterate_prefix(self, prefix):
prefixes = list(map(''.join, itertools.product(*zip(prefix.upper(), prefix.lower()))))
print(prefixes)
return prefixes
async def setup_hook(self): # overwriting a handler
cogs_folder = f"{os.path.abspath(os.path.dirname(__file__))}/cogs"
for filename in os.listdir(cogs_folder):
if filename.endswith(".py"):
try:
await self.load_extension(f"cogs.{filename[:-3]}")
except Exception as e:
print(f"Failed to load {filename}: {e}")
memory = NPCMemory()
npc_handler = NPCHandler(memory)
await self.add_cog(NPCCog(self, npc_handler))
await self.tree.sync()
print("Loaded cogs")
def main():
load_dotenv()
client = Client()
token = os.getenv("TOKEN")
if token is not None:
client.run(token)
else:
print("Token is missing.")
if __name__ == "__main__":
main()