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