lunarflu HF staff commited on
Commit
7fe3a13
·
verified ·
1 Parent(s): af299cb

create new record for members on_member_join (not just when they send messages or react)

Browse files
Files changed (1) hide show
  1. app.py +42 -1
app.py CHANGED
@@ -672,7 +672,48 @@ def get_data2():
672
  display_df = pd.DataFrame(display_data)
673
  return display_df
674
  except Exception as e:
675
- print(f"get_data2 Error: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
676
 
677
 
678
  #-------------------------------------------------------------------------------------------------------------------------------
 
672
  display_df = pd.DataFrame(display_data)
673
  return display_df
674
  except Exception as e:
675
+ print(f"get_data2 Error: {e}")
676
+
677
+
678
+ @bot.event
679
+ async def on_member_join(member):
680
+ try:
681
+ # Check if the member already has a record
682
+ global global_df
683
+ member_id = f"L{member.id}L" # Ensure consistent formatting with the database
684
+ if member_id not in global_df['discord_user_id'].values:
685
+ # Create a new row for the user
686
+ print(f"Creating new record for {member}")
687
+ xp = 0 # Start with zero XP
688
+ current_level = calculate_level(xp)
689
+ xp = f"L{xp}L"
690
+ member_name = member.name
691
+ hf_user_name = "n/a"
692
+ hub_exp = "L0L"
693
+ total_exp = xp
694
+ verified_date = "n/a"
695
+
696
+ # Initialize additional columns for the new row
697
+ likes = 0
698
+ models = 0
699
+ datasets = 0
700
+ spaces = 0
701
+ discussions = 0
702
+ papers = 0
703
+ upvotes = 0
704
+
705
+ row_data = [
706
+ member_id, member_name, xp, current_level, hf_user_name, hub_exp,
707
+ total_exp, verified_date, likes, models, datasets, spaces, discussions,
708
+ papers, upvotes
709
+ ]
710
+ global_df.loc[len(global_df.index)] = row_data # Add the new row
711
+
712
+ print(f"Added new user {member.name} with ID {member.id} to the database.")
713
+ else:
714
+ print(f"User {member.name} with ID {member.id} already exists in the database.")
715
+ except Exception as e:
716
+ print(f"Error adding new member {member}: {e}")
717
 
718
 
719
  #-------------------------------------------------------------------------------------------------------------------------------