Spaces:
Running
Running
button test
Browse files
app.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
-
import gradio as gr
|
2 |
import os
|
3 |
-
import threading
|
4 |
-
from urllib.parse import urlparse, parse_qs
|
5 |
import discord
|
6 |
-
from discord.ext import commands
|
7 |
import secrets
|
|
|
|
|
8 |
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
intents = discord.Intents.all()
|
11 |
bot = commands.Bot(command_prefix="!", intents=intents)
|
12 |
GRADIO_APP_URL = "https://huggingface.co/spaces/lunarflu/gradio-oauth2"
|
@@ -22,6 +25,8 @@ async def on_ready():
|
|
22 |
def generate_unique_string(length=6):
|
23 |
return secrets.token_hex(length // 2)
|
24 |
|
|
|
|
|
25 |
@bot.command()
|
26 |
async def sendlink(ctx, user: discord.User):
|
27 |
if ctx.author.id == 811235357663297546:
|
@@ -30,10 +35,27 @@ async def sendlink(ctx, user: discord.User):
|
|
30 |
unique_link = f"{GRADIO_APP_URL}?user_id={user.id}&token={unique_string}"
|
31 |
await user.send(f"Click the link to sign in with Hugging Face: {unique_link}")
|
32 |
|
33 |
-
def run_bot():
|
34 |
-
bot.run(DISCORD_TOKEN)
|
35 |
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# Gradio ------------------------------------------------------------------------------------------------------------
|
39 |
def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
@@ -83,3 +105,8 @@ with gr.Blocks() as demo:
|
|
83 |
login_button.click(check_login_wrapper, inputs=None, outputs=m1)
|
84 |
|
85 |
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import os
|
|
|
|
|
2 |
import discord
|
|
|
3 |
import secrets
|
4 |
+
import threading
|
5 |
+
import gradio as gr
|
6 |
|
7 |
+
from discord.ext import commands
|
8 |
+
from discord.ui import Button, View
|
9 |
+
from urllib.parse import urlparse, parse_qs
|
10 |
+
|
11 |
+
|
12 |
+
# Discord bot ------------------------------------------------------------------------------------------------------
|
13 |
intents = discord.Intents.all()
|
14 |
bot = commands.Bot(command_prefix="!", intents=intents)
|
15 |
GRADIO_APP_URL = "https://huggingface.co/spaces/lunarflu/gradio-oauth2"
|
|
|
25 |
def generate_unique_string(length=6):
|
26 |
return secrets.token_hex(length // 2)
|
27 |
|
28 |
+
|
29 |
+
# commands ---------------------------------------------------------------------------------------------------------
|
30 |
@bot.command()
|
31 |
async def sendlink(ctx, user: discord.User):
|
32 |
if ctx.author.id == 811235357663297546:
|
|
|
35 |
unique_link = f"{GRADIO_APP_URL}?user_id={user.id}&token={unique_string}"
|
36 |
await user.send(f"Click the link to sign in with Hugging Face: {unique_link}")
|
37 |
|
|
|
|
|
38 |
|
39 |
+
class DMButton(Button):
|
40 |
+
def __init__(self, label, style, message):
|
41 |
+
super().__init__(label=label, style=style)
|
42 |
+
self.message = message
|
43 |
+
|
44 |
+
async def callback(self, interaction: discord.Interaction):
|
45 |
+
await interaction.user.send(self.message)
|
46 |
+
await interaction.response.send_message(f"DM sent to {interaction.user.mention}", ephemeral=True)
|
47 |
+
|
48 |
+
@bot.command(name='sendbutton')
|
49 |
+
async def send_button(ctx):
|
50 |
+
if ctx.author.id == 811235357663297546:
|
51 |
+
unique_string = generate_unique_string()
|
52 |
+
user_tokens[user.id] = unique_string
|
53 |
+
unique_link = f"{GRADIO_APP_URL}?user_id={user.id}&token={unique_string}"
|
54 |
+
button = DMButton(label="Verify Discord Account", style=discord.ButtonStyle.primary, message=f"To complete the verification process, visit this link and click the 'sign in with Hugging Face' button: {unique_link}")
|
55 |
+
view = View()
|
56 |
+
view.add_item(button)
|
57 |
+
await ctx.send("Click the button below:", view=view)
|
58 |
+
|
59 |
|
60 |
# Gradio ------------------------------------------------------------------------------------------------------------
|
61 |
def hello(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
|
|
105 |
login_button.click(check_login_wrapper, inputs=None, outputs=m1)
|
106 |
|
107 |
demo.launch()
|
108 |
+
|
109 |
+
def run_bot():
|
110 |
+
bot.run(DISCORD_TOKEN)
|
111 |
+
|
112 |
+
threading.Thread(target=run_bot).start()
|