Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
re-enable verify button; test async role assignment
Browse files
app.py
CHANGED
@@ -104,7 +104,6 @@ async def on_ready():
|
|
104 |
print(f"XP_PER_MESSAGE: {XP_PER_MESSAGE}")
|
105 |
|
106 |
|
107 |
-
"""
|
108 |
channel = bot.get_channel(900125909984624713)
|
109 |
if channel:
|
110 |
try:
|
@@ -119,10 +118,7 @@ async def on_ready():
|
|
119 |
print(f"Message with ID 1271145797433557023 not found.")
|
120 |
except discord.HTTPException as e:
|
121 |
print(f"Failed to fetch message with ID 1271145797433557023: {e}")
|
122 |
-
|
123 |
-
"""
|
124 |
-
|
125 |
-
|
126 |
|
127 |
"""import data from google sheets -> HF Space df (doesn't make API call this way, as it's read-only)"""
|
128 |
global_df = test_merge
|
@@ -216,12 +212,35 @@ def update_hub_stats():
|
|
216 |
print("------------------------------------------------------------------------")
|
217 |
print(f"Hub stats successfully updated at {timestamp}! \n{global_df}")
|
218 |
print("------------------------------------------------------------------------")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
scheduler
|
223 |
-
|
|
|
|
|
|
|
|
|
|
|
224 |
scheduler.start()
|
|
|
225 |
|
226 |
|
227 |
def calculate_level(xp):
|
|
|
104 |
print(f"XP_PER_MESSAGE: {XP_PER_MESSAGE}")
|
105 |
|
106 |
|
|
|
107 |
channel = bot.get_channel(900125909984624713)
|
108 |
if channel:
|
109 |
try:
|
|
|
118 |
print(f"Message with ID 1271145797433557023 not found.")
|
119 |
except discord.HTTPException as e:
|
120 |
print(f"Failed to fetch message with ID 1271145797433557023: {e}")
|
121 |
+
|
|
|
|
|
|
|
122 |
|
123 |
"""import data from google sheets -> HF Space df (doesn't make API call this way, as it's read-only)"""
|
124 |
global_df = test_merge
|
|
|
212 |
print("------------------------------------------------------------------------")
|
213 |
print(f"Hub stats successfully updated at {timestamp}! \n{global_df}")
|
214 |
print("------------------------------------------------------------------------")
|
215 |
+
|
216 |
+
|
217 |
+
async def give_verified_roles():
|
218 |
+
global global_df
|
219 |
+
for index, row in global_df.iterrows():
|
220 |
+
hf_user_name = row['hf_user_name']
|
221 |
+
if pd.notna(hf_user_name) and hf_user_name.lower() != 'n/a':
|
222 |
+
discord_id = row['discord_id'].strip('L')
|
223 |
+
|
224 |
+
guild = bot.get_guild(879548962464493619)
|
225 |
+
member = guild.get_member(discord_id)
|
226 |
+
role = guild.get_role(900063512829755413)
|
227 |
+
if role not in member.roles:
|
228 |
+
await member.add_roles(role)
|
229 |
+
lunar = bot.get_user(811235357663297546)
|
230 |
+
await lunar.send(f"Verified role given to {member}!")
|
231 |
+
|
232 |
|
233 |
+
thread_pool_executor = ThreadPoolExecutor(max_workers=2)
|
234 |
+
asyncio_executor = AsyncIOExecutor()
|
235 |
+
scheduler = BackgroundScheduler(executors={
|
236 |
+
'default': thread_pool_executor,
|
237 |
+
'asyncio': asyncio_executor
|
238 |
+
})
|
239 |
+
scheduler.add_job(update_google_sheet, trigger='interval', minutes=1, max_instances=2, executor='default')
|
240 |
+
scheduler.add_job(update_hub_stats, trigger='interval', minutes=1.5, max_instances=2, executor='default')
|
241 |
+
scheduler.add_job(give_verified_roles, trigger='interval', minutes=1, max_instances=1, executor='asyncio')
|
242 |
scheduler.start()
|
243 |
+
asyncio.get_event_loop().run_forever()
|
244 |
|
245 |
|
246 |
def calculate_level(xp):
|