-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdverify.py
More file actions
67 lines (56 loc) · 2.48 KB
/
dverify.py
File metadata and controls
67 lines (56 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import aiohttp
from config import MEME_BACKEND, ADMIN_TOKEN
USER_AUTH_CACHE = {}
async def handle_login(ctx):
user = await check_user_status(ctx)
if user is not None:
await ctx.respond(
f"Your discord account is connected to memes.party\nETH Address: {user['username']}\nKarma: {user['userprofile']['karma']}\n",
ephemeral=True)
else:
await generate_send_login_link(ctx)
async def generate_send_login_link(ctx):
discord_username = str(ctx.user)
print('now generating login link')
url = f"{MEME_BACKEND}/museum/discord/"
headers = {
"Authorization": f"Token {ADMIN_TOKEN}",
"Content-Type": "application/json"
}
json = {"discord_username": discord_username}
async with aiohttp.ClientSession() as session:
async with session.post(url, json=json, headers=headers) as resp:
print(resp.status)
resp_json = await resp.json()
print(resp_json)
generated_url = f'https://memes.party/?dverify={resp_json["token"]}'
await ctx.respond(
f"Beep boop, I'm the friendly memes.party bot! 👋 🤖 \nBy logging in with the link below the memes you upload to the Gitcoin meme channels will magically be uploaded to memes.party! 🎺 \n{generated_url}\nHappy memeing!",
ephemeral=True)
async def check_user_status(ctx):
discord_username = str(ctx.user)
url = f"{MEME_BACKEND}/museum/discord/"
headers = {"Authorization": f"Token {ADMIN_TOKEN}"}
params = {"d_username": discord_username}
verified = False
async with aiohttp.ClientSession() as session:
async with session.get(url, params=params, headers=headers) as resp:
if resp.status != 404:
verified = True
user = await resp.json()
return user if verified else None
async def get_user_token(user):
discord_username = str(user)
if discord_username in USER_AUTH_CACHE:
return USER_AUTH_CACHE[discord_username]
url = f"{MEME_BACKEND}/museum/botauth/"
headers = {"Authorization": f"Token {ADMIN_TOKEN}"}
params = {"d_username": discord_username}
verified = False
async with aiohttp.ClientSession() as session:
async with session.get(url, params=params, headers=headers) as resp:
if resp.status != 404:
verified = True
token = await resp.json()
USER_AUTH_CACHE[discord_username] = token['auth_token']
return token['auth_token'] if verified else None