Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -219,154 +219,162 @@ async def add_exp(member_id):
|
|
219 |
|
220 |
member_found = False
|
221 |
|
222 |
-
|
223 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
224 |
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
236 |
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
#
|
269 |
-
#
|
270 |
-
# do
|
271 |
-
copy_df = global_df.copy()
|
272 |
-
copy_df['discord_user_id'] = copy_df['discord_user_id'].str.strip('L').astype(str)
|
273 |
-
copy_df['discord_exp'] = copy_df['discord_exp'].str.strip('L').astype(int)
|
274 |
-
row = copy_df[copy_df['discord_user_id'] == str(member_id)]
|
275 |
-
print(f"Row found for {member_id}!")
|
276 |
-
target_exp = row['discord_exp'].values[0]
|
277 |
-
rank = (copy_df['discord_exp'] > target_exp).sum() + 1
|
278 |
-
print(f"The rank for discord_id {member_id} based on discord_exp is: {rank}")
|
279 |
-
except Exception as e:
|
280 |
-
print(f"Discord ID {member_id} not found in the DataFrame.")
|
281 |
-
rank = "🤗"
|
282 |
-
|
283 |
-
# temporary fix: remove ~100 exp when not verified, send embed on "levelup" prompting to verify
|
284 |
-
# if level 3 -> then send embed, remove some exp
|
285 |
-
if current_level >= 3: # could change to 4 maybe
|
286 |
-
if verified_role not in member.roles:
|
287 |
-
if new_xp % 50 == 0: # staggers messages so we don't send one every time exp is earned
|
288 |
-
# claim exp (-30 for level 3, but +100 as bonus exp. This scales infinitely until the member verifies,
|
289 |
-
# so they can continue earning exp, it just won't translate to levels and the leaderboard.
|
290 |
-
# This way they can claim at any time and get a big boost in levels!
|
291 |
-
claim_exp = new_xp + 70
|
292 |
-
|
293 |
-
# send embed
|
294 |
-
embed = Embed(color=Color.red())
|
295 |
-
embed.set_author(name=f"{member}", icon_url=member.avatar.url if member.avatar else bot.user.avatar.url)
|
296 |
-
embed.title = f"⚠️Your account is not Verified! Unable to level up `{current_level-1}` -> `{current_level}` ❌"
|
297 |
-
msg = f'🤗 Hey {member}! You can continue leveling up in the Hugging Face Discord server by Verifying your account, and claim `{claim_exp}` bonus exp points!'
|
298 |
-
embed.description = f"{msg}"
|
299 |
-
verification_link = "https://discord.com/channels/879548962464493619/900125909984624713"
|
300 |
-
embed.add_field(name="Verify Here:", value=verification_link, inline=True)
|
301 |
-
u_1 = f"👑 Earn exp for activity on Discord and HF and climb the leaderboard !"
|
302 |
-
u_2 = f"🌎 Feature your content in weekly news and increase its visibility!"
|
303 |
-
u_3 = f"🚀 Early access to Beta features!"
|
304 |
-
u_4 = f"🛡️ Secure your progress, and restore if needed!"
|
305 |
-
embed.add_field(name="You can Unlock:", value=f"{u_1}\n{u_2}\n{u_3}\n{u_4}", inline=True)
|
306 |
-
embed.set_image(url='https://cdn.discordapp.com/attachments/1150399343912833024/1205537451242688573/download_1.png?ex=65d8bb3e&is=65c6463e&hm=042fe7dd3521887db0bd48eeb846de1cc7c75194f9e95215c23512ff61ea3475&')
|
307 |
-
|
308 |
-
lunar = bot.get_user(811235357663297546)
|
309 |
-
await member.send(embed=embed)
|
310 |
-
print(f"Sent verification cap embed to {member}")
|
311 |
-
return
|
312 |
-
|
313 |
|
314 |
-
|
315 |
-
|
316 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
317 |
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
# can use ^ to track changes in leaderboard ranking and display in levelup message when climbing
|
336 |
-
# (green red arrow thingies)
|
337 |
-
# could also pull ranks above and below yourself (if they exist, i.e.)
|
338 |
-
# 1 nateraw
|
339 |
-
# 2 [you are here]
|
340 |
-
# 3 osanseviero
|
341 |
-
# also, ahead by how much exp, how many levels maybe
|
342 |
-
msg3 = "- Posting\n- Reacting / being reacted to\n- Being active on the Hugging Face Hub (verify to link your Hub + Discord accounts!)"
|
343 |
-
embed.add_field(name="How to Level Up:", value=msg3, inline=True)
|
344 |
-
verification_link = "https://discord.com/channels/879548962464493619/900125909984624713"
|
345 |
-
embed.add_field(name="Verify Here:", value=verification_link, inline=True)
|
346 |
-
|
347 |
-
lunar = bot.get_user(811235357663297546)
|
348 |
-
await member.send(embed=embed)
|
349 |
-
print(f"Sent levelup embed to {member}")
|
350 |
-
#You can verify your account to earn 100 points! To verify, do A.
|
351 |
-
|
352 |
-
|
353 |
print(f"------------------------------------------------------------------------")
|
354 |
-
if not member_found:
|
355 |
-
# if not, create new record
|
356 |
-
print(f"Creating new record for {member}")
|
357 |
-
|
358 |
-
xp = 10 # define somewhere else?
|
359 |
-
current_level = calculate_level(xp)
|
360 |
-
xp = str(xp)
|
361 |
-
if not xp.startswith("L") and not xp.endswith("L"):
|
362 |
-
xp = f"L" + str(xp) + f"L"
|
363 |
-
member_id = str(member_id)
|
364 |
-
if not member_id.startswith("L") and not member_id.endswith("L"):
|
365 |
-
member_id = f"L" + str(member_id) + f"L"
|
366 |
-
member_name = str(member.name)
|
367 |
-
row_data = [member_id, member_name, xp, current_level]
|
368 |
-
global_df.loc[len(global_df.index)] = row_data
|
369 |
-
print(f"------------------------------------------------------------------------")
|
370 |
except Exception as e:
|
371 |
print(f"add_exp Error: {e}")
|
372 |
|
|
|
219 |
|
220 |
member_found = False
|
221 |
|
222 |
+
|
223 |
+
if member_id == 811235357663297546:
|
224 |
+
print("test1")
|
225 |
+
# discord_user_id column
|
226 |
+
for index, cell_value in global_df.iloc[:, 0].items():
|
227 |
+
print("test2")
|
228 |
+
# remove L (read, so no need to replace)
|
229 |
+
# tldr; set_as_dataframe forces scientific notation which corrupts discord_user_id data.
|
230 |
+
# set_as_dataframe is still highly efficient (1 API call), so we format numerical data as strings,
|
231 |
+
# which results in efficient google sheet updating + data integrity
|
232 |
+
if cell_value.startswith("L") and cell_value.endswith("L"):
|
233 |
+
print("test3")
|
234 |
+
cell_value_clipped = cell_value[1:-1]
|
235 |
+
# cell_value_clipped = 1234567890
|
236 |
+
if cell_value_clipped == str(member_id): # is this needed?
|
237 |
+
print("test4")
|
238 |
+
# if found, update that row...
|
239 |
+
member_found = True
|
240 |
+
print(f"Record for {member} found at row {index + 1}, column 1")
|
241 |
+
|
242 |
+
# increment the old experience value (better not to replace outright)
|
243 |
+
old_xp = global_df.loc[index, 'discord_exp']
|
244 |
+
# remove L (write, so we replace)
|
245 |
+
old_xp = str(old_xp)
|
246 |
+
if old_xp.startswith("L") and old_xp.endswith("L"):
|
247 |
+
old_xp = old_xp[1:-1]
|
248 |
+
# str -> int temporarily
|
249 |
+
new_xp = int(old_xp) + XP_PER_MESSAGE
|
250 |
+
# check + convert back to string + google sheet proofing
|
251 |
+
current_level = calculate_level(new_xp)
|
252 |
+
new_xp = str(new_xp)
|
253 |
+
if not new_xp.startswith("L") and not new_xp.endswith("L"):
|
254 |
+
new_xp = f"L" + str(new_xp) + f"L"
|
255 |
+
|
256 |
+
# add back to dataframe in memory after checking redundantly;
|
257 |
+
if new_xp.startswith("L") and new_xp.endswith("L"):
|
258 |
+
print("test5")
|
259 |
+
global_df.loc[index, 'discord_exp'] = new_xp # do not change column name
|
260 |
+
print(f"Record for {member} updated from {old_xp} to {global_df.loc[index, 'discord_exp']} (+{XP_PER_MESSAGE}) ")
|
261 |
+
|
262 |
+
# level up
|
263 |
+
|
264 |
+
verified_role = guild.get_role(900063512829755413)
|
265 |
+
|
266 |
+
print(f"Current_level for {member}: {current_level}")
|
267 |
+
if current_level >= 2 and current_level <=30:
|
268 |
+
print("test6")
|
269 |
+
current_role = lvls[current_level]
|
270 |
+
if current_role not in member.roles: # if we leveled up
|
271 |
|
272 |
+
# finding leaderboard rank + excluding huggingfolks
|
273 |
+
try:
|
274 |
+
# cell_value = L1234567890L
|
275 |
+
# make copy
|
276 |
+
# remove L
|
277 |
+
# do calculations
|
278 |
+
copy_df = global_df.copy()
|
279 |
+
copy_df['discord_user_id'] = copy_df['discord_user_id'].str.strip('L').astype(str)
|
280 |
+
copy_df['discord_exp'] = copy_df['discord_exp'].str.strip('L').astype(int)
|
281 |
+
row = copy_df[copy_df['discord_user_id'] == str(member_id)]
|
282 |
+
print(f"Row found for {member_id}!")
|
283 |
+
target_exp = row['discord_exp'].values[0]
|
284 |
+
rank = (copy_df['discord_exp'] > target_exp).sum() + 1
|
285 |
+
print(f"The rank for discord_id {member_id} based on discord_exp is: {rank}")
|
286 |
+
except Exception as e:
|
287 |
+
print(f"Discord ID {member_id} not found in the DataFrame.")
|
288 |
+
rank = "🤗"
|
289 |
|
290 |
+
# temporary fix: remove ~100 exp when not verified, send embed on "levelup" prompting to verify
|
291 |
+
# if level 3 -> then send embed, remove some exp
|
292 |
+
if current_level >= 3: # could change to 4 maybe
|
293 |
+
if verified_role not in member.roles:
|
294 |
+
if new_xp % 50 == 0: # staggers messages so we don't send one every time exp is earned
|
295 |
+
# claim exp (-30 for level 3, but +100 as bonus exp. This scales infinitely until the member verifies,
|
296 |
+
# so they can continue earning exp, it just won't translate to levels and the leaderboard.
|
297 |
+
# This way they can claim at any time and get a big boost in levels!
|
298 |
+
claim_exp = new_xp + 70
|
299 |
+
|
300 |
+
# send embed
|
301 |
+
embed = Embed(color=Color.red())
|
302 |
+
embed.set_author(name=f"{member}", icon_url=member.avatar.url if member.avatar else bot.user.avatar.url)
|
303 |
+
embed.title = f"⚠️Your account is not Verified! Unable to level up `{current_level-1}` -> `{current_level}` ❌"
|
304 |
+
msg = f'🤗 Hey {member}! You can continue leveling up in the Hugging Face Discord server by Verifying your account, and claim `{claim_exp}` bonus exp points!'
|
305 |
+
embed.description = f"{msg}"
|
306 |
+
verification_link = "https://discord.com/channels/879548962464493619/900125909984624713"
|
307 |
+
embed.add_field(name="Verify Here:", value=verification_link, inline=True)
|
308 |
+
u_1 = f"👑 Earn exp for activity on Discord and HF and climb the leaderboard !"
|
309 |
+
u_2 = f"🌎 Feature your content in weekly news and increase its visibility!"
|
310 |
+
u_3 = f"🚀 Early access to Beta features!"
|
311 |
+
u_4 = f"🛡️ Secure your progress, and restore if needed!"
|
312 |
+
embed.add_field(name="You can Unlock:", value=f"{u_1}\n{u_2}\n{u_3}\n{u_4}", inline=True)
|
313 |
+
embed.set_image(url='https://cdn.discordapp.com/attachments/1150399343912833024/1205537451242688573/download_1.png?ex=65d8bb3e&is=65c6463e&hm=042fe7dd3521887db0bd48eeb846de1cc7c75194f9e95215c23512ff61ea3475&')
|
314 |
+
|
315 |
+
lunar = bot.get_user(811235357663297546)
|
316 |
+
await member.send(embed=embed)
|
317 |
+
print(f"Sent verification cap embed to {member}")
|
318 |
+
return
|
319 |
+
|
320 |
+
|
321 |
+
# increment the old level value (better to replace outright)
|
322 |
+
# only increment level column if you are lvl2 or 3+ with verified role
|
323 |
+
global_df.loc[index, 'discord_level'] = current_level # do not change column name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
|
325 |
+
await member.add_roles(current_role)
|
326 |
+
print(f"Level Up! Gave {member} {current_role}")
|
327 |
+
await member.remove_roles(lvls[current_level-1])
|
328 |
+
print(f"Removed {lvls[current_level-1]} from {member}")
|
329 |
+
#print(f"{member} Level up! {current_level-1} -> {current_level}!")
|
330 |
+
if current_role in member.roles: # needs update; reference exp reward for verification
|
331 |
+
#await member.send(f"Level up! {current_level-1} -> {current_level}!")
|
332 |
+
#if member_id == 811235357663297546:
|
333 |
+
|
334 |
+
|
335 |
+
# send embed
|
336 |
+
embed = Embed(color=Color.blue())
|
337 |
+
embed.set_author(name=f"{member}", icon_url=member.avatar.url if member.avatar else bot.user.avatar.url)
|
338 |
+
embed.title = f"Level Up! `{current_level-1}` -> `{current_level}`"
|
339 |
+
msg = f'🤗 Congrats {member}! You just leveled up in the Hugging Face Discord server'
|
340 |
+
embed.description = f"{msg}."
|
341 |
+
embed.add_field(name="Leaderboard Ranking:", value=f"👑 **{rank}**\n\nhttps://discord.com/channels/879548962464493619/1197143964994773023", inline=True)
|
342 |
+
# can use ^ to track changes in leaderboard ranking and display in levelup message when climbing
|
343 |
+
# (green red arrow thingies)
|
344 |
+
# could also pull ranks above and below yourself (if they exist, i.e.)
|
345 |
+
# 1 nateraw
|
346 |
+
# 2 [you are here]
|
347 |
+
# 3 osanseviero
|
348 |
+
# also, ahead by how much exp, how many levels maybe
|
349 |
+
msg3 = "- Posting\n- Reacting / being reacted to\n- Being active on the Hugging Face Hub (verify to link your Hub + Discord accounts!)"
|
350 |
+
embed.add_field(name="How to Level Up:", value=msg3, inline=True)
|
351 |
+
verification_link = "https://discord.com/channels/879548962464493619/900125909984624713"
|
352 |
+
embed.add_field(name="Verify Here:", value=verification_link, inline=True)
|
353 |
+
|
354 |
+
lunar = bot.get_user(811235357663297546)
|
355 |
+
await member.send(embed=embed)
|
356 |
+
print(f"Sent levelup embed to {member}")
|
357 |
+
#You can verify your account to earn 100 points! To verify, do A.
|
358 |
+
|
359 |
|
360 |
+
print(f"------------------------------------------------------------------------")
|
361 |
+
if not member_found:
|
362 |
+
print("test7")
|
363 |
+
# if not, create new record
|
364 |
+
print(f"Creating new record for {member}")
|
365 |
+
|
366 |
+
xp = 10 # define somewhere else?
|
367 |
+
current_level = calculate_level(xp)
|
368 |
+
xp = str(xp)
|
369 |
+
if not xp.startswith("L") and not xp.endswith("L"):
|
370 |
+
xp = f"L" + str(xp) + f"L"
|
371 |
+
member_id = str(member_id)
|
372 |
+
if not member_id.startswith("L") and not member_id.endswith("L"):
|
373 |
+
member_id = f"L" + str(member_id) + f"L"
|
374 |
+
member_name = str(member.name)
|
375 |
+
row_data = [member_id, member_name, xp, current_level]
|
376 |
+
global_df.loc[len(global_df.index)] = row_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
377 |
print(f"------------------------------------------------------------------------")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
378 |
except Exception as e:
|
379 |
print(f"add_exp Error: {e}")
|
380 |
|