diff --git a/bot.py b/bot.py index ef615e7bb74ad7f0630b3044a8c219bbf891c014..f43afb6d9e2709ec83362c2608b43bf98a9f8490 100644 --- a/bot.py +++ b/bot.py @@ -46,7 +46,7 @@ async def help(ctx): command_info = [] for command in commands_list: short_description = command.brief or "Keine kurze Beschreibung verfügbar." - command_info.append(f"`{command.name}` - {short_description}") + command_info.append(f"`{command.name}` - {short_description}\n") await ctx.send(command_info) diff --git a/modules/RPGLoader.py b/modules/RPGLoader.py index f67bedf020cbd40abf78d410256bd46799411dbd..aae7cdb642f626844107f71182c6e99209dc5bc4 100644 --- a/modules/RPGLoader.py +++ b/modules/RPGLoader.py @@ -82,24 +82,32 @@ class MedievalGame: class RPGLoader(commands.Cog): - def __init__(self, bot): - self.bot = bot + def __init__(self, client): + self.client = client self.game = None - self.channel = None - self.users = [] + self.channel_id = 1200993669478621226 + self.channel = self.client.get_channel(self.channel_id) + self.users = {} + + self.load_usernames() + @commands.command() @commands.is_owner() - async def aitargetchannel(self, ctx, channelid): - self.channel = channelid - await ctx.send("ChannelID set") + async def aitargetchannel(self, ctx, channelid=None): + if channelid is None: + self.channel = self.client.get_channel(self.channel_id) + else: + self.channel = self.client.get_channel(channelid) + await self.channel.send("ChannelID set") + @commands.command() async def listgames(self, ctx): directory_path = "./modules/gameStates/" try: # Überprüfe, ob das Verzeichnis existiert - if not os.path.exists(): + if not os.path.exists(directory_path): await self.channel.send(f"Fehler: der Pfad {directory_path} existiert nicht") # Liste alle Dateien im Verzeichnis auf files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))] @@ -120,8 +128,10 @@ class RPGLoader(commands.Cog): @commands.command(aliases=["startgame"]) async def loadgame(self, ctx, gameStateName=None): try: - self.game = MedievalGame('medievalrpgai') + self.game = MedievalGame('middleagerpg') self.game.loadGame(gameStateName) + if gameStateName is None: + gameStateName = "new Game" await ctx.send(f"Loaded {gameStateName}") except Exception as e: await self.channel.send("Error ", e) @@ -134,27 +144,70 @@ class RPGLoader(commands.Cog): await self.channel.send(game.chat()) - @commands.command() - async def setUsername(self, ctx, username): + async def load_usernames(self): try: - with open(self.users, 'r') as file0: - file = list(json.load(file0)) - self.users = file + with open("players.json", 'r') as file0: + self.users = json.load(file0) + except FileNotFoundError: + # Falls die Datei nicht gefunden wird, leeres Dictionary initialisieren + self.users = {} + + +####################################################### + + @commands.command(brief="Hier kannst du deinen Adventurer Namen anpassen!") + async def setusername(self, ctx, username): + try: + with open("players.json", 'r') as file0: + self.users = json.load(file0) + except FileNotFoundError: + # Falls die Datei nicht gefunden wird, leeres Dictionary initialisieren + self.users = {} + + user_name = ctx.author.name + + if user_name in self.users: + # Der Benutzer existiert bereits, aktualisiere den Ingame-Namen + self.users[user_name] = username + else: + # Der Benutzer existiert nicht, füge ihn hinzu + self.users[user_name] = username + + try: + with open("players.json", 'w') as file0: + json.dump(self.users, file0, indent=1) + await self.channel.send(f"Username {username} gesetzt.") except Exception as e: - with open(self.users, 'w') as file0: - json.dump(self.users, file0) - with open(self.users, 'r') as file0: - file = list(json.load(file0)) - self.gameStateContent = file - - self.users.append({f'{ctx.author.name}' : f'{username}'}) + await self.channel.send(f"Fehler beim Speichern: {e}") + + + @commands.command(brief="Habe ich einen Adventurer Namen?") + async def getusername(self, ctx): + try: + with open("players.json", 'r') as file0: + self.users = json.load(file0) + except FileNotFoundError: + # Falls die Datei nicht gefunden wird, leeres Dictionary initialisieren + self.users = {} + + user_name = ctx.author.name + + if user_name in self.users: + ingame_user = self.users[user_name] + await self.channel.send(f"Dein Abenteurer heißt {ingame_user}") + else: + await self.channel.send("Du hast noch keinen Namen!") ############################################################################ - @commands.Cog.listener() - async def on_message(self, message): - if not any(item in message.content for item in ["setUsername","savegame", "loadgame", "aitargetchannel", "listgames", "downloadgame"]): - await self.channel.send(self.game.chat()) + @commands.command(aliases=["c"]) + async def chat(self, ctx, *, message): + if ctx.author.name in self.users: + ingameuser = self.users[ctx.author.name] + await self.channel.send(self.game.chat(ingameuser, message)) + else: + await self.channel.send("No Ingame Name!") + async def setup(client): diff --git a/modules/__pycache__/RPGLoader.cpython-312.pyc b/modules/__pycache__/RPGLoader.cpython-312.pyc index 84a510b594a11043809826a333cd37419ae17867..09a1c20e594745e43af7ca73477bbf50deec712e 100644 Binary files a/modules/__pycache__/RPGLoader.cpython-312.pyc and b/modules/__pycache__/RPGLoader.cpython-312.pyc differ diff --git a/modules/gameStates/gameState-02-32_28-01-2024-num884 b/modules/gameStates/gameState-02-32_28-01-2024-num884 deleted file mode 100644 index 25720664402dfddcadc431de119f04673ca75023..0000000000000000000000000000000000000000 --- a/modules/gameStates/gameState-02-32_28-01-2024-num884 +++ /dev/null @@ -1,30 +0,0 @@ -[ - { - "role": "system", - "content": "Messages are given to you like this: \"Seraphina : message-conent\". You respond to the Adventurers Inputs after his or her Name. In this example, the Adventurer (Which is the Player) named Seraphina says to you \"Hi\" When you answer the player you dont say \"Here is Seraphinas Inventory\" instead you say \"Here is your inventory\". Because the name in front of the Message content is the players name. The player decided to name the character \"Seraphina\" in this example." - }, - { - "role": "user", - "content": "Seraphina: Hi" - }, - { - "role": "assistant", - "content": "You nod in greeting as you look over Seraphina's inventory. \"Greetings, Seraphina. What can I help you with today?\"" - }, - { - "role": "user", - "content": "Seraphina: Inventory" - }, - { - "role": "assistant", - "content": "You nod and say, \"Of course! Here is Seraphina's inventory:\n\n* 10 Potions of Healing\n* 5 Scrolls of Protection from Evil and Good\n* 3 Vials of Dragon's Breath (Breath Weapon)\n* A small pouch containing 25 gold pieces\n* A map of the surrounding area with several marked locations of interest\n* A note from a mysterious stranger, inviting Seraphina to a secret location for a unknown purpose\n\nIs there anything specific you would like to know or do?\"" - }, - { - "role": "user", - "content": "Seraphina: Inventory" - }, - { - "role": "assistant", - "content": "You nod and say, \"Of course! Here is Seraphina's inventory:\n\n* 10 Potions of Healing\n* 5 Scrolls of Protection from Evil and Good\n* 3 Vials of Dragon's Breath (Breath Weapon)\n* A small pouch containing 25 gold pieces\n* A map of the surrounding area with several marked locations of interest\n* A note from a mysterious stranger, inviting Seraphina to a secret location for a unknown purpose\n\nIs there anything specific you would like to know or do?\"" - } -] \ No newline at end of file diff --git a/players.json b/players.json new file mode 100644 index 0000000000000000000000000000000000000000..877ead2e9596600fbff351887e436355bf9e2720 --- /dev/null +++ b/players.json @@ -0,0 +1,4 @@ +{ + "r4ge_6168": "Ragnar", + "n1ghtw1tch": "Ingvar" +} \ No newline at end of file diff --git a/players.txt b/players.txt new file mode 100644 index 0000000000000000000000000000000000000000..0637a088a01e8ddab3bf3fa98dbe804cbde1a0dc --- /dev/null +++ b/players.txt @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/rpgtargetchannel b/rpgtargetchannel new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391