Compare commits

...

5 Commits

Author SHA1 Message Date
0363dc2bcd Catch IndexError for user upgrade. 2025-09-02 09:04:14 +10:00
ce46bd49fe fix: Remove transaction block. 2025-09-02 08:57:04 +10:00
4653689e5e fix: Profile component typo. 2025-09-02 07:55:41 +10:00
e8e44b7da8 Add twitch_setup export. 2025-09-02 07:54:08 +10:00
445935f2c9 Add version check and init to component. 2025-09-01 23:23:48 +10:00
3 changed files with 28 additions and 28 deletions

View File

@@ -1 +1 @@
from .profiles import setup from .profiles import setup, twitch_setup

View File

@@ -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))

View File

@@ -24,6 +24,8 @@ class ProfilesComponent(cmds.Component):
# ----- API ----- # ----- API -----
async def component_load(self): async def component_load(self):
await self.data.init() await self.data.init()
await self.bot.version_check(*self.data.VERSION)
await self.profiles.init()
async def component_teardown(self): async def component_teardown(self):
pass pass
@@ -39,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
@@ -68,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