forked from thomasgonda3/QueueBot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhost_fcs.py
44 lines (34 loc) · 1.51 KB
/
host_fcs.py
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
import common
from typing import Dict
from collections.abc import Iterable
import aiohttp
MKW_HOST_API_URL = f"https://mkwlounge.gg/api/hostfc.php?discord_guild_id={common.CONFIG['guild_id']}&discord_user_id="
SESSION = None
def create_new_session():
global SESSION
SESSION = aiohttp.ClientSession()
async def _get_mk8dx_hosts(discord_ids: Iterable[str]) -> Dict[str, str]:
return {}
async def _get_mkw_hosts(discord_ids: Iterable[str]) -> Dict[str, str]:
request_url = MKW_HOST_API_URL + ",".join(discord_ids)
async with aiohttp.ClientSession(timeout=aiohttp.ClientTimeout(total=5)) as session:
async with session.get(request_url) as r:
if r.status != 200:
print(f"hostfc endpoint returned status {r.status}")
return {}
results = await r.json()
if "status" not in results or results["status"] != "success":
print(
f"hostfc endpoint returned unsuccessful results {results}")
return {}
host_mapping = {}
for item in results["results"]:
host_mapping[item["discord_user_id"]] = item["fc"]
return host_mapping
async def get_hosts(discord_ids: Iterable[str]) -> Dict[str, str]:
if common.SERVER is common.Server.MKW:
return await _get_mkw_hosts(discord_ids)
elif common.SERVER is common.Server.MK8DX:
return await _get_mk8dx_hosts(discord_ids)
else:
raise ValueError("Bad config settings for server.")