Explorar o código

Added help_start.json and changed some error handlings.

baumsplitter41 hai 4 meses
pai
achega
d54075b3a4

+ 38 - 5
VPD_BOT/cogs/help_start.py

@@ -1,3 +1,5 @@
+import json
+from pathlib import Path
 import discord
 from discord.ext import commands
 from discord.commands import Option
@@ -10,14 +12,45 @@ class helpstart(commands.Cog):
 
 #Command initialization
     @slash_command(name="help_how_to_start", description= "Get Infos how to start playing on the server")
-    async def help_how_to_start(
-        self,
-        ctx,
+    async def help_how_to_start(self,ctx: discord.ApplicationContext,
     ):
         server = ctx.guild
+
+        json_path = Path(__file__).resolve().parent / "json_files" / "help_start.json"
+        if not json_path.exists():
+            await ctx.respond("The .json file is missing.")
+            return
+
+        try:
+            with json_path.open("r", encoding="utf-8") as f:
+                json_data = json.load(f)
+        except json.JSONDecodeError:
+            await ctx.respond("The .json file is not valid JSON.")
+            return
+
+        if isinstance(json_data, dict):
+            entries = [json_data]
+        elif isinstance(json_data, list):
+            entries = json_data
+        else:
+            await ctx.respond("The .json file has an unexpected structure.")
+            return
+
+        if not entries or not isinstance(entries[0], dict):
+            await ctx.respond("The .json file has an unexpected structure.")
+            return
+
+        if not entries:
+            await ctx.respond("The .json file is empty.")
+            return
+
+        entry = entries[0]
+        jstitle = entry.get("title", "Help")
+        jsdesc = entry.get("desc", "No description provided.")
+        
         embed = discord.Embed(
-            title=f"__How to start__",
-            description=f"Hallo {ctx.author.mention}, um auf unserem Server spielen zu können, ließ dir zuerst das Regelwerk in in #regelwerk durch. Um einem Department beizutreten wähle in #how-to-start eine Einweisungsrolle aus. Melde dich anschließend für eine Einweisung an. **Wichtig: gehe erst krz vor der Einweisung auf den Server!**",
+            title=f"{jstitle}",
+            description=f"{jsdesc}",
             color=discord.Color.yellow()
         )
 

+ 6 - 6
VPD_BOT/cogs/help_team.py

@@ -15,14 +15,14 @@ class helpteam(commands.Cog):
 
         json_path = Path(__file__).resolve().parent / "json_files" / "help_team.json"
         if not json_path.exists():
-            await ctx.respond("The help_team.json file is missing.")
+            await ctx.respond("The .json file is missing.")
             return
 
         try:
             with json_path.open("r", encoding="utf-8") as f:
                 json_data = json.load(f)
         except json.JSONDecodeError:
-            await ctx.respond("The help_team.json file is not valid JSON.")
+            await ctx.respond("The .json file is not valid JSON.")
             return
 
         if isinstance(json_data, dict):
@@ -30,19 +30,19 @@ class helpteam(commands.Cog):
         elif isinstance(json_data, list):
             entries = json_data
         else:
-            await ctx.respond("The help_team.json file has an unexpected structure.")
+            await ctx.respond("The .json file has an unexpected structure.")
             return
 
         if not entries or not isinstance(entries[0], dict):
-            await ctx.respond("The help_team.json file has an unexpected structure.")
+            await ctx.respond("The .json file has an unexpected structure.")
             return
 
         if not entries:
-            await ctx.respond("The help_team.json file is empty.")
+            await ctx.respond("The .json file is empty.")
             return
 
         entry = entries[0]
-        jstitle = entry.get("title", "Help Team")
+        jstitle = entry.get("title", "Help")
         jsdesc = entry.get("desc", "No description provided.")
         
         embed = discord.Embed(

+ 4 - 0
VPD_BOT/cogs/json_files/help_cache.json

@@ -0,0 +1,4 @@
+{ 
+     "title": "__How to join the Team on VicePD__",
+     "desc": "Um **dich** im team zu bewerben, muss du dich \n im support melden"  
+ }

+ 4 - 0
VPD_BOT/cogs/json_files/help_start.json

@@ -0,0 +1,4 @@
+{ 
+     "title": "__How to start on VicePD__",
+     "desc": "1. Lies dir zuerst das Regelwerk durch \n \n 2. Hol dir deine Einweisungsrolle \n \n 3. Melde dich für eine Einweisung an."  
+ }