add RPC Manager (not working)
This commit is contained in:
173
RPC_Manager.py
Normal file
173
RPC_Manager.py
Normal file
@@ -0,0 +1,173 @@
|
||||
from pypresence import Presence
|
||||
import time
|
||||
import os
|
||||
|
||||
# ========= CONFIG =========
|
||||
CLIENT_ID = "TON_CLIENT_ID_ICI" # à récupérer sur https://discord.com/developers
|
||||
# =========================
|
||||
|
||||
|
||||
def ask_buttons():
|
||||
"""
|
||||
Crée jusqu'à 2 boutons au format attendu par Discord :
|
||||
[{"label": "...", "url": "https://..."}]
|
||||
Doc pypresence: paramètre 'buttons' de Presence.update() :contentReference[oaicite:3]{index=3}
|
||||
"""
|
||||
buttons = []
|
||||
for i in range(1, 3):
|
||||
label = input(f"Label du bouton {i} (laisser vide pour arrêter) : ").strip()
|
||||
if not label:
|
||||
break
|
||||
url = input(f"URL du bouton {i} (https://...) : ").strip()
|
||||
if not url:
|
||||
print("URL vide, bouton ignoré.")
|
||||
continue
|
||||
buttons.append({"label": label, "url": url})
|
||||
|
||||
return buttons if buttons else None
|
||||
|
||||
|
||||
def ask_party_size():
|
||||
"""
|
||||
Discord / pypresence : party_size = [current, max] :contentReference[oaicite:4]{index=4}
|
||||
"""
|
||||
text = input("Taille de party (format actuel/max, ex 1/4, vide pour aucune) : ").strip()
|
||||
if not text:
|
||||
return None
|
||||
try:
|
||||
cur_str, max_str = text.split("/")
|
||||
return [int(cur_str), int(max_str)]
|
||||
except Exception:
|
||||
print("Format invalide, party ignorée.")
|
||||
return None
|
||||
|
||||
|
||||
def build_activity_kwargs():
|
||||
"""
|
||||
Construit les kwargs passés à Presence.update(**kwargs)
|
||||
en suivant la structure de l'objet activity de la doc Discord. :contentReference[oaicite:5]{index=5}
|
||||
"""
|
||||
print("\n--- Texte principal ---")
|
||||
details = input("details (ligne du haut, ce que tu fais) : ").strip()
|
||||
state = input("state (ligne du bas, statut / contexte) : ").strip()
|
||||
|
||||
use_timer = input("Afficher un timer de durée ? (y/n) : ").lower().startswith("y")
|
||||
start_ts = int(time.time() * 1000) if use_timer else None # ms epoch, comme dans la doc pypresence :contentReference[oaicite:6]{index=6}
|
||||
|
||||
print("\n--- Images (assets) ---")
|
||||
large_image = input("large_image (nom d'asset, vide = rien) : ").strip() or None
|
||||
large_text = input("large_text (tooltip de la grande image, vide = rien) : ").strip() or None
|
||||
small_image = input("small_image (nom d'asset, vide = rien) : ").strip() or None
|
||||
small_text = input("small_text (tooltip petite image, vide = rien) : ").strip() or None
|
||||
|
||||
print("\n--- Party (optionnel) ---")
|
||||
party_size = ask_party_size()
|
||||
|
||||
print("\n--- Boutons (optionnel, max 2) ---")
|
||||
buttons = ask_buttons()
|
||||
|
||||
kwargs = {}
|
||||
|
||||
# → activity.details / activity.state
|
||||
if details:
|
||||
kwargs["details"] = details
|
||||
if state:
|
||||
kwargs["state"] = state
|
||||
|
||||
# → activity.timestamps.start
|
||||
if start_ts is not None:
|
||||
kwargs["start"] = start_ts
|
||||
|
||||
# → activity.assets
|
||||
if large_image:
|
||||
kwargs["large_image"] = large_image
|
||||
if large_text:
|
||||
kwargs["large_text"] = large_text
|
||||
if small_image:
|
||||
kwargs["small_image"] = small_image
|
||||
if small_text:
|
||||
kwargs["small_text"] = small_text
|
||||
|
||||
# → activity.party
|
||||
if party_size:
|
||||
kwargs["party_size"] = party_size
|
||||
|
||||
# → activity.buttons
|
||||
if buttons:
|
||||
kwargs["buttons"] = buttons
|
||||
|
||||
kwargs["instance"] = True
|
||||
|
||||
return kwargs
|
||||
|
||||
|
||||
def main_menu():
|
||||
if CLIENT_ID == "1447561790564204687":
|
||||
print("[!] Pense à mettre ton CLIENT_ID dans le script avant de lancer.")
|
||||
return
|
||||
|
||||
rpc = Presence(CLIENT_ID)
|
||||
connected = False
|
||||
|
||||
while True:
|
||||
print("\n=== Discord RPC Manager (style doc officielle) ===")
|
||||
print("1) Se connecter / reconnecter à Discord")
|
||||
print("2) Mettre à jour la Rich Presence")
|
||||
print("3) Effacer la Rich Presence")
|
||||
print("4) Quitter")
|
||||
choice = input("Choix : ").strip()
|
||||
|
||||
if choice == "1":
|
||||
if connected:
|
||||
print("[i] Déjà connecté.")
|
||||
continue
|
||||
try:
|
||||
rpc.connect()
|
||||
connected = True
|
||||
print("[+] Connecté à Discord.")
|
||||
except Exception as e:
|
||||
print("[!] Erreur de connexion :", e)
|
||||
|
||||
elif choice == "2":
|
||||
if not connected:
|
||||
try:
|
||||
rpc.connect()
|
||||
connected = True
|
||||
print("[+] Connecté à Discord.")
|
||||
except Exception as e:
|
||||
print("[!] Impossible de se connecter :", e)
|
||||
continue
|
||||
|
||||
kwargs = build_activity_kwargs()
|
||||
try:
|
||||
rpc.update(**kwargs)
|
||||
print("[+] Rich Presence mise à jour avec succès !")
|
||||
except Exception as e:
|
||||
print("[!] Erreur lors de la mise à jour :", e)
|
||||
|
||||
elif choice == "3":
|
||||
if not connected:
|
||||
print("[i] Pas connecté.")
|
||||
continue
|
||||
try:
|
||||
rpc.clear()
|
||||
print("[i] Rich Presence effacée.")
|
||||
except Exception as e:
|
||||
print("[!] Erreur lors de l'effacement :", e)
|
||||
|
||||
elif choice == "4":
|
||||
print("Fermeture...")
|
||||
if connected:
|
||||
try:
|
||||
rpc.clear()
|
||||
rpc.close()
|
||||
except Exception:
|
||||
pass
|
||||
break
|
||||
|
||||
else:
|
||||
print("[!] Choix invalide.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main_menu()
|
||||
Reference in New Issue
Block a user