Procházet zdrojové kódy

Fixing missing variable assignments in einweisung.py Adding .json implementation in help_cache.py

BaumSplitter41 před 4 měsíci
rodič
revize
b59c6e7636

+ 2 - 1
VPD_BOT/cogs/einweisung.py

@@ -44,7 +44,8 @@ class einweisung(commands.Cog):
         department2_role_id = int(config.get('Einweisung', 'department2_role_id'))
 
         if department2_supervisor_id == "" or department2_role_id == "":
-            return
+            department2_role = None
+            department2_supervisor = None
         else:
             department2_role = server.get_role(department2_role_id)
             department2_supervisor = server.get_role(department2_supervisor_id)

+ 36 - 9
VPD_BOT/cogs/help_cache.py

@@ -2,6 +2,8 @@ import discord
 from discord.ext import commands
 from discord.commands import Option
 from discord.commands import slash_command
+import json
+from pathlib import Path
 
 
 class helpcache(commands.Cog):
@@ -16,19 +18,44 @@ class helpcache(commands.Cog):
         ctx,
     ):
         server = ctx.guild
+        json_path = Path(__file__).resolve().parent / "json_files" / "help_cache.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 clear your game cache__",
-            description=f"Follow the follwing steps to clear your game cache:",
+            title=f"{jstitle}",
+            description=f"{jsdesc}",
             color=discord.Color.yellow()
         )
 
-        embed.add_field(name="Close Game", value="Close FiveM completely", inline=False)
-        embed.add_field(name="Press keys", value="Win + R", inline=False)
-        embed.add_field(name="Go to the folder", value="\Local\FiveM\FiveM.app\data", inline=False)
-        embed.add_field(name="Delete the folders", value="cache, server-cache, server-cache-priv", inline=False)
-        embed.add_field(name="Restart Game", value="Restart the game and download the resources again.", inline=False)
-
-
         embed.set_thumbnail(url=server.icon)
         embed.set_author(name="VicePD", icon_url="https://i.imgur.com/6QteFrg.png")
         embed.set_footer(text="VicePD - Bot | Made by BaumSplitter41")

+ 2 - 2
VPD_BOT/cogs/json_files/help_cache.json

@@ -1,4 +1,4 @@
 { 
-     "title": "__How to join the Team on VicePD__",
-     "desc": "Um **dich** im team zu bewerben, muss du dich \n im support melden"  
+     "title": "__How to clear your game cache__",
+     "desc": "Follow the follwing steps to clear your game cache: \n **Close Game** \n Close FiveM completely \n **Press keys** \n Win + R \n Go to the folder \n ```/Local/FiveM/FiveM.app/data```\n **Delete the folders** \n cache, server-cache, server-cache-priv \n **Restart Game** \n Restart the game and download the resources again."  
  }