Răsfoiți Sursa

changing the verify system, to edit the message in a json not in the setup command.

BaumSplitter41 1 lună în urmă
părinte
comite
26b7c789bd
2 a modificat fișierele cu 49 adăugiri și 6 ștergeri
  1. 4 0
      VPD_BOT/json_files/verify_text.json
  2. 45 6
      VPD_BOT/main.py

+ 4 - 0
VPD_BOT/json_files/verify_text.json

@@ -0,0 +1,4 @@
+{ 
+     "title": "Regelwerk",
+     "desc": "Herzlich willkommen auf VicePD! \n\n Bitte lies dir kurz unser [Regelwerk](https://vicepd-fivem.de/?page_id=94) durch. Mit einem Klick auf „Verifizieren“ bestätigst du, dass du alles gelesen hast und schaltest deinen Zugriff frei. \n \n Starte deinen Weg beim LSCSO: Melde dich im Channel <#1469776042058191055> und mache den ersten Schritt in deine Laufbahn als LEO-Beamter. \n \n Viel Spaß auf dem Server!"  
+ }

+ 45 - 6
VPD_BOT/main.py

@@ -8,6 +8,9 @@ from datetime import datetime, time
 import configparser
 import mysql.connector
 import asyncio
+import json
+from flask import Flask, request, jsonify
+from pathlib import Path
 
 
 intents = discord.Intents.default()
@@ -43,6 +46,10 @@ dbdb = os.getenv("DATABASE")
 if dbdb is None:
     raise ValueError("DATABASE not found in .env file")
 
+API_KEY = os.getenv("API_KEY")
+if API_KEY is None:
+    raise ValueError("API_KEY not found in .env file")
+
 #---------------------------------#
 #ConfigParser
 
@@ -577,22 +584,52 @@ class PersistentRoleView(discord.ui.View):
         await interaction.response.send_message(msg, ephemeral=True)
 
 
-
-@bot.slash_command(name="verify_message", description="Send the reactionrole message| This is for setup only!")
+#Setup the reaction role message
+@bot.slash_command(name="verify_message", description="Send the reactionrole message | This is for setup only!")
 async def setup_rr(
     ctx: discord.ApplicationContext,
     channel: discord.TextChannel, 
-    title: str,
-    description: str
 ):
 
     if not ctx.author.guild_permissions.administrator:
         await ctx.respond("You dont have the permissions to do that..", ephemeral=True)
         return
+    
+    json_path = Path(__file__).resolve().parent.joinpath("json_files", "verify_text.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", "Verify")
+    jsdesc = entry.get("desc", "No description provided.")
 
     embed = discord.Embed(
-        title=title,
-        description=f"{description}\n\nViel Spass auf dem Server!",
+        title=jstitle,
+        description=jsdesc,
         color=discord.Color.red()
     )
     embed.set_image(url="https://i.imgur.com/FoF791J.png")
@@ -667,6 +704,8 @@ async def update_users_periodically():
         await asyncio.sleep(60)  # Update every minute
 
 
+
+#_________________________________#
 #---------------------------------#
 #Run function
 load_extensions()