This repository was archived by the owner on Feb 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathLookup.py
More file actions
65 lines (50 loc) · 1.63 KB
/
Lookup.py
File metadata and controls
65 lines (50 loc) · 1.63 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
#!/bin/env python3
from aiohttp import web
import asyncio
import discord
import json
import os
import threading
import time
class DiscordClient(discord.Client):
ready = False
async def on_ready(self):
self.ready = True
print(f'[INFO] Discord: logged in as {self.user}')
def is_ready(self):
return self.ready
async def fetch_by_id(request):
uid = request.match_info["uid"]
if not uid.isnumeric():
return web.Response(text = json.dumps({"error":"UID must be numeric"}))
print("[INFO] fetchById: Searching for uid:", uid)
discordUser = await client.fetch_user(uid)
user = {
"uid": discordUser.id,
"tag": discordUser.name + "#" + discordUser.discriminator,
"avatar": discordUser.avatar,
"bot": discordUser.bot,
"created_at": int(time.mktime(discordUser.created_at.timetuple()))
}
return web.Response(text = json.dumps(user))
async def handle_health(request):
if not client.is_ready() or client.is_closed():
return web.Response(text="no")
return web.Response(text="yes")
async def alive(request):
return web.Response(text="yes")
async def run_bot(token):
await client.start(token)
def run_forever(loop):
loop.run_forever()
token = os.environ['DISCORD_TOKEN']
client = DiscordClient()
loop = asyncio.get_event_loop()
loop.create_task(run_bot(token))
thread = threading.Thread(target=run_forever, args=(loop, ))
app = web.Application()
app.add_routes([web.get('/health', handle_health),
web.get('/alive', alive),
web.get('/by-uid/{uid}', fetch_by_id)])
web.run_app(app)
thread.join()