|
@@ -1,3 +1,5 @@
|
|
|
|
|
+import json
|
|
|
|
|
+from pathlib import Path
|
|
|
import discord
|
|
import discord
|
|
|
from discord.ext import commands
|
|
from discord.ext import commands
|
|
|
from discord.commands import Option
|
|
from discord.commands import Option
|
|
@@ -10,14 +12,45 @@ class helpstart(commands.Cog):
|
|
|
|
|
|
|
|
#Command initialization
|
|
#Command initialization
|
|
|
@slash_command(name="help_how_to_start", description= "Get Infos how to start playing on the server")
|
|
@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
|
|
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(
|
|
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()
|
|
color=discord.Color.yellow()
|
|
|
)
|
|
)
|
|
|
|
|
|