Compare commits

...

4 Commits

Author SHA1 Message Date
f853f01bf8 fix: Version module typo. 2025-09-02 07:57:13 +10:00
4707bc2aca Move to new plugin framework.
- User `profiles` component for profile and community fetch.
- Add data version check
- Move `datamodels` to `botdata`.
2025-09-02 07:14:51 +10:00
094b1e3c57 Fix imported client name. 2025-09-01 19:47:34 +10:00
c84ae3b281 Rename scheam file. 2025-09-01 19:47:04 +10:00
4 changed files with 31 additions and 43 deletions

View File

@@ -1,3 +1 @@
async def twitch_setup(bot):
from .tracker import setup
await setup(bot)
from .tracker import setup as twitch_setup

View File

@@ -1,3 +1,5 @@
BEGIN;
INSERT INTO version_history (component, from_version, to_version, author) VALUES ('EVENT_TRACKER', 0, 1, 'Initial Creation');
-- TODO: Assert profiles data version
@@ -176,3 +178,5 @@ CREATE TABLE raid_in_events(
FOREIGN KEY (event_id, event_type) REFERENCES events (event_id, event_type)
);
-- }}}
COMMIT;

View File

@@ -4,8 +4,8 @@ import twitchio
from twitchio import PartialUser, Scopes, eventsub
from twitchio.ext import commands as cmds
from datamodels import BotChannel, Communities, UserProfile
from meta import CrocBot
from botdata import BotChannel
from meta import Bot
from utils.lib import utc_now
from . import logger
@@ -13,10 +13,9 @@ from .data import EventData, TrackingChannel
class TrackerComponent(cmds.Component):
def __init__(self, bot: CrocBot):
def __init__(self, bot: Bot):
self.bot = bot
self.data = bot.dbconn.load_registry(EventData())
print(self.__all_listeners__)
# One command, which sends join link to start tracking
# Utility for fetch_or_create community and profiles and setting names
@@ -25,6 +24,7 @@ class TrackerComponent(cmds.Component):
# ----- API -----
async def component_load(self):
await self.data.init()
await self.bot.version_check(*self.data.VERSION)
async def component_teardown(self):
pass
@@ -131,11 +131,9 @@ class TrackerComponent(cmds.Component):
async def event_custom_redemption_add(self, payload: twitchio.ChannelPointsRedemptionAdd):
tracked = await TrackingChannel.fetch(payload.broadcaster.id)
if tracked and tracked.joined:
community = await self.bot.community_fetch(twitchid=payload.broadcaster.id, name=payload.broadcaster.name)
community = await self.bot.profiles.fetch_community(payload.broadcaster)
cid = community.communityid
profile = await self.bot.profile_fetch(
twitchid=payload.user.id, name=payload.user.name,
)
profile = await self.bot.profiles.fetch_profile(payload.user)
pid = profile.profileid
event_row = await self.data.events.insert(
@@ -160,11 +158,9 @@ class TrackerComponent(cmds.Component):
async def event_custom_redemption_update(self, payload: twitchio.ChannelPointsRedemptionUpdate):
tracked = await TrackingChannel.fetch(payload.broadcaster.id)
if tracked and tracked.joined:
community = await self.bot.community_fetch(twitchid=payload.broadcaster.id, name=payload.broadcaster.name)
community = await self.bot.profiles.fetch_community(payload.broadcaster)
cid = community.communityid
profile = await self.bot.profile_fetch(
twitchid=payload.user.id, name=payload.user.name,
)
profile = await self.bot.profiles.fetch_profile(payload.user)
pid = profile.profileid
event_row = await self.data.events.insert(
@@ -188,11 +184,9 @@ class TrackerComponent(cmds.Component):
async def event_follow(self, payload: twitchio.ChannelFollow):
tracked = await TrackingChannel.fetch(payload.broadcaster.id)
if tracked and tracked.joined:
community = await self.bot.community_fetch(twitchid=payload.broadcaster.id, name=payload.broadcaster.name)
community = await self.bot.profiles.fetch_community(payload.broadcaster)
cid = community.communityid
profile = await self.bot.profile_fetch(
twitchid=payload.user.id, name=payload.user.name,
)
profile = await self.bot.profiles.fetch_profile(payload.user)
pid = profile.profileid
# Computer follower count
@@ -214,11 +208,9 @@ class TrackerComponent(cmds.Component):
async def event_bits_use(self, payload: twitchio.ChannelBitsUse):
tracked = await TrackingChannel.fetch(payload.broadcaster.id)
if tracked and tracked.joined:
community = await self.bot.community_fetch(twitchid=payload.broadcaster.id, name=payload.broadcaster.name)
community = await self.bot.profiles.fetch_community(payload.broadcaster)
cid = community.communityid
profile = await self.bot.profile_fetch(
twitchid=payload.user.id, name=payload.user.name,
)
profile = await self.bot.profiles.fetch_profile(payload.user)
pid = profile.profileid
event_row = await self.data.events.insert(
@@ -241,11 +233,9 @@ class TrackerComponent(cmds.Component):
async def event_subscription(self, payload: twitchio.ChannelSubscribe):
tracked = await TrackingChannel.fetch(payload.broadcaster.id)
if tracked and tracked.joined:
community = await self.bot.community_fetch(twitchid=payload.broadcaster.id, name=payload.broadcaster.name)
community = await self.bot.profiles.fetch_community(payload.broadcaster)
cid = community.communityid
profile = await self.bot.profile_fetch(
twitchid=payload.user.id, name=payload.user.name,
)
profile = await self.bot.profiles.fetch_profile(payload.user)
pid = profile.profileid
event_row = await self.data.events.insert(
@@ -266,12 +256,10 @@ class TrackerComponent(cmds.Component):
async def event_subscription_gift(self, payload: twitchio.ChannelSubscriptionGift):
tracked = await TrackingChannel.fetch(payload.broadcaster.id)
if tracked and tracked.joined:
community = await self.bot.community_fetch(twitchid=payload.broadcaster.id, name=payload.broadcaster.name)
community = await self.bot.profiles.fetch_community(payload.broadcaster)
cid = community.communityid
if payload.user is not None:
profile = await self.bot.profile_fetch(
twitchid=payload.user.id, name=payload.user.name,
)
profile = await self.bot.profiles.fetch_profile(payload.user)
pid = profile.profileid
else:
pid = None
@@ -294,11 +282,9 @@ class TrackerComponent(cmds.Component):
async def event_subscription_message(self, payload: twitchio.ChannelSubscriptionMessage):
tracked = await TrackingChannel.fetch(payload.broadcaster.id)
if tracked and tracked.joined:
community = await self.bot.community_fetch(twitchid=payload.broadcaster.id, name=payload.broadcaster.name)
community = await self.bot.profiles.fetch_community(payload.broadcaster)
cid = community.communityid
profile = await self.bot.profile_fetch(
twitchid=payload.user.id, name=payload.user.name,
)
profile = await self.bot.profiles.fetch_profile(payload.user)
pid = profile.profileid
event_row = await self.data.events.insert(
@@ -322,7 +308,7 @@ class TrackerComponent(cmds.Component):
async def event_stream_online(self, payload: twitchio.StreamOnline):
tracked = await TrackingChannel.fetch(payload.broadcaster.id)
if tracked and tracked.joined:
community = await self.bot.community_fetch(twitchid=payload.broadcaster.id, name=payload.broadcaster.name)
community = await self.bot.profiles.fetch_community(payload.broadcaster)
cid = community.communityid
event_row = await self.data.events.insert(
@@ -341,7 +327,7 @@ class TrackerComponent(cmds.Component):
async def event_stream_offline(self, payload: twitchio.StreamOffline):
tracked = await TrackingChannel.fetch(payload.broadcaster.id)
if tracked and tracked.joined:
community = await self.bot.community_fetch(twitchid=payload.broadcaster.id, name=payload.broadcaster.name)
community = await self.bot.profiles.fetch_community(payload.broadcaster)
cid = community.communityid
event_row = await self.data.events.insert(
@@ -369,7 +355,7 @@ class TrackerComponent(cmds.Component):
async def _event_raid_out(self, broadcaster: PartialUser, to_broadcaster: PartialUser, viewer_count: int):
tracked = await TrackingChannel.fetch(broadcaster.id)
if tracked and tracked.joined:
community = await self.bot.community_fetch(twitchid=broadcaster.id, name=broadcaster.name)
community = await self.bot.profiles.fetch_community(broadcaster)
cid = community.communityid
event_row = await self.data.events.insert(
@@ -387,7 +373,7 @@ class TrackerComponent(cmds.Component):
async def _event_raid_in(self, broadcaster: PartialUser, from_broadcaster: PartialUser, viewer_count: int):
tracked = await TrackingChannel.fetch(broadcaster.id)
if tracked and tracked.joined:
community = await self.bot.community_fetch(twitchid=broadcaster.id, name=broadcaster.name)
community = await self.bot.profiles.fetch_community(broadcaster)
cid = community.communityid
event_row = await self.data.events.insert(
@@ -406,11 +392,9 @@ class TrackerComponent(cmds.Component):
async def event_message(self, payload: twitchio.ChatMessage):
tracked = await TrackingChannel.fetch(payload.broadcaster.id)
if tracked and tracked.joined:
community = await self.bot.community_fetch(twitchid=payload.broadcaster.id, name=payload.broadcaster.name)
community = await self.bot.profiles.fetch_community(payload.broadcaster)
cid = community.communityid
profile = await self.bot.profile_fetch(
twitchid=payload.chatter.id, name=payload.chatter.name,
)
profile = await self.bot.profiles.fetch_profile(payload.chatter)
pid = profile.profileid
event_row = await self.data.events.insert(

View File

@@ -13,6 +13,8 @@ class TrackingChannel(RowModel):
class EventData(Registry):
VERSION = ('EVENT_TRACKER', 1)
tracking_channels = TrackingChannel.table
events = Table('events')