Hana Celeste commited on
Update app/discord_logic.py
Browse files- app/discord_logic.py +4 -8
app/discord_logic.py
CHANGED
|
@@ -11,7 +11,6 @@ class DiscordApp:
|
|
| 11 |
def resolve_dns(self, hostname):
|
| 12 |
"""Tự tìm IP của hostname nếu hệ thống bị lỗi DNS"""
|
| 13 |
try:
|
| 14 |
-
# Thử dùng DNS của Google để tìm IP
|
| 15 |
resolver = dns.resolver.Resolver()
|
| 16 |
resolver.nameservers = ['8.8.8.8', '1.1.1.1']
|
| 17 |
answers = resolver.resolve(hostname, 'A')
|
|
@@ -23,9 +22,9 @@ class DiscordApp:
|
|
| 23 |
if not self.client:
|
| 24 |
self.client = httpx.AsyncClient(
|
| 25 |
timeout=20.0,
|
| 26 |
-
verify=False
|
| 27 |
)
|
| 28 |
-
print("✅ [Discord] HTTPX Client started
|
| 29 |
|
| 30 |
async def stop(self):
|
| 31 |
if self.client:
|
|
@@ -35,7 +34,6 @@ class DiscordApp:
|
|
| 35 |
if not self.token:
|
| 36 |
return {"status": "error", "message": "Missing TOKEN"}
|
| 37 |
|
| 38 |
-
# Thử lấy IP của discord.com
|
| 39 |
ip = self.resolve_dns("discord.com")
|
| 40 |
if ip:
|
| 41 |
url = f"https://{ip}/api/v10/users/{uid}"
|
|
@@ -44,7 +42,6 @@ class DiscordApp:
|
|
| 44 |
"Host": "discord.com" # Quan trọng: Phải giữ Host header là discord.com
|
| 45 |
}
|
| 46 |
else:
|
| 47 |
-
# Nếu không tìm được IP thì dùng URL mặc định
|
| 48 |
url = f"https://discord.com/api/v10/users/{uid}"
|
| 49 |
headers = {"Authorization": f"Bot {self.token}"}
|
| 50 |
|
|
@@ -55,10 +52,9 @@ class DiscordApp:
|
|
| 55 |
user_id = data.get("id")
|
| 56 |
avatar_hash = data.get("avatar")
|
| 57 |
|
| 58 |
-
# Link avatar dùng CDN (thường CDN ít bị lỗi DNS hơn)
|
| 59 |
if avatar_hash:
|
| 60 |
-
fmt = "gif" if avatar_hash.startswith("a_") else "
|
| 61 |
-
avatar_url = f"https://cdn.discordapp.com/avatars/{user_id}/{avatar_hash}.
|
| 62 |
else:
|
| 63 |
default_index = (int(user_id) >> 22) % 6
|
| 64 |
avatar_url = f"https://cdn.discordapp.com/embed/avatars/{default_index}.png"
|
|
|
|
| 11 |
def resolve_dns(self, hostname):
|
| 12 |
"""Tự tìm IP của hostname nếu hệ thống bị lỗi DNS"""
|
| 13 |
try:
|
|
|
|
| 14 |
resolver = dns.resolver.Resolver()
|
| 15 |
resolver.nameservers = ['8.8.8.8', '1.1.1.1']
|
| 16 |
answers = resolver.resolve(hostname, 'A')
|
|
|
|
| 22 |
if not self.client:
|
| 23 |
self.client = httpx.AsyncClient(
|
| 24 |
timeout=20.0,
|
| 25 |
+
verify=False
|
| 26 |
)
|
| 27 |
+
print("✅ [Discord] HTTPX Client started.")
|
| 28 |
|
| 29 |
async def stop(self):
|
| 30 |
if self.client:
|
|
|
|
| 34 |
if not self.token:
|
| 35 |
return {"status": "error", "message": "Missing TOKEN"}
|
| 36 |
|
|
|
|
| 37 |
ip = self.resolve_dns("discord.com")
|
| 38 |
if ip:
|
| 39 |
url = f"https://{ip}/api/v10/users/{uid}"
|
|
|
|
| 42 |
"Host": "discord.com" # Quan trọng: Phải giữ Host header là discord.com
|
| 43 |
}
|
| 44 |
else:
|
|
|
|
| 45 |
url = f"https://discord.com/api/v10/users/{uid}"
|
| 46 |
headers = {"Authorization": f"Bot {self.token}"}
|
| 47 |
|
|
|
|
| 52 |
user_id = data.get("id")
|
| 53 |
avatar_hash = data.get("avatar")
|
| 54 |
|
|
|
|
| 55 |
if avatar_hash:
|
| 56 |
+
fmt = "gif" if avatar_hash.startswith("a_") else "webp"
|
| 57 |
+
avatar_url = f"https://cdn.discordapp.com/avatars/{user_id}/{avatar_hash}.webp?size=4096"
|
| 58 |
else:
|
| 59 |
default_index = (int(user_id) >> 22) % 6
|
| 60 |
avatar_url = f"https://cdn.discordapp.com/embed/avatars/{default_index}.png"
|