On branch DiscordProfile

Initial commit
This commit is contained in:
EG
2026-07-01 15:15:07 +03:00
commit d4bf750c9e
3125 changed files with 601334 additions and 0 deletions
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+91
View File
@@ -0,0 +1,91 @@
from services.profile_manager import load_profile, save_profile
def set_attach(
slot: int,
name: str,
description: str,
icon: str = "",
mini_icon: str = ""
):
"""
Меняет один из 6 attach-слотов
"""
if slot < 1 or slot > 6:
raise ValueError("Attach slot должен быть от 1 до 6")
profile = load_profile()
attachments = profile.setdefault(
"attachments",
[
{},
{},
{},
{},
{},
{}
]
)
attachments[slot - 1] = {
"name": name,
"description": description,
"icon": icon,
"mini_icon": mini_icon
}
profile["attachments"] = attachments
save_profile(profile)
return attachments[slot - 1]
def get_attach(slot: int):
if slot < 1 or slot > 6:
raise ValueError("Attach slot должен быть от 1 до 6")
profile = load_profile()
attachments = profile.get(
"attachments",
[
{},
{},
{},
{},
{},
{}
]
)
return attachments[slot - 1]
def clear_attach(slot: int):
if slot < 1 or slot > 6:
raise ValueError("Attach slot должен быть от 1 до 6")
profile = load_profile()
profile["attachments"][slot - 1] = {}
save_profile(profile)
+70
View File
@@ -0,0 +1,70 @@
from services.profile_manager import load_profile, save_profile
def set_description(slot: int, text: str):
"""
Меняет пользовательское описание.
slot:
1 -> Discord description 2
2 -> Discord description 3
"""
if slot < 1 or slot > 2:
raise ValueError(
"Доступны только описания 1 и 2"
)
profile = load_profile()
descriptions = profile.setdefault(
"descriptions",
{
"1": "",
"2": "",
"3": ""
}
)
discord_slot = slot + 1
descriptions[str(discord_slot)] = text
profile["descriptions"] = descriptions
save_profile(profile)
return text
def get_description(slot: int):
if slot < 1 or slot > 2:
raise ValueError(
"Доступны только описания 1 и 2"
)
profile = load_profile()
descriptions = profile.get(
"descriptions",
{}
)
discord_slot = slot + 1
return descriptions.get(
str(discord_slot),
""
)
+204
View File
@@ -0,0 +1,204 @@
import os
import requests
from dotenv import load_dotenv
from services.profile_manager import load_profile
load_dotenv()
APP_ID = os.getenv("APP_ID")
TOKEN = os.getenv("TOKEN")
UID = os.getenv("UID")
def build_dynamic(profile):
dynamic = []
# ======================
# TEXT DYNAMIC
# ======================
old_dynamic = profile.get(
"dynamic",
[]
)
for item in old_dynamic:
if item.get("name") in [
"time",
"sub2",
"sub3"
]:
dynamic.append(
{
"type": 1,
"name": item["name"],
"value": item["value"]
}
)
# ======================
# ATTACHMENTS
# ======================
attachments = profile.get(
"attachments",
[]
)
for index, attach in enumerate(
attachments,
start=1
):
if not attach:
continue
if attach.get("name"):
dynamic.append(
{
"type": 1,
"name": f"attach_{index}_name",
"value": attach["name"]
}
)
if attach.get("description"):
dynamic.append(
{
"type": 1,
"name": f"attach_{index}_description",
"value": attach["description"]
}
)
if attach.get("icon"):
dynamic.append(
{
"type": 3,
"name": f"attach_{index}_icon",
"value": {
"url": attach["icon"]
}
}
)
if attach.get("mini_icon"):
dynamic.append(
{
"type": 3,
"name": f"attach_{index}_mini_icon",
"value": {
"url": attach["mini_icon"]
}
}
)
return dynamic
def sync():
profile = load_profile()
payload = {
"username": profile.get(
"username",
"Profile Widget"
),
"data": {
"dynamic": build_dynamic(profile)
}
}
print(
"PAYLOAD:",
payload,
flush=True
)
url = (
"https://discord.com/api/v9/"
f"applications/{APP_ID}/users/"
f"{UID}/identities/0/profile"
)
headers = {
"Authorization":
f"Bot {TOKEN}",
"User-Agent":
"DiscordBot (https://github.com/discord/discord-api-docs, 1.0.0)",
"Content-Type":
"application/json"
}
print(
"PATCH START",
flush=True
)
try:
response = requests.patch(
url,
json=payload,
headers=headers,
timeout=20
)
print(
"PATCH END",
response.status_code,
response.text,
flush=True
)
return response
except Exception as e:
print(
"PATCH ERROR",
repr(e),
flush=True
)
return None
+64
View File
@@ -0,0 +1,64 @@
import json
import os
BASE = "/home/eg/profile-system"
FILE = os.path.join(
BASE,
"config/profile.json"
)
def load_profile():
with open(
FILE,
"r",
encoding="utf-8"
) as f:
return json.load(f)
def save_profile(data):
with open(
FILE,
"w",
encoding="utf-8"
) as f:
json.dump(
data,
f,
indent=4,
ensure_ascii=False
)
def set_value(name,value):
data = load_profile()
for item in data["dynamic"]:
if item["name"] == name:
item["value"] = value
save_profile(data)
return
data["dynamic"].append(
{
"type":1,
"name":name,
"value":value
}
)
save_profile(data)
+23
View File
@@ -0,0 +1,23 @@
import datetime
from services.profile_manager import set_value
def get_local_time():
now = datetime.datetime.now()
return now.strftime("%H:%M")
def update_time():
time = get_local_time()
set_value(
"time",
f"My time rn is {time}"
)
return time