Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
revert; trying caching all members on_ready
Browse files
app.py
CHANGED
|
@@ -103,6 +103,8 @@ async def on_ready():
|
|
| 103 |
print(f'Logged in as {bot.user.name}')
|
| 104 |
print(f"XP_PER_MESSAGE: {XP_PER_MESSAGE}")
|
| 105 |
|
|
|
|
|
|
|
| 106 |
channel = bot.get_channel(900125909984624713)
|
| 107 |
if channel:
|
| 108 |
try:
|
|
@@ -833,7 +835,6 @@ def send_lunar_verification_logs_def(lunar, member, username):
|
|
| 833 |
|
| 834 |
async def get_member_async(user_id, server):
|
| 835 |
member = await server.fetch_member(user_id)
|
| 836 |
-
print(f"member={member}")
|
| 837 |
return member
|
| 838 |
|
| 839 |
|
|
@@ -843,11 +844,15 @@ def get_member_def(user_id, server):
|
|
| 843 |
return loop.run_until_complete(get_member_async(user_id, server))
|
| 844 |
|
| 845 |
|
| 846 |
-
|
| 847 |
url_str = str(request.url)
|
| 848 |
query_params = parse_qs(urlparse(url_str).query)
|
| 849 |
user_id = query_params.get('user_id', [None])[0]
|
|
|
|
| 850 |
token = query_params.get('token', [None])[0]
|
|
|
|
|
|
|
|
|
|
| 851 |
|
| 852 |
if user_id is None or token is None:
|
| 853 |
return "# β Invalid link. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) !"
|
|
@@ -859,10 +864,10 @@ async def verify_button(profile: gr.OAuthProfile | None, request: gr.Request) ->
|
|
| 859 |
return f"# β Not logged in with Hugging Face yet."
|
| 860 |
|
| 861 |
server = bot.get_guild(879548962464493619)
|
|
|
|
| 862 |
role = server.get_role(900063512829755413)
|
| 863 |
-
|
| 864 |
-
member
|
| 865 |
-
|
| 866 |
verified_date = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
|
| 867 |
likes = 0
|
| 868 |
models = 0
|
|
@@ -872,30 +877,38 @@ async def verify_button(profile: gr.OAuthProfile | None, request: gr.Request) ->
|
|
| 872 |
papers = 0
|
| 873 |
upvotes = 0
|
| 874 |
|
|
|
|
| 875 |
if role in member.roles:
|
| 876 |
return (f" β {member} already has has the '{role}' role! To change discord accounts or HF accounts, contact @lunarflu on discord or adam@huggingface.co")
|
| 877 |
|
|
|
|
|
|
|
| 878 |
if profile.username in global_df['hf_user_name'].values:
|
| 879 |
return (f"The HF account {profile.username} is already verified! To change discord accounts or HF accounts, contact @lunarflu or adam@huggingface.co")
|
| 880 |
|
|
|
|
| 881 |
lunar = bot.get_user(811235357663297546)
|
| 882 |
altered_member_id = "L" + str(member.id) + "L"
|
| 883 |
if altered_member_id in global_df['discord_user_id'].values:
|
|
|
|
| 884 |
hf_user_name = global_df.loc[global_df['discord_user_id'] == altered_member_id, 'hf_user_name'].iloc[0]
|
| 885 |
|
| 886 |
if pd.isnull(hf_user_name) or hf_user_name == 'n/a':
|
|
|
|
| 887 |
global_df.loc[global_df['discord_user_id'] == altered_member_id, 'hf_user_name'] = profile.username
|
| 888 |
global_df.loc[global_df['discord_user_id'] == altered_member_id, 'verified_date'] = verified_date
|
| 889 |
-
|
| 890 |
if role in member.roles:
|
| 891 |
-
|
| 892 |
-
return (f" β
Verification successful! [{member} <---> {profile.username}] π€\n{invite_message}\n{org_link} ")
|
|
|
|
|
|
|
| 893 |
else:
|
| 894 |
-
return (f" β The Discord account {member} is already verified! To change discord accounts or HF accounts, contact @lunarflu or adam@huggingface.co")
|
|
|
|
| 895 |
|
|
|
|
| 896 |
del user_tokens[int(user_id)]
|
| 897 |
-
return "# β An unexpected error occurred."
|
| 898 |
-
|
| 899 |
|
| 900 |
|
| 901 |
demo = gr.Blocks()
|
|
|
|
| 103 |
print(f'Logged in as {bot.user.name}')
|
| 104 |
print(f"XP_PER_MESSAGE: {XP_PER_MESSAGE}")
|
| 105 |
|
| 106 |
+
await server.fetch_members(limit=None).flatten()
|
| 107 |
+
|
| 108 |
channel = bot.get_channel(900125909984624713)
|
| 109 |
if channel:
|
| 110 |
try:
|
|
|
|
| 835 |
|
| 836 |
async def get_member_async(user_id, server):
|
| 837 |
member = await server.fetch_member(user_id)
|
|
|
|
| 838 |
return member
|
| 839 |
|
| 840 |
|
|
|
|
| 844 |
return loop.run_until_complete(get_member_async(user_id, server))
|
| 845 |
|
| 846 |
|
| 847 |
+
def verify_button(profile: gr.OAuthProfile | None, request: gr.Request) -> str:
|
| 848 |
url_str = str(request.url)
|
| 849 |
query_params = parse_qs(urlparse(url_str).query)
|
| 850 |
user_id = query_params.get('user_id', [None])[0]
|
| 851 |
+
print(f"user_id={user_id}")
|
| 852 |
token = query_params.get('token', [None])[0]
|
| 853 |
+
print(f"token={token}")
|
| 854 |
+
|
| 855 |
+
print(f"||| token:{token}||| user_id:{user_id}||| profile:{profile}||| user_tokens:{user_tokens}")
|
| 856 |
|
| 857 |
if user_id is None or token is None:
|
| 858 |
return "# β Invalid link. Generate a new link [here](https://discord.com/channels/879548962464493619/900125909984624713) !"
|
|
|
|
| 864 |
return f"# β Not logged in with Hugging Face yet."
|
| 865 |
|
| 866 |
server = bot.get_guild(879548962464493619)
|
| 867 |
+
print(f"server={server}")
|
| 868 |
role = server.get_role(900063512829755413)
|
| 869 |
+
member = server.get_member(user_id)
|
| 870 |
+
print(f"member={member}")
|
|
|
|
| 871 |
verified_date = datetime.now().strftime("%m/%d/%Y, %H:%M:%S")
|
| 872 |
likes = 0
|
| 873 |
models = 0
|
|
|
|
| 877 |
papers = 0
|
| 878 |
upvotes = 0
|
| 879 |
|
| 880 |
+
# do they have the verified role already?
|
| 881 |
if role in member.roles:
|
| 882 |
return (f" β {member} already has has the '{role}' role! To change discord accounts or HF accounts, contact @lunarflu on discord or adam@huggingface.co")
|
| 883 |
|
| 884 |
+
|
| 885 |
+
# check if hf_user_name in dataframe:
|
| 886 |
if profile.username in global_df['hf_user_name'].values:
|
| 887 |
return (f"The HF account {profile.username} is already verified! To change discord accounts or HF accounts, contact @lunarflu or adam@huggingface.co")
|
| 888 |
|
| 889 |
+
# check if discord_user_id in dataframe:
|
| 890 |
lunar = bot.get_user(811235357663297546)
|
| 891 |
altered_member_id = "L" + str(member.id) + "L"
|
| 892 |
if altered_member_id in global_df['discord_user_id'].values:
|
| 893 |
+
|
| 894 |
hf_user_name = global_df.loc[global_df['discord_user_id'] == altered_member_id, 'hf_user_name'].iloc[0]
|
| 895 |
|
| 896 |
if pd.isnull(hf_user_name) or hf_user_name == 'n/a':
|
| 897 |
+
# empty (no link created yet between discord_user_id and hf_user_name) so we can update
|
| 898 |
global_df.loc[global_df['discord_user_id'] == altered_member_id, 'hf_user_name'] = profile.username
|
| 899 |
global_df.loc[global_df['discord_user_id'] == altered_member_id, 'verified_date'] = verified_date
|
| 900 |
+
add_verified_role(member, role)
|
| 901 |
if role in member.roles:
|
| 902 |
+
print(f"Updated hf_user_name for id {member.id} | discord_user_name {member} | hf_user_name {user['name']}")
|
| 903 |
+
return (f" β
Verification successful! [{member} <---> {profile.username}] π€\n{invite_message}\n{org_link} ")
|
| 904 |
+
send_lunar_verification_logs_def(lunar, member, profile.username)
|
| 905 |
+
print(f" β
Verification successful! [{member} <---> {profile.username}] π€")
|
| 906 |
else:
|
| 907 |
+
return (f" β The Discord account {member} is already verified! To change discord accounts or HF accounts, contact @lunarflu or adam@huggingface.co")
|
| 908 |
+
print(f"The Discord account {member} is already verified! To change discord accounts or HF accounts, contact @lunarflu or adam@huggingface.co")
|
| 909 |
|
| 910 |
+
# Remove the token after successful verification
|
| 911 |
del user_tokens[int(user_id)]
|
|
|
|
|
|
|
| 912 |
|
| 913 |
|
| 914 |
demo = gr.Blocks()
|