Spaces:
Runtime error
Runtime error
xp to level up test
Browse files
app.py
CHANGED
@@ -234,19 +234,30 @@ async def on_reaction_add(reaction, user):
|
|
234 |
|
235 |
|
236 |
@bot.command(name='update_leaderboard')
|
237 |
-
async def update_leaderboard(ctx,
|
238 |
worksheet = gspread_bot.open("levelbot").sheet1
|
239 |
|
240 |
names_list = worksheet.col_values(2)[1:]
|
241 |
levels_list = worksheet.col_values(4)[1:]
|
|
|
242 |
channel = bot.get_channel(1197143964994773023)
|
243 |
message = await channel.fetch_message(1197148293164187678)
|
244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
# get position, then find that value in updated_names_list
|
246 |
levels_list = list(map(int, levels_list))
|
247 |
data_pairs = list(zip(names_list, levels_list))
|
248 |
sorted_data_pairs = sorted(data_pairs, key=lambda x: x[1], reverse=True)
|
249 |
-
top_data_pairs = sorted_data_pairs[:
|
|
|
|
|
250 |
|
251 |
# remove huggingfolks
|
252 |
guild = ctx.guild
|
@@ -255,14 +266,21 @@ async def update_leaderboard(ctx, num_pairs: int = 10):
|
|
255 |
await ctx.send("Role not found.")
|
256 |
return
|
257 |
members_with_role = [member.name for member in guild.members if role in member.roles]
|
258 |
-
|
259 |
|
260 |
-
for name, level in
|
261 |
-
print(f"Name: {name}, Level: {level}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
262 |
|
263 |
# put into message / leaderboard
|
264 |
-
new_leaderboard_data = [(
|
265 |
-
new_table = tabulate(new_leaderboard_data, headers=["Name", "Level"], tablefmt="plain")
|
266 |
await message.edit(content=f"Updated Leaderboard:\n```\n{new_table}\n```")
|
267 |
|
268 |
|
|
|
234 |
|
235 |
|
236 |
@bot.command(name='update_leaderboard')
|
237 |
+
async def update_leaderboard(ctx, num_results: int = 10):
|
238 |
worksheet = gspread_bot.open("levelbot").sheet1
|
239 |
|
240 |
names_list = worksheet.col_values(2)[1:]
|
241 |
levels_list = worksheet.col_values(4)[1:]
|
242 |
+
exp_list = worksheet.col_values(3)[1:]
|
243 |
channel = bot.get_channel(1197143964994773023)
|
244 |
message = await channel.fetch_message(1197148293164187678)
|
245 |
|
246 |
+
|
247 |
+
# for 3 lists
|
248 |
+
combined_list = [list(sublist) for sublist in zip(names_list, levels_list, exp_list)]
|
249 |
+
combined_list = sorted(combined_list, key=lambda x: x[1], reverse=True)
|
250 |
+
combined_list = [[name, int(level), int(exp)] for name, level, exp in combined_list]
|
251 |
+
top_results = combined_list[:num_results]
|
252 |
+
|
253 |
+
"""
|
254 |
# get position, then find that value in updated_names_list
|
255 |
levels_list = list(map(int, levels_list))
|
256 |
data_pairs = list(zip(names_list, levels_list))
|
257 |
sorted_data_pairs = sorted(data_pairs, key=lambda x: x[1], reverse=True)
|
258 |
+
top_data_pairs = sorted_data_pairs[:num_results]
|
259 |
+
"""
|
260 |
+
|
261 |
|
262 |
# remove huggingfolks
|
263 |
guild = ctx.guild
|
|
|
266 |
await ctx.send("Role not found.")
|
267 |
return
|
268 |
members_with_role = [member.name for member in guild.members if role in member.roles]
|
269 |
+
top_results = [r for r in top_results if r[0] not in members_with_role]
|
270 |
|
271 |
+
for name, level in top_results:
|
272 |
+
print(f"Name: {name}, Level: {level}, Exp: {exp}")
|
273 |
+
|
274 |
+
|
275 |
+
def xp_required_to_next_level(current_level, current_xp):
|
276 |
+
level_ceiling_xp = calculate_xp(current_level+1)
|
277 |
+
xp_to_level_up = level_ceiling_xp - current_xp
|
278 |
+
return max(xp_tp_level_up)
|
279 |
+
|
280 |
|
281 |
# put into message / leaderboard
|
282 |
+
new_leaderboard_data = [(name, level, str(xp_required_to_next_level(int(level), int(xp)))) for name, level, xp in top_results]
|
283 |
+
new_table = tabulate(new_leaderboard_data, headers=["Name", "Level", "XP to level up"], tablefmt="plain")
|
284 |
await message.edit(content=f"Updated Leaderboard:\n```\n{new_table}\n```")
|
285 |
|
286 |
|