Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
fix
Browse files
app.py
CHANGED
@@ -53,29 +53,75 @@ async def on_ready():
|
|
53 |
global_df = test_merge
|
54 |
print(f"csv successfully retrieved: \n {global_df}")
|
55 |
|
56 |
-
@tasks.loop(
|
57 |
async def give_verified_roles():
|
58 |
try:
|
|
|
|
|
|
|
59 |
global global_df
|
|
|
|
|
|
|
60 |
guild = bot.get_guild(879548962464493619)
|
|
|
|
|
|
|
61 |
role = guild.get_role(900063512829755413)
|
|
|
|
|
|
|
62 |
org_link = "https://huggingface.co/organizations/discord-community/share/wPKRAHYbAlaEaCxUxcqVyaaaeZcYagDvqc"
|
63 |
invite_message = "Click to join our community org on the HF Hub!"
|
|
|
|
|
|
|
|
|
64 |
await guild.chunk()
|
|
|
|
|
|
|
65 |
for index, row in global_df.iterrows():
|
|
|
|
|
|
|
66 |
hf_user_name = row['hf_user_name']
|
67 |
if pd.notna(hf_user_name) and hf_user_name.lower() != 'n/a':
|
|
|
|
|
|
|
68 |
discord_id = row['discord_user_id'].strip('L')
|
|
|
|
|
|
|
69 |
member = guild.get_member(int(discord_id))
|
70 |
if not member:
|
|
|
71 |
continue
|
|
|
|
|
|
|
72 |
if role not in member.roles:
|
|
|
73 |
await member.add_roles(role)
|
|
|
|
|
|
|
74 |
lunar = bot.get_user(811235357663297546)
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
except Exception as e:
|
78 |
-
print(f"Error: {e}")
|
|
|
79 |
|
80 |
|
81 |
# runs discord bot in thread = helps avoid blocking calls
|
|
|
53 |
global_df = test_merge
|
54 |
print(f"csv successfully retrieved: \n {global_df}")
|
55 |
|
56 |
+
@tasks.loop(minutes=1)
|
57 |
async def give_verified_roles():
|
58 |
try:
|
59 |
+
print("Starting the give_verified_roles task...")
|
60 |
+
|
61 |
+
# Access the global dataframe
|
62 |
global global_df
|
63 |
+
print(f"Dataframe loaded with {len(global_df)} rows.")
|
64 |
+
|
65 |
+
# Get the guild (server)
|
66 |
guild = bot.get_guild(879548962464493619)
|
67 |
+
print(f"Guild found: {guild}")
|
68 |
+
|
69 |
+
# Get the role
|
70 |
role = guild.get_role(900063512829755413)
|
71 |
+
print(f"Role found: {role}")
|
72 |
+
|
73 |
+
# Define the invite message
|
74 |
org_link = "https://huggingface.co/organizations/discord-community/share/wPKRAHYbAlaEaCxUxcqVyaaaeZcYagDvqc"
|
75 |
invite_message = "Click to join our community org on the HF Hub!"
|
76 |
+
print("Invite message and link prepared.")
|
77 |
+
|
78 |
+
# Cache members in the guild
|
79 |
+
print("Chunking guild members to cache...")
|
80 |
await guild.chunk()
|
81 |
+
print("Guild members chunked.")
|
82 |
+
|
83 |
+
# Iterate over the dataframe rows
|
84 |
for index, row in global_df.iterrows():
|
85 |
+
print(f"Processing row {index}: {row}")
|
86 |
+
|
87 |
+
# Extract Hugging Face username
|
88 |
hf_user_name = row['hf_user_name']
|
89 |
if pd.notna(hf_user_name) and hf_user_name.lower() != 'n/a':
|
90 |
+
print(f"Valid HF username found: {hf_user_name}")
|
91 |
+
|
92 |
+
# Extract and clean Discord ID
|
93 |
discord_id = row['discord_user_id'].strip('L')
|
94 |
+
print(f"Cleaned Discord ID: {discord_id}")
|
95 |
+
|
96 |
+
# Get the guild member
|
97 |
member = guild.get_member(int(discord_id))
|
98 |
if not member:
|
99 |
+
print(f"Member with Discord ID {discord_id} not found.")
|
100 |
continue
|
101 |
+
print(f"Member found: {member}")
|
102 |
+
|
103 |
+
# Check if the member already has the role
|
104 |
if role not in member.roles:
|
105 |
+
print(f"Adding role to member: {member}")
|
106 |
await member.add_roles(role)
|
107 |
+
print(f"Role added to member: {member}")
|
108 |
+
|
109 |
+
# Notify Lunar
|
110 |
lunar = bot.get_user(811235357663297546)
|
111 |
+
if lunar:
|
112 |
+
print(f"Notifying Lunar about verification for {member}")
|
113 |
+
await lunar.send(f"Verified role given to {member}!")
|
114 |
+
|
115 |
+
# Notify the member
|
116 |
+
print(f"Sending success message to {member}")
|
117 |
+
await member.send(
|
118 |
+
f"Verification successful! [{member} <---> {row['discord_user_name']}] \n🤗 {org_link} {invite_message}"
|
119 |
+
)
|
120 |
+
|
121 |
+
print("Finished processing all rows.")
|
122 |
except Exception as e:
|
123 |
+
print(f"Error encountered: {e}")
|
124 |
+
|
125 |
|
126 |
|
127 |
# runs discord bot in thread = helps avoid blocking calls
|