lunarflu HF staff commited on
Commit
4f19e81
1 Parent(s): ed9981f

async def remove_huggingfolks():

Browse files
Files changed (1) hide show
  1. app.py +39 -38
app.py CHANGED
@@ -54,6 +54,7 @@ api = HfApi()
54
  #csv_file = 'data.csv'
55
  global_df = pd.DataFrame()
56
  print(type(global_df))
 
57
  data = pd.read_csv("https://docs.google.com/spreadsheets/d/1hQSsIg1Y9WdBF_CdNM1L1rUUREoxKqRTe3_ILo-WK8w/export?format=csv&gid=0")
58
 
59
  @bot.event
@@ -71,6 +72,8 @@ async def on_ready():
71
  global_df = data
72
  print(f"csv successfully retrieved: \n {global_df}")
73
  #data.to_csv(csv_file, index=False)
 
 
74
  print(f"------------------------------------------------------------------------")
75
  except Exception as e:
76
  print(f"on_message Error: {e}")
@@ -123,7 +126,7 @@ processed_users = set()
123
 
124
  async def periodic_api_test(): # needs rewrite, can do same thing and interact with csv -> push to google sheets
125
  try:
126
- await asyncio.sleep(1.1)
127
  column_values_3 = worksheet2.col_values(3)
128
  column_values_8 = worksheet2.col_values(8)
129
 
@@ -158,6 +161,7 @@ async def periodic_api_test(): # needs rewrite, can do same thing and interact w
158
 
159
  async def add_exp(member_id):
160
  try:
 
161
  await asyncio.sleep(0.1)
162
  global global_df
163
 
@@ -262,15 +266,9 @@ async def add_exp(member_id):
262
  verification_link = "https://discord.com/channels/879548962464493619/900125909984624713"
263
  embed.add_field(name="Verify Here:", value=verification_link, inline=True)
264
 
265
-
266
- lunar = bot.get_user(811235357663297546)
267
- await lunar.send(embed=embed)
268
- # just send all levelup messages to me for a few hours
269
-
270
- #Review the leaderboard at <link>
271
- # leaderboard link
272
 
273
-
274
  #You can verify your account to earn 100 points! To verify, do A.
275
 
276
 
@@ -278,7 +276,6 @@ async def add_exp(member_id):
278
  if not member_found:
279
  # if not, create new record
280
  print(f"creating new record for {member}")
281
- #string_member_id = str(member.id)
282
 
283
  xp = 10 # define somewhere else?
284
  member_id = str(member_id)
@@ -287,25 +284,12 @@ async def add_exp(member_id):
287
  row_data = [member_id, member_name, xp, current_level]
288
  global_df.loc[len(global_df.index)] = row_data
289
 
290
- #new_row_df = pd.DataFrame([row_data], columns=global_df.columns)
291
- #updated_df = global_df.append(new_row_df, ignore_index=True) deprecated
292
- #updated_df = pd.concat([global_df, pd.DataFrame([new_row_df])], ignore_index=True)
293
-
294
  # initial role assignment
295
  if current_level == 1:
296
  if lvl1 not in member.roles:
297
  await member.add_roles(lvl1)
298
  print(f"Gave {member} {lvl1}") # can log this better
299
  print(f"------------------------------------------------------------------------")
300
-
301
- """
302
- if member_id == 811235357663297546:
303
- await asyncio.sleep(1.1)
304
- await update_google_sheet()
305
- await asyncio.sleep(1.1)
306
-
307
- """
308
-
309
  except Exception as e:
310
  print(f"add_exp Error: {e}")
311
 
@@ -316,7 +300,7 @@ async def on_message(message):
316
  if message.author.id not in bot_ids: # could change to if author does not have bot role (roleid)
317
  if "!help_xp" not in message.content:
318
  print(f"adding exp from message {message.author}")
319
- await asyncio.sleep(1.1)
320
  await add_exp(message.author.id)
321
  await bot.process_commands(message)
322
  except Exception as e:
@@ -328,22 +312,45 @@ async def on_reaction_add(reaction, user):
328
  try:
329
  if user.id not in bot_ids:
330
  print(f"adding exp from react {user.id}")
331
- await asyncio.sleep(1)
332
  await add_exp(user.id)
333
- await asyncio.sleep(1)
334
  await add_exp(reaction.message.author.id)
335
  except Exception as e:
336
  print(f"on_reaction_add Error: {e}")
337
 
338
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
 
340
- @bot.command(name='update_leaderboard')
341
- async def update_leaderboard(ctx, num_results: int = 10): # needs rewrite
342
  try:
 
343
  if ctx.author.id == 811235357663297546:
344
- await asyncio.sleep(1)
345
  worksheet = gspread_bot.open("levelbot").sheet1
346
-
 
 
 
347
  names_list = worksheet.col_values(2)[1:]
348
  levels_list = worksheet.col_values(4)[1:]
349
  exp_list = worksheet.col_values(3)[1:]
@@ -367,13 +374,7 @@ async def update_leaderboard(ctx, num_results: int = 10): # needs rewrite
367
  top_data_pairs = sorted_data_pairs[:num_results]
368
  """
369
 
370
- # remove huggingfolks
371
- guild = ctx.guild
372
- role = discord.utils.get(guild.roles, id=897376942817419265)
373
- if role is None:
374
- await ctx.send("Role not found.")
375
- return
376
- members_with_role = [member.name for member in guild.members if role in member.roles]
377
  top_results = [r for r in top_results if r[0] not in members_with_role]
378
 
379
  for name, level, xp in top_results:
@@ -392,7 +393,7 @@ async def update_leaderboard(ctx, num_results: int = 10): # needs rewrite
392
  new_table = tabulate(new_leaderboard_data, headers=["Name", "Level", "XP to level up"], tablefmt="plain")
393
  await message.edit(content=f"Updated Leaderboard:\n```\n{new_table}\n```")
394
  except Exception as e:
395
- print(f"on_message Error: {e}")
396
 
397
 
398
  @bot.command(name='xp_help')
 
54
  #csv_file = 'data.csv'
55
  global_df = pd.DataFrame()
56
  print(type(global_df))
57
+ community_global_df = pd.DataFrame()
58
  data = pd.read_csv("https://docs.google.com/spreadsheets/d/1hQSsIg1Y9WdBF_CdNM1L1rUUREoxKqRTe3_ILo-WK8w/export?format=csv&gid=0")
59
 
60
  @bot.event
 
72
  global_df = data
73
  print(f"csv successfully retrieved: \n {global_df}")
74
  #data.to_csv(csv_file, index=False)
75
+
76
+ await remove_huggingfolks()
77
  print(f"------------------------------------------------------------------------")
78
  except Exception as e:
79
  print(f"on_message Error: {e}")
 
126
 
127
  async def periodic_api_test(): # needs rewrite, can do same thing and interact with csv -> push to google sheets
128
  try:
129
+ await asyncio.sleep(0.1)
130
  column_values_3 = worksheet2.col_values(3)
131
  column_values_8 = worksheet2.col_values(8)
132
 
 
161
 
162
  async def add_exp(member_id):
163
  try:
164
+ """Uses member_id to create new record or update old one [member_id_column] ... [member_exp_column]"""
165
  await asyncio.sleep(0.1)
166
  global global_df
167
 
 
266
  verification_link = "https://discord.com/channels/879548962464493619/900125909984624713"
267
  embed.add_field(name="Verify Here:", value=verification_link, inline=True)
268
 
269
+ #lunar = bot.get_user(811235357663297546)
270
+ await member.send(embed=embed)
 
 
 
 
 
271
 
 
272
  #You can verify your account to earn 100 points! To verify, do A.
273
 
274
 
 
276
  if not member_found:
277
  # if not, create new record
278
  print(f"creating new record for {member}")
 
279
 
280
  xp = 10 # define somewhere else?
281
  member_id = str(member_id)
 
284
  row_data = [member_id, member_name, xp, current_level]
285
  global_df.loc[len(global_df.index)] = row_data
286
 
 
 
 
 
287
  # initial role assignment
288
  if current_level == 1:
289
  if lvl1 not in member.roles:
290
  await member.add_roles(lvl1)
291
  print(f"Gave {member} {lvl1}") # can log this better
292
  print(f"------------------------------------------------------------------------")
 
 
 
 
 
 
 
 
 
293
  except Exception as e:
294
  print(f"add_exp Error: {e}")
295
 
 
300
  if message.author.id not in bot_ids: # could change to if author does not have bot role (roleid)
301
  if "!help_xp" not in message.content:
302
  print(f"adding exp from message {message.author}")
303
+ await asyncio.sleep(0.1)
304
  await add_exp(message.author.id)
305
  await bot.process_commands(message)
306
  except Exception as e:
 
312
  try:
313
  if user.id not in bot_ids:
314
  print(f"adding exp from react {user.id}")
315
+ await asyncio.sleep(0.1)
316
  await add_exp(user.id)
317
+ await asyncio.sleep(0.1)
318
  await add_exp(reaction.message.author.id)
319
  except Exception as e:
320
  print(f"on_reaction_add Error: {e}")
321
 
322
 
323
+ # non-huggingfolks data
324
+ async def remove_huggingfolks():
325
+ try:
326
+ # remove huggingfolks
327
+ global community_global_df
328
+
329
+ community_global_df = global_df.copy()
330
+
331
+ guild = bot.get_guild(879548962464493619)
332
+ role = discord.utils.get(guild.roles, id=897376942817419265)
333
+ members_with_role = [member.id for member in guild.members if role in member.roles]
334
+
335
+ for member_id in members_with_role:
336
+ community_global_df = community_global_df[community_global_df.iloc[:, 0] != str(member_id)]
337
+
338
+ print(community_global_df)
339
+
340
+ except Exception as e:
341
+ print(f"remove_huggingfolks Error: {e}")
342
+
343
 
344
+ async def update_leaderboard(): # needs rewrite
 
345
  try:
346
+ # split into clear sections, discord bot only and gspread only
347
  if ctx.author.id == 811235357663297546:
348
+
349
  worksheet = gspread_bot.open("levelbot").sheet1
350
+
351
+ # get from global_df
352
+ # update second global df
353
+ # use both in gradio and discord to present?
354
  names_list = worksheet.col_values(2)[1:]
355
  levels_list = worksheet.col_values(4)[1:]
356
  exp_list = worksheet.col_values(3)[1:]
 
374
  top_data_pairs = sorted_data_pairs[:num_results]
375
  """
376
 
377
+
 
 
 
 
 
 
378
  top_results = [r for r in top_results if r[0] not in members_with_role]
379
 
380
  for name, level, xp in top_results:
 
393
  new_table = tabulate(new_leaderboard_data, headers=["Name", "Level", "XP to level up"], tablefmt="plain")
394
  await message.edit(content=f"Updated Leaderboard:\n```\n{new_table}\n```")
395
  except Exception as e:
396
+ print(f"update_leaderboard Error: {e}")
397
 
398
 
399
  @bot.command(name='xp_help')