Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
test
Browse files
app.py
CHANGED
@@ -239,17 +239,7 @@ async def add_exp(member_id):
|
|
239 |
# member_name = string
|
240 |
# discord_user_id = string
|
241 |
|
242 |
-
member_found = False
|
243 |
-
|
244 |
-
if member_id == 811235357663297546:
|
245 |
-
for member in guild.members:
|
246 |
-
current_level_roles = [role for level, role in lvls.items() if role in member.roles]
|
247 |
-
if len(current_level_roles) > 1:
|
248 |
-
print(f"{member.name} has multiple level roles:")
|
249 |
-
for role in current_level_roles:
|
250 |
-
print(f"- {role.name}")
|
251 |
-
|
252 |
-
|
253 |
|
254 |
print("test1")
|
255 |
# discord_user_id column
|
@@ -341,22 +331,16 @@ async def add_exp(member_id):
|
|
341 |
# make copy
|
342 |
# remove L
|
343 |
# do calculations
|
344 |
-
print("
|
345 |
copy_df = global_df.copy()
|
346 |
-
print("test9")
|
347 |
copy_df['discord_user_id'] = copy_df['discord_user_id'].str.strip('L').astype(str)
|
348 |
-
print("test10")
|
349 |
copy_df['total_exp'] = copy_df['total_exp'].str.strip('L').astype(int)
|
350 |
-
print("test11")
|
351 |
row = copy_df[copy_df['discord_user_id'] == str(member_id)]
|
352 |
-
print("test12")
|
353 |
-
print(f"Row found for {member_id}!")
|
354 |
target_exp = row['total_exp'].values[0]
|
355 |
-
print("test13")
|
356 |
rank = (copy_df['total_exp'] > target_exp).sum() + 1
|
357 |
-
print(f"The rank for
|
358 |
except Exception as e:
|
359 |
-
print(f"Discord ID {member_id} not found in the DataFrame.")
|
360 |
rank = "π€"
|
361 |
|
362 |
# temporary fix: remove ~100 exp when not verified, send embed on "levelup" prompting to verify
|
@@ -404,10 +388,10 @@ async def add_exp(member_id):
|
|
404 |
|
405 |
# remove all level roles then add new role
|
406 |
current_level_roles = [role for level, role in lvls.items() if role in member.roles]
|
407 |
-
print(current_level_roles)
|
408 |
-
for
|
409 |
-
await member.remove_roles(
|
410 |
-
print(f"Removed {
|
411 |
await member.add_roles(current_role)
|
412 |
print(f"Level Up! Gave {member} {current_role}")
|
413 |
|
@@ -421,7 +405,7 @@ async def add_exp(member_id):
|
|
421 |
# send embed
|
422 |
embed = Embed(color=Color.blue())
|
423 |
embed.set_author(name=f"{member}", icon_url=member.avatar.url if member.avatar else bot.user.avatar.url)
|
424 |
-
embed.title = f"Level Up! `{
|
425 |
msg = f'π€ Congrats {member}! You just leveled up in the Hugging Face Discord server'
|
426 |
embed.description = f"{msg}."
|
427 |
embed.add_field(name="Leaderboard Ranking:", value=f"π **{rank}**\n\nhttps://discord.com/channels/879548962464493619/1197143964994773023", inline=True)
|
@@ -446,7 +430,6 @@ async def add_exp(member_id):
|
|
446 |
|
447 |
print(f"------------------------------------------------------------------------")
|
448 |
if not member_found:
|
449 |
-
print("test7")
|
450 |
# if not, create new record
|
451 |
print(f"Creating new record for {member}")
|
452 |
|
|
|
239 |
# member_name = string
|
240 |
# discord_user_id = string
|
241 |
|
242 |
+
member_found = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
243 |
|
244 |
print("test1")
|
245 |
# discord_user_id column
|
|
|
331 |
# make copy
|
332 |
# remove L
|
333 |
# do calculations
|
334 |
+
print("Calculating rank...")
|
335 |
copy_df = global_df.copy()
|
|
|
336 |
copy_df['discord_user_id'] = copy_df['discord_user_id'].str.strip('L').astype(str)
|
|
|
337 |
copy_df['total_exp'] = copy_df['total_exp'].str.strip('L').astype(int)
|
|
|
338 |
row = copy_df[copy_df['discord_user_id'] == str(member_id)]
|
|
|
|
|
339 |
target_exp = row['total_exp'].values[0]
|
|
|
340 |
rank = (copy_df['total_exp'] > target_exp).sum() + 1
|
341 |
+
print(f"The rank for {member} based on total_exp is: {rank}")
|
342 |
except Exception as e:
|
343 |
+
print(f"Discord ID {member} {member_id} not found in the DataFrame.")
|
344 |
rank = "π€"
|
345 |
|
346 |
# temporary fix: remove ~100 exp when not verified, send embed on "levelup" prompting to verify
|
|
|
388 |
|
389 |
# remove all level roles then add new role
|
390 |
current_level_roles = [role for level, role in lvls.items() if role in member.roles]
|
391 |
+
print(f"current_level_roles for {member}: {current_level_roles}")
|
392 |
+
for removable_role in current_level_roles:
|
393 |
+
await member.remove_roles(removable_role)
|
394 |
+
print(f"Removed {removable_role} from {member}")
|
395 |
await member.add_roles(current_role)
|
396 |
print(f"Level Up! Gave {member} {current_role}")
|
397 |
|
|
|
405 |
# send embed
|
406 |
embed = Embed(color=Color.blue())
|
407 |
embed.set_author(name=f"{member}", icon_url=member.avatar.url if member.avatar else bot.user.avatar.url)
|
408 |
+
embed.title = f"Level Up! `{removable_role.name}` -> `{current_level}`"
|
409 |
msg = f'π€ Congrats {member}! You just leveled up in the Hugging Face Discord server'
|
410 |
embed.description = f"{msg}."
|
411 |
embed.add_field(name="Leaderboard Ranking:", value=f"π **{rank}**\n\nhttps://discord.com/channels/879548962464493619/1197143964994773023", inline=True)
|
|
|
430 |
|
431 |
print(f"------------------------------------------------------------------------")
|
432 |
if not member_found:
|
|
|
433 |
# if not, create new record
|
434 |
print(f"Creating new record for {member}")
|
435 |
|