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