tweak: Add inactive redeem event listener

This commit is contained in:
2026-07-31 13:23:42 +03:00
parent 14134d8831
commit 97bdf8e8e3
2 changed files with 42 additions and 6 deletions
+6 -3
View File
@@ -62,6 +62,7 @@ class RewardCampaign:
twitch_user_id: Optional[str] = None, twitch_user_id: Optional[str] = None,
twitch_user_name: Optional[str] = None, twitch_user_name: Optional[str] = None,
earned_at: Optional[datetime] = None, earned_at: Optional[datetime] = None,
**kwargs,
) -> EarnedReward: ) -> EarnedReward:
row = await EarnedReward.create( row = await EarnedReward.create(
campaign_id=self.row.campaign_id, campaign_id=self.row.campaign_id,
@@ -71,6 +72,7 @@ class RewardCampaign:
twitch_user_id=twitch_user_id, twitch_user_id=twitch_user_id,
twitch_user_name=twitch_user_name, twitch_user_name=twitch_user_name,
earned_at=earned_at or utc_now(), earned_at=earned_at or utc_now(),
**kwargs,
) )
await self.try_to_log_reward(row) await self.try_to_log_reward(row)
@@ -99,7 +101,8 @@ class RewardCampaign:
return rows return rows
async def try_to_unlog_reward(self, reward: EarnedReward): async def try_to_unlog_reward(self, reward: EarnedReward):
import discord import discord
try: try:
if self.webhook and reward.log_messageid: if self.webhook and reward.log_messageid:
await self.webhook.delete_message(reward.log_messageid) await self.webhook.delete_message(reward.log_messageid)
@@ -218,8 +221,8 @@ class CampaignRegistry:
condition = Campaign.communityid == cid condition = Campaign.communityid == cid
if active is not None: if active is not None:
active_condition = ( active_condition = (Campaign.started_at != NULL) & (
(Campaign.started_at != NULL) & (Campaign.completed_at == NULL) Campaign.completed_at == NULL
) )
if active: if active:
condition = condition & active_condition condition = condition & active_condition
+36 -3
View File
@@ -80,10 +80,43 @@ class CampaignComponent(cmds.Component):
twitch_user_name=data["chatter_user_name"], twitch_user_name=data["chatter_user_name"],
) )
await self.dispatch_update(campaign) await self.dispatch_update(campaign)
# TODO: Webhook logging maybe.. (do this in campaign)
# Or just general logging. (also do this in campaign, but we can do again here)
@cmds.Component.listener() # @cmds.Component.listener()
async def event_custom_redemption_add(self, payload):
if payload.reward.title not in (
"hi!",
"hydrate",
"stretch",
"save file",
"pet lilac",
):
return
community = await self.bot.profiles.fetch_community(payload.broadcaster)
cid = community.communityid
profile = await self.bot.profiles.fetch_profile(payload.user)
pid = profile.profileid
campaigns = await self.campaigns.fetch_campaigns(cid)
for campaign in campaigns:
reward_progress = len(await campaign.get_rewards())
if (
campaign.row.target_rewards is None
or reward_progress < campaign.row.target_rewards
):
# Add a reward to the database with the correct info.
await campaign.add_reward(
profileid=pid,
earned_from=f"(REDEEM) User redeemed {payload.reward.title}",
event_id=None,
twitch_user_id=payload.user.id,
twitch_user_name=payload.user.name,
reference=f"Redeem text: {payload.user_input}",
)
await self.dispatch_update(campaign)
# @cmds.Component.listener()
async def event_message(self, payload): async def event_message(self, payload):
if not payload.text.startswith("%reward%"): if not payload.text.startswith("%reward%"):
return return