Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
test
Browse files
app.py
CHANGED
|
@@ -65,12 +65,28 @@ hf_token = os.environ.get("HF_TOKEN")
|
|
| 65 |
discord_loop = None # global variable
|
| 66 |
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
class DMButton(Button):
|
| 69 |
def __init__(self, label, style):
|
| 70 |
-
super().__init__(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
async def callback(self, interaction: discord.Interaction):
|
| 73 |
# await interaction.user.send(self.message) # this is for DMs, but users may have DMs disabled
|
|
|
|
|
|
|
| 74 |
user_id = interaction.user.id
|
| 75 |
|
| 76 |
guild = interaction.guild
|
|
@@ -86,13 +102,40 @@ class DMButton(Button):
|
|
| 86 |
await interaction.response.send_message(message, ephemeral=True)
|
| 87 |
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
@bot.event
|
| 90 |
async def on_ready():
|
| 91 |
try:
|
| 92 |
print(f'Logged in as {bot.user.name}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
guild = bot.get_guild(879548962464493619)
|
| 94 |
await guild.chunk() # get all users into bot cache
|
| 95 |
|
|
|
|
|
|
|
| 96 |
channel = bot.get_channel(900125909984624713)
|
| 97 |
if channel:
|
| 98 |
try:
|
|
@@ -106,7 +149,11 @@ async def on_ready():
|
|
| 106 |
except discord.NotFound:
|
| 107 |
print(f"Message with ID 1271145797433557023 not found.")
|
| 108 |
except discord.HTTPException as e:
|
| 109 |
-
print(f"Failed to fetch message with ID 1271145797433557023: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
print("------------------------------------------------------------------------")
|
| 111 |
except Exception as e:
|
| 112 |
print(f"on_ready Error: {e}")
|
|
|
|
| 65 |
discord_loop = None # global variable
|
| 66 |
|
| 67 |
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# new
|
| 71 |
+
@bot.event
|
| 72 |
+
async def on_interaction(interaction: discord.Interaction):
|
| 73 |
+
# Fires for every interaction—great catch-all probe.
|
| 74 |
+
cid = getattr(interaction.data, "get", lambda k, d=None: None)("custom_id")
|
| 75 |
+
logging.debug(f"on_interaction custom_id={cid!r} responded={interaction.response.is_done()}")
|
| 76 |
+
|
| 77 |
+
|
| 78 |
class DMButton(Button):
|
| 79 |
def __init__(self, label, style):
|
| 80 |
+
super().__init__(
|
| 81 |
+
label="Verify Discord Account",
|
| 82 |
+
style=discord.ButtonStyle.primary,
|
| 83 |
+
custom_id="verify_discord_account_button" # <- stable
|
| 84 |
+
)
|
| 85 |
|
| 86 |
async def callback(self, interaction: discord.Interaction):
|
| 87 |
# await interaction.user.send(self.message) # this is for DMs, but users may have DMs disabled
|
| 88 |
+
await interaction.response.defer(ephemeral=True) # to fix interaction issue
|
| 89 |
+
|
| 90 |
user_id = interaction.user.id
|
| 91 |
|
| 92 |
guild = interaction.guild
|
|
|
|
| 102 |
await interaction.response.send_message(message, ephemeral=True)
|
| 103 |
|
| 104 |
|
| 105 |
+
# new
|
| 106 |
+
class PersistentVerifyView(discord.ui.View):
|
| 107 |
+
def __init__(self):
|
| 108 |
+
super().__init__(timeout=None) # <- persistent
|
| 109 |
+
self.add_item(DMButton())
|
| 110 |
+
|
| 111 |
+
async def on_error(self, error: Exception, item, interaction: discord.Interaction):
|
| 112 |
+
import logging
|
| 113 |
+
logging.exception("Component error")
|
| 114 |
+
if interaction.response.is_done():
|
| 115 |
+
await interaction.followup.send("Something broke while handling that click.", ephemeral=True)
|
| 116 |
+
else:
|
| 117 |
+
await interaction.response.send_message("Something broke while handling that click.", ephemeral=True)
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
|
| 121 |
@bot.event
|
| 122 |
async def on_ready():
|
| 123 |
try:
|
| 124 |
print(f'Logged in as {bot.user.name}')
|
| 125 |
+
|
| 126 |
+
#new
|
| 127 |
+
bot.add_view(PersistentVerifyView()) # <- binds handler to custom_id
|
| 128 |
+
channel = bot.get_channel(900125909984624713)
|
| 129 |
+
msg = await channel.fetch_message(1271145797433557023)
|
| 130 |
+
await msg.edit(view=PersistentVerifyView()) # <- updates the message’s components
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
|
| 134 |
guild = bot.get_guild(879548962464493619)
|
| 135 |
await guild.chunk() # get all users into bot cache
|
| 136 |
|
| 137 |
+
|
| 138 |
+
"""
|
| 139 |
channel = bot.get_channel(900125909984624713)
|
| 140 |
if channel:
|
| 141 |
try:
|
|
|
|
| 149 |
except discord.NotFound:
|
| 150 |
print(f"Message with ID 1271145797433557023 not found.")
|
| 151 |
except discord.HTTPException as e:
|
| 152 |
+
print(f"Failed to fetch message with ID 1271145797433557023: {e}")
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
"""
|
| 156 |
+
|
| 157 |
print("------------------------------------------------------------------------")
|
| 158 |
except Exception as e:
|
| 159 |
print(f"on_ready Error: {e}")
|