Profile schema and discord hook
This commit is contained in:
46
profiles/profiles.py
Normal file
46
profiles/profiles.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from typing import Optional
|
||||
from .data import (
|
||||
ProfilesData,
|
||||
UserProfile,
|
||||
DiscordProfileLink,
|
||||
TwitchProfileLink,
|
||||
Community,
|
||||
DiscordCommunityLink,
|
||||
TwitchCommunityLink,
|
||||
)
|
||||
|
||||
|
||||
class ProfilesRegistry:
|
||||
VERSION = ProfilesData.VERSION
|
||||
|
||||
def __init__(self, data: ProfilesData):
|
||||
self.data = data
|
||||
|
||||
async def init(self):
|
||||
await self.data.init()
|
||||
|
||||
async def get_profile(self, profileid: int) -> Optional[UserProfile]:
|
||||
return await UserProfile.fetch(profileid)
|
||||
|
||||
async def get_profile_discord(self, userid: int) -> Optional[UserProfile]:
|
||||
link = await DiscordProfileLink.fetch(userid)
|
||||
if link:
|
||||
return await UserProfile.fetch(link.profileid)
|
||||
|
||||
async def get_profile_twitch(self, userid: str) -> Optional[UserProfile]:
|
||||
link = await TwitchProfileLink.fetch(userid)
|
||||
if link:
|
||||
return await UserProfile.fetch(link.profileid)
|
||||
|
||||
async def get_community(self, communityid: int) -> Optional[Community]:
|
||||
return await Community.fetch(communityid)
|
||||
|
||||
async def get_community_discord(self, guildid: int) -> Optional[Community]:
|
||||
link = await DiscordCommunityLink.fetch(guildid)
|
||||
if link:
|
||||
return await Community.fetch(link.communityid)
|
||||
|
||||
async def get_community_twitch(self, channelid: str) -> Optional[Community]:
|
||||
link = await TwitchCommunityLink.fetch(channelid)
|
||||
if link:
|
||||
return await Community.fetch(link.communityid)
|
||||
Reference in New Issue
Block a user