Compare commits

..

4 Commits

3 changed files with 73 additions and 35 deletions
+5 -4
View File
@@ -154,12 +154,13 @@ class RewardCampaign:
) )
# Fulfilled field # Fulfilled field
fluffed_emoji = "" if reward.fulfilled_at else "🔳"
if reward.fulfilled_at is not None: if reward.fulfilled_at is not None:
fluffed = f"Fluffed at {discord.utils.format_dt(reward.fulfilled_at, 'F')}" fluffed = f"{fluffed_emoji} Fluffed at {discord.utils.format_dt(reward.fulfilled_at, 'F')}"
if reward.fulfilled_note: if reward.fulfilled_note:
fluffed += "\n" + "Fluff Note: " + reward.fulfilled_note fluffed += "\n" + "Fluff Note: " + reward.fulfilled_note
else: else:
fluffed = "Not yet fluffed" fluffed = f"{fluffed_emoji} Not yet fluffed"
embed.add_field(name="Fulfilled", value=fluffed) embed.add_field(name="Fulfilled", value=fluffed)
@@ -204,8 +205,8 @@ class CampaignRegistry:
condition = Campaign.communityid == cid condition = Campaign.communityid == cid
if active is not None: if active is not None:
active_condition = (Campaign.started_at != NULL) & ( active_condition = (
Campaign.completed_at == NULL (Campaign.started_at != NULL) & (Campaign.completed_at == NULL)
) )
if active: if active:
condition = condition & active_condition condition = condition & active_condition
+55 -25
View File
@@ -323,9 +323,19 @@ class CampaignCog(LionCog):
) )
@appcmds.describe( @appcmds.describe(
rewardid="Earned reward to edit", rewardid="Earned reward to edit",
fulfilled="Whether this reward has been completed or not.",
reference="Reference information for this reward, e.g. image or message URL",
notes="Any additional notes",
) )
@appcmds.rename(rewardid="reward") @appcmds.rename(rewardid="reward")
async def campaign_editreward_cmd(self, ctx: LionContext, rewardid: str): async def campaign_editreward_cmd(
self,
ctx: LionContext,
rewardid: str,
fulfilled: Optional[bool] = None,
reference: Optional[str] = None,
notes: Optional[str] = None
):
# For this we'll just open the reward editor # For this we'll just open the reward editor
# Will need to identify the reward with autocomplete. Can use the reward id directly.. # Will need to identify the reward with autocomplete. Can use the reward id directly..
if not rewardid.isdigit(): if not rewardid.isdigit():
@@ -353,40 +363,60 @@ class CampaignCog(LionCog):
) )
return return
# Okay, this is our reward, and author has permission to modify it. Spin the modal. # Okay, this is our reward, and author has permission to modify it.
modal = RewardEditor.from_reward(reward)
currently_fluffed = reward.fulfilled_at is not None currently_fluffed = reward.fulfilled_at is not None
@modal.submit_callback() update_args = {}
async def on_editor_submit(interaction: discord.Interaction): if fulfilled is not None:
update_args = {} if fulfilled and not currently_fluffed:
if modal.flufbox.component.value and not currently_fluffed:
# Reward has been fluffed # Reward has been fluffed
update_args["fulfilled_at"] = utc_now() update_args["fulfilled_at"] = utc_now()
elif currently_fluffed and not modal.flufbox.component.value: elif currently_fluffed and not fulfilled:
# Reward has been unfluffed # Reward has been unfluffed
update_args["fulfilled_at"] = None update_args["fulfilled_at"] = None
if reference is not None and reference != reward.reference:
update_args["reference"] = reference
if notes is not None and notes != reward.modnote:
update_args["modnote"] = notes
new_ref_value = modal.reference.component.value or None if update_args:
if new_ref_value != reward.reference: await ctx.interaction.response.defer(thinking=True, ephemeral=True)
update_args["reference"] = new_ref_value await campaign.update_reward(reward.earned_id, **update_args)
await ctx.interaction.followup.send(
content="Reward updated!"
)
else:
modal = RewardEditor.from_reward(reward)
new_notes_value = modal.notes.component.value or None @modal.submit_callback()
if new_notes_value != reward.modnote: async def on_editor_submit(interaction: discord.Interaction):
update_args["modnote"] = new_notes_value update_args = {}
if update_args: if modal.flufbox.component.value and not currently_fluffed:
await interaction.response.defer(thinking=True, ephemeral=True) # Reward has been fluffed
await campaign.update_reward(reward.earned_id, **update_args) update_args["fulfilled_at"] = utc_now()
await interaction.followup.send( elif currently_fluffed and not modal.flufbox.component.value:
content="Reward updated!", ephemeral=True # Reward has been unfluffed
) update_args["fulfilled_at"] = None
else:
await interaction.response.defer(thinking=False)
await ctx.interaction.response.send_modal(modal) new_ref_value = modal.reference.component.value or None
if new_ref_value != reward.reference:
update_args["reference"] = new_ref_value
new_notes_value = modal.notes.component.value or None
if new_notes_value != reward.modnote:
update_args["modnote"] = new_notes_value
if update_args:
await interaction.response.defer(thinking=True, ephemeral=True)
await campaign.update_reward(reward.earned_id, **update_args)
await interaction.followup.send(
content="Reward updated!", ephemeral=True
)
else:
await interaction.response.defer(thinking=False)
await ctx.interaction.response.send_modal(modal)
def _reward_acmpl_format( def _reward_acmpl_format(
self, campaign: RewardCampaign, reward: EarnedReward self, campaign: RewardCampaign, reward: EarnedReward
+13 -6
View File
@@ -208,7 +208,6 @@ class RewardList(MessageUI):
""" """
# Title is Reward #n earned by twitch_username # Title is Reward #n earned by twitch_username
# Reward, Earned at, Earned by, Fulfilled at (not fulfilled/date), Ref, Added Notes # Reward, Earned at, Earned by, Fulfilled at (not fulfilled/date), Ref, Added Notes
name = f"Reward #{reward.earned_id} earned by {reward.twitch_user_name or reward.twitch_user_id}"
if reward.fulfilled_at is not None: if reward.fulfilled_at is not None:
fat = discord.utils.format_dt(reward.fulfilled_at, "F") fat = discord.utils.format_dt(reward.fulfilled_at, "F")
@@ -219,17 +218,25 @@ class RewardList(MessageUI):
else: else:
fluf = "*Not Fulfilled*" fluf = "*Not Fulfilled*"
fluffed_emoji = "" if reward.fulfilled_at else "🔳"
earned = discord.utils.format_dt(reward.earned_at, "d")
name = f"{fluffed_emoji} #{reward.earned_id} earned by {reward.twitch_user_name or reward.twitch_user_id} at {earned}"
table = { table = {
"Reward": "Plus Campaign Sketch", # "Reward": "Plus Campaign Sketch",
"Earned At": discord.utils.format_dt(reward.earned_at, "F"), # "Earned From": reward.earned_from,
"Earned From": reward.earned_from, # "Fulfilled At": fluf,
"Fulfilled At": fluf,
"Reference": reward.reference or "*No reference set*", "Reference": reward.reference or "*No reference set*",
"Further notes": reward.modnote or "*No notes*", "Further notes": reward.modnote or "*No notes*",
} }
prop_table = "\n".join(tabulate(*table.items())) prop_table = "\n".join(tabulate(*table.items()))
return (name, prop_table) value = '\n'.join((
"> {reason}",
"{table}",
)).format(reason=reward.earned_from, table=prop_table)
return (name, value)
def _format_reward_option(self, reward: EarnedReward) -> SelectOption: def _format_reward_option(self, reward: EarnedReward) -> SelectOption:
""" """