generated from HoloTech/holotech-plugin-template
tweak: Add inactive redeem event listener
This commit is contained in:
+6
-3
@@ -62,6 +62,7 @@ class RewardCampaign:
|
||||
twitch_user_id: Optional[str] = None,
|
||||
twitch_user_name: Optional[str] = None,
|
||||
earned_at: Optional[datetime] = None,
|
||||
**kwargs,
|
||||
) -> EarnedReward:
|
||||
row = await EarnedReward.create(
|
||||
campaign_id=self.row.campaign_id,
|
||||
@@ -71,6 +72,7 @@ class RewardCampaign:
|
||||
twitch_user_id=twitch_user_id,
|
||||
twitch_user_name=twitch_user_name,
|
||||
earned_at=earned_at or utc_now(),
|
||||
**kwargs,
|
||||
)
|
||||
await self.try_to_log_reward(row)
|
||||
|
||||
@@ -99,7 +101,8 @@ class RewardCampaign:
|
||||
return rows
|
||||
|
||||
async def try_to_unlog_reward(self, reward: EarnedReward):
|
||||
import discord
|
||||
import discord
|
||||
|
||||
try:
|
||||
if self.webhook and reward.log_messageid:
|
||||
await self.webhook.delete_message(reward.log_messageid)
|
||||
@@ -218,8 +221,8 @@ class CampaignRegistry:
|
||||
condition = Campaign.communityid == cid
|
||||
|
||||
if active is not None:
|
||||
active_condition = (
|
||||
(Campaign.started_at != NULL) & (Campaign.completed_at == NULL)
|
||||
active_condition = (Campaign.started_at != NULL) & (
|
||||
Campaign.completed_at == NULL
|
||||
)
|
||||
if active:
|
||||
condition = condition & active_condition
|
||||
|
||||
@@ -80,10 +80,43 @@ class CampaignComponent(cmds.Component):
|
||||
twitch_user_name=data["chatter_user_name"],
|
||||
)
|
||||
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):
|
||||
if not payload.text.startswith("%reward%"):
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user