Spaces:
Running on CPU Upgrade

lunarflu HF Staff commited on
Commit
2deada4
Β·
verified Β·
1 Parent(s): f3bd195

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -75
app.py CHANGED
@@ -73,15 +73,10 @@ class DMButton(Button):
73
  await interaction.response.send_message(message, ephemeral=True)
74
 
75
 
76
-
77
-
78
  @bot.event
79
  async def on_ready():
80
  try:
81
-
82
  print(f'Logged in as {bot.user.name}')
83
-
84
-
85
  guild = bot.get_guild(879548962464493619)
86
  await guild.chunk() # get all users into bot cache
87
 
@@ -99,86 +94,17 @@ async def on_ready():
99
  print(f"Message with ID 1271145797433557023 not found.")
100
  except discord.HTTPException as e:
101
  print(f"Failed to fetch message with ID 1271145797433557023: {e}")
102
-
103
-
104
-
105
-
106
-
107
-
108
  print("------------------------------------------------------------------------")
109
  except Exception as e:
110
  print(f"on_ready Error: {e}")
111
 
112
 
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
124
  def run_bot():
125
  bot.run(DISCORD_TOKEN)
126
  threading.Thread(target=run_bot).start()
127
 
128
 
129
-
130
- #-------------------------------------------------------------------------------------------------------------------------------
131
-
132
-
133
- """
134
- def verify_button(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
135
- url_str = str(request.url)
136
- query_params = parse_qs(urlparse(url_str).query)
137
- user_id = query_params.get('user_id', [None])[0]
138
- print(f"user_id={user_id}")
139
- token = query_params.get('token', [None])[0]
140
- print(f"token={token}")
141
-
142
- print(f"||| token:{token}||| user_id:{user_id}||| profile:{profile}||| user_tokens:{user_tokens}")
143
-
144
- if user_id is None or token is None:
145
- return "# ❌ Invalid link. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) !"
146
-
147
- if int(user_id) not in user_tokens or user_tokens[int(user_id)] != token:
148
- return "# ❌ Invalid or expired link. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) !"
149
-
150
- if profile is None:
151
- return f"# ❌ Not logged in with Hugging Face yet."
152
-
153
- # check if hf_user_name in dataframe:
154
- if profile.username in global_df['hf_user_name'].values:
155
- return (f"# ❌ The HF account {profile.username} is already verified!")
156
-
157
- # check if discord_user_id in dataframe:
158
- altered_member_id = "L" + str(user_id) + "L"
159
- if altered_member_id in global_df['discord_user_id'].values:
160
-
161
- hf_user_name = global_df.loc[global_df['discord_user_id'] == altered_member_id, 'hf_user_name'].iloc[0]
162
-
163
- if pd.isnull(hf_user_name) or hf_user_name == 'n/a':
164
- # empty (no link created yet between discord_user_id and hf_user_name) so we can update
165
- verified_date = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
166
- global_df.loc[global_df['discord_user_id'] == altered_member_id, 'hf_user_name'] = profile.username
167
- global_df.loc[global_df['discord_user_id'] == altered_member_id, 'verified_date'] = verified_date
168
- org_link = "https://huggingface.co/organizations/discord-community/share/wPKRAHYbAlaEaCxUxcqVyaaaeZcYagDvqc"
169
- invite_message = "Click to join our community org on the HF Hub!"
170
- return (f"# βœ… Verification successful! [Discord ID {user_id} <---> {profile.username}] πŸ€—\n{invite_message}\n{org_link} ")
171
- print(f"# βœ… Verification successful! [Discord ID {user_id} <---> {profile.username}] πŸ€—")
172
- else:
173
- return (f"# ❌ The Discord account {user_id} is already verified! To change discord accounts or HF accounts, contact @lunarflu on discord")
174
- print(f"# ❌ The Discord account {user_id} is already verified! To change discord accounts or HF accounts, contact @lunarflu on discord")
175
-
176
- # Remove the token after successful verification
177
- del user_tokens[int(user_id)]
178
- """
179
-
180
-
181
-
182
  def verify_button(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
183
  query_params = parse_qs(urlparse(str(request.url)).query)
184
  user_id = query_params.get('user_id', [None])[0]
@@ -206,7 +132,7 @@ def verify_button(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
206
  else:
207
  print(f"⚠️ {member.name} did not have the pending role. Ignoring.")
208
 
209
- await upgrade_role()
210
  return f"# βœ… Verification successful! Welcome, {profile.username} πŸŽ‰"
211
 
212
 
 
73
  await interaction.response.send_message(message, ephemeral=True)
74
 
75
 
 
 
76
  @bot.event
77
  async def on_ready():
78
  try:
 
79
  print(f'Logged in as {bot.user.name}')
 
 
80
  guild = bot.get_guild(879548962464493619)
81
  await guild.chunk() # get all users into bot cache
82
 
 
94
  print(f"Message with ID 1271145797433557023 not found.")
95
  except discord.HTTPException as e:
96
  print(f"Failed to fetch message with ID 1271145797433557023: {e}")
 
 
 
 
 
 
97
  print("------------------------------------------------------------------------")
98
  except Exception as e:
99
  print(f"on_ready Error: {e}")
100
 
101
 
 
 
 
 
 
 
 
 
 
 
102
  DISCORD_TOKEN = os.environ.get("DISCORD_TOKEN", None)
103
  def run_bot():
104
  bot.run(DISCORD_TOKEN)
105
  threading.Thread(target=run_bot).start()
106
 
107
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  def verify_button(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
109
  query_params = parse_qs(urlparse(str(request.url)).query)
110
  user_id = query_params.get('user_id', [None])[0]
 
132
  else:
133
  print(f"⚠️ {member.name} did not have the pending role. Ignoring.")
134
 
135
+ asyncio.create_task(upgrade_role())
136
  return f"# βœ… Verification successful! Welcome, {profile.username} πŸŽ‰"
137
 
138