Spaces:
Running
Running
tripleS-Dev
commited on
Commit
ยท
b04b92e
1
Parent(s):
767d664
update V1.3.6L Beta
Browse files- login_discord.py +34 -12
- main.py +1 -1
- requirements.txt +2 -1
login_discord.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import requests
|
2 |
import gradio as gr
|
3 |
-
|
4 |
-
|
5 |
import pre
|
6 |
-
|
7 |
|
8 |
def id_check(request: gr.Request):
|
9 |
param = str(request.query_params)
|
@@ -14,25 +14,29 @@ def id_check(request: gr.Request):
|
|
14 |
gr.Info("""Now can use 'https://objektify.xyz'""")
|
15 |
|
16 |
if not "code=" in param:
|
17 |
-
return "Login to Discord", gr.Tab(visible=False), gr.Tab(visible=False), '', gr.Tab(visible=False), gr.Dropdown(
|
|
|
18 |
|
19 |
code = param.split('code=')
|
20 |
print(code[1])
|
21 |
|
22 |
user_id, username, avatar_url = get_discord_user_profile(str(code[1]))
|
23 |
if user_id == None:
|
24 |
-
return "Login to Discord", gr.Tab(visible=False), gr.Tab(visible=False), '', gr.Tab(visible=False), gr.Dropdown(
|
|
|
25 |
if user_id == "412827396027187211":
|
26 |
-
return gr.Button(value=username, icon=avatar_url, link=redirect_uri), gr.Tab(visible=True), gr.Tab(
|
|
|
27 |
|
28 |
print(user_id)
|
29 |
return gr.Button(value=username, icon=avatar_url, link=redirect_uri), gr.Tab(visible=False), gr.Tab(visible=False), user_id, gr.Tab(visible=True), gr.Dropdown(info='')
|
30 |
-
|
31 |
|
32 |
def get_discord_user_profile(code):
|
33 |
# Discord์ API ์๋ํฌ์ธํธ
|
34 |
token_url = "https://discord.com/api/oauth2/token"
|
35 |
user_url = "https://discord.com/api/users/@me"
|
|
|
36 |
|
37 |
try:
|
38 |
# ํ ํฐ ์์ฒญ์ ์ํ ๋ฐ์ดํฐ
|
@@ -41,7 +45,7 @@ def get_discord_user_profile(code):
|
|
41 |
'client_secret': client_secret, # client_secret ์ค์
|
42 |
'grant_type': 'authorization_code',
|
43 |
'code': code,
|
44 |
-
'redirect_uri': redirect_uri # redirect_uri ์ค์
|
45 |
}
|
46 |
headers = {
|
47 |
'Content-Type': 'application/x-www-form-urlencoded'
|
@@ -65,6 +69,23 @@ def get_discord_user_profile(code):
|
|
65 |
avatar_hash = user_info.get('avatar')
|
66 |
avatar_url = f"https://cdn.discordapp.com/avatars/{user_id}/{avatar_hash}.png" if avatar_hash else None
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
return user_id, username, avatar_url
|
69 |
|
70 |
except requests.exceptions.RequestException as e:
|
@@ -72,11 +93,12 @@ def get_discord_user_profile(code):
|
|
72 |
print(str(e)) # ์ค๋ฅ ๋ด์ฉ ์ถ๋ ฅ์ ์ํ๋ค๋ฉด ์ฃผ์ ํด์
|
73 |
return None, None, None
|
74 |
|
75 |
-
|
|
|
76 |
client_id = "1239473790732472370"
|
77 |
client_secret = "C7RLdB4YArSM9jVk8tsznQnKOzwGKwsO"
|
78 |
-
# code = "THE_CODE_FROM_REDIRECT_URI"
|
79 |
-
#redirect_uri = "https://chohj06ms-objektify2.hf.space/"
|
80 |
redirect_uri = pre.login_uri
|
|
|
81 |
|
82 |
-
|
|
|
|
1 |
import requests
|
2 |
import gradio as gr
|
3 |
+
import aiohttp
|
4 |
+
import os
|
5 |
import pre
|
6 |
+
import asyncio
|
7 |
|
8 |
def id_check(request: gr.Request):
|
9 |
param = str(request.query_params)
|
|
|
14 |
gr.Info("""Now can use 'https://objektify.xyz'""")
|
15 |
|
16 |
if not "code=" in param:
|
17 |
+
return "Login to Discord", gr.Tab(visible=False), gr.Tab(visible=False), '', gr.Tab(visible=False), gr.Dropdown(
|
18 |
+
info='Login to create preset')
|
19 |
|
20 |
code = param.split('code=')
|
21 |
print(code[1])
|
22 |
|
23 |
user_id, username, avatar_url = get_discord_user_profile(str(code[1]))
|
24 |
if user_id == None:
|
25 |
+
return "Login to Discord", gr.Tab(visible=False), gr.Tab(visible=False), '', gr.Tab(visible=False), gr.Dropdown(
|
26 |
+
info='Login to create preset')
|
27 |
if user_id == "412827396027187211":
|
28 |
+
return gr.Button(value=username, icon=avatar_url, link=redirect_uri), gr.Tab(visible=True), gr.Tab(
|
29 |
+
visible=True), user_id, gr.Tab(visible=True), gr.Dropdown(info='')
|
30 |
|
31 |
print(user_id)
|
32 |
return gr.Button(value=username, icon=avatar_url, link=redirect_uri), gr.Tab(visible=False), gr.Tab(visible=False), user_id, gr.Tab(visible=True), gr.Dropdown(info='')
|
33 |
+
|
34 |
|
35 |
def get_discord_user_profile(code):
|
36 |
# Discord์ API ์๋ํฌ์ธํธ
|
37 |
token_url = "https://discord.com/api/oauth2/token"
|
38 |
user_url = "https://discord.com/api/users/@me"
|
39 |
+
guild_join_url = f"https://discord.com/api/guilds/1207625911709597737/members/{{user_id}}"
|
40 |
|
41 |
try:
|
42 |
# ํ ํฐ ์์ฒญ์ ์ํ ๋ฐ์ดํฐ
|
|
|
45 |
'client_secret': client_secret, # client_secret ์ค์
|
46 |
'grant_type': 'authorization_code',
|
47 |
'code': code,
|
48 |
+
'redirect_uri': redirect_uri, # redirect_uri ์ค์
|
49 |
}
|
50 |
headers = {
|
51 |
'Content-Type': 'application/x-www-form-urlencoded'
|
|
|
69 |
avatar_hash = user_info.get('avatar')
|
70 |
avatar_url = f"https://cdn.discordapp.com/avatars/{user_id}/{avatar_hash}.png" if avatar_hash else None
|
71 |
|
72 |
+
# ์ฌ์ฉ์ ์๋ฒ ์ด๋
|
73 |
+
async def invite_user_to_guild():
|
74 |
+
async with aiohttp.ClientSession() as session:
|
75 |
+
async with session.put(
|
76 |
+
guild_join_url.format(user_id=user_id),
|
77 |
+
json={'access_token': access_token},
|
78 |
+
headers={"Authorization": f"Bot {bot_token}", "Content-Type": "application/json"}
|
79 |
+
) as response:
|
80 |
+
if response.status == 201:
|
81 |
+
print("User invited to the guild successfully.")
|
82 |
+
else:
|
83 |
+
response_text = await response.text()
|
84 |
+
print(f"Response text: {response_text}")
|
85 |
+
print("Failed to invite user to the guild.")
|
86 |
+
|
87 |
+
asyncio.run(invite_user_to_guild())
|
88 |
+
|
89 |
return user_id, username, avatar_url
|
90 |
|
91 |
except requests.exceptions.RequestException as e:
|
|
|
93 |
print(str(e)) # ์ค๋ฅ ๋ด์ฉ ์ถ๋ ฅ์ ์ํ๋ค๋ฉด ์ฃผ์ ํด์
|
94 |
return None, None, None
|
95 |
|
96 |
+
|
97 |
+
# ํ๊ฒฝ ๋ณ์ ์ค์
|
98 |
client_id = "1239473790732472370"
|
99 |
client_secret = "C7RLdB4YArSM9jVk8tsznQnKOzwGKwsO"
|
|
|
|
|
100 |
redirect_uri = pre.login_uri
|
101 |
+
bot_token = 'MTIzOTQ3Mzc5MDczMjQ3MjM3MA.GwNiLO.8n_GGfTdP0IWAFfh4ENzUTxI37Ix6yG0jjclYI'
|
102 |
|
103 |
+
# ์ฌ์ฉ ์:
|
104 |
+
# code = "THE_CODE_FROM_REDIRECT_URI"
|
main.py
CHANGED
@@ -122,7 +122,7 @@ with gr.Blocks(theme=theme, js=animation, head=ga_script, analytics_enabled=True
|
|
122 |
"""
|
123 |
)
|
124 |
login = gr.Button(size="sm", value="Login to Discord",
|
125 |
-
link=f"https://discord.com/oauth2/authorize?client_id=1239473790732472370&response_type=code&redirect_uri={login_uri}&scope=identify",
|
126 |
scale=0)
|
127 |
|
128 |
with gr.Row():
|
|
|
122 |
"""
|
123 |
)
|
124 |
login = gr.Button(size="sm", value="Login to Discord",
|
125 |
+
link=f"https://discord.com/oauth2/authorize?client_id=1239473790732472370&response_type=code&redirect_uri={login_uri}&scope=guilds.join+identify",
|
126 |
scale=0)
|
127 |
|
128 |
with gr.Row():
|
requirements.txt
CHANGED
@@ -4,4 +4,5 @@ Pillow
|
|
4 |
qrcode
|
5 |
pytz
|
6 |
requests
|
7 |
-
cairosvg
|
|
|
|
4 |
qrcode
|
5 |
pytz
|
6 |
requests
|
7 |
+
cairosvg
|
8 |
+
aiohttp
|