fix: Make 'earned_from' column name consistent

This commit is contained in:
2026-07-30 11:58:35 +03:00
parent d8817d4473
commit 5873b0fe65
3 changed files with 48 additions and 34 deletions
+28 -5
View File
@@ -74,7 +74,7 @@ class CampaignComponent(cmds.Component):
# Add a reward to the database with the correct info.
await campaign.add_reward(
profileid=event_row["profileid"],
earned_reason=f"(SUB) User subscribed for {duration} months at tier {tier}",
earned_from=f"(SUB) User subscribed for {duration} months at tier {tier}",
event_id=event_row["event_id"],
twitch_user_id=data["chatter_user_id"],
twitch_user_name=data["chatter_user_name"],
@@ -83,6 +83,31 @@ class CampaignComponent(cmds.Component):
# 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()
async def event_message(self, payload):
community = await self.bot.profiles.fetch_community(payload.broadcaster)
cid = community.communityid
profile = await self.bot.profiles.fetch_profile(payload.chatter)
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"(MSG) User messaged in chat: {payload.text}",
event_id=None,
twitch_user_id=payload.chatter.id,
twitch_user_name=payload.chatter.name,
)
await self.dispatch_update(campaign)
@cmds.Component.listener()
async def event_safe_event_chat_notice_resub(self, payload):
# Check that the end of the sub is past the threshold by adding duration to the previous sub
@@ -137,11 +162,9 @@ class CampaignComponent(cmds.Component):
reward_cap = campaign.row.target_rewards
if reward_cap is not None:
response = (
f"{name}: {rewards_earned} rewards earned out of {reward_cap}!"
)
response = "{name}: {given} rewards earned out of {cap}!"
else:
response = f"{name}: {rewards_earned} rewards earned so far!"
response = "{name}: {given} rewards earned so far!"
formatted = response.format(
name=campaign.row.campaign_name,
given=rewards_earned,