Compare commits
6 Commits
543a65b7fb
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| c9b6ce8f60 | |||
| 0363dc2bcd | |||
| ce46bd49fe | |||
| 4653689e5e | |||
| e8e44b7da8 | |||
| 445935f2c9 |
@@ -1 +1 @@
|
||||
from .profiles import setup
|
||||
from .profiles import setup, twitch_setup
|
||||
|
||||
@@ -41,7 +41,7 @@ CREATE UNIQUE INDEX profiles_twitch_userid ON profiles_twitch (userid);
|
||||
|
||||
CREATE TABLE communities(
|
||||
communityid INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
|
||||
migrated INTEGER REFERENCES user_profiles (profileid) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
migrated INTEGER REFERENCES communities (communityid) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
last_seen TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
_timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
|
||||
@@ -6,5 +6,5 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
async def setup(bot: 'Bot'):
|
||||
from .component import ProfileComponent
|
||||
await bot.add_component(ProfileComponent(bot))
|
||||
from .component import ProfilesComponent
|
||||
await bot.add_component(ProfilesComponent(bot))
|
||||
|
||||
@@ -24,6 +24,8 @@ class ProfilesComponent(cmds.Component):
|
||||
# ----- API -----
|
||||
async def component_load(self):
|
||||
await self.data.init()
|
||||
await self.bot.version_check(*self.data.VERSION)
|
||||
await self.profiles.init()
|
||||
|
||||
async def component_teardown(self):
|
||||
pass
|
||||
@@ -39,22 +41,22 @@ class ProfilesComponent(cmds.Component):
|
||||
Fetch or create the profile for the given user.
|
||||
"""
|
||||
userid = str(user.id)
|
||||
async with self.bot.dbconn.connection() as conn:
|
||||
self.bot.dbconn.conn = conn
|
||||
async with conn.transaction():
|
||||
profile = await self.profiles.get_profile_twitch(userid)
|
||||
if profile is None:
|
||||
args = {}
|
||||
try:
|
||||
user = await user.user()
|
||||
args['nickname'] = user.display_name
|
||||
args['avatar'] = user.profile_image.url
|
||||
except twitchio.HTTPException:
|
||||
pass
|
||||
profile = await UserProfile.create(**args)
|
||||
await TwitchProfileLink.create(profileid=profile.profileid, userid=userid)
|
||||
elif touch:
|
||||
await profile.update(last_seen=utc_now())
|
||||
# TODO: Transaction
|
||||
profile = await self.profiles.get_profile_twitch(userid)
|
||||
if profile is None:
|
||||
args = {}
|
||||
try:
|
||||
user = await user.user()
|
||||
args['nickname'] = user.display_name
|
||||
args['avatar'] = user.profile_image.url
|
||||
except twitchio.HTTPException:
|
||||
pass
|
||||
except IndexError:
|
||||
pass
|
||||
profile = await UserProfile.create(**args)
|
||||
await TwitchProfileLink.create(profileid=profile.profileid, userid=userid)
|
||||
elif touch:
|
||||
await profile.update(last_seen=utc_now())
|
||||
|
||||
return profile
|
||||
|
||||
@@ -68,14 +70,12 @@ class ProfilesComponent(cmds.Component):
|
||||
Fetch or create the community for this channel.
|
||||
"""
|
||||
chanid = channel.id
|
||||
async with self.bot.dbconn.connection() as conn:
|
||||
self.bot.dbconn.conn = conn
|
||||
async with conn.transaction():
|
||||
comm = await self.profiles.get_community_twitch(chanid)
|
||||
if comm is None:
|
||||
comm = await Community.create()
|
||||
await TwitchCommunityLink.create(channelid=chanid, communityid=comm.communityid)
|
||||
elif touch:
|
||||
await comm.update(last_seen=utc_now())
|
||||
# TODO: Transaction
|
||||
comm = await self.profiles.get_community_twitch(chanid)
|
||||
if comm is None:
|
||||
comm = await Community.create()
|
||||
await TwitchCommunityLink.create(channelid=chanid, communityid=comm.communityid)
|
||||
elif touch:
|
||||
await comm.update(last_seen=utc_now())
|
||||
return comm
|
||||
|
||||
|
||||
Reference in New Issue
Block a user