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