From 8189eeec058e235a0043404619ae54e522e42b96 Mon Sep 17 00:00:00 2001 From: Interitio Date: Thu, 30 Jul 2026 14:40:58 +0300 Subject: [PATCH] feat(discord): Inline reward editing --- plugin/discord/cog.py | 80 +++++++++++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 25 deletions(-) diff --git a/plugin/discord/cog.py b/plugin/discord/cog.py index 6c24a6c..bf36d6d 100644 --- a/plugin/discord/cog.py +++ b/plugin/discord/cog.py @@ -323,9 +323,19 @@ class CampaignCog(LionCog): ) @appcmds.describe( 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") - 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 # Will need to identify the reward with autocomplete. Can use the reward id directly.. if not rewardid.isdigit(): @@ -353,40 +363,60 @@ class CampaignCog(LionCog): ) return - # Okay, this is our reward, and author has permission to modify it. Spin the modal. - modal = RewardEditor.from_reward(reward) - + # Okay, this is our reward, and author has permission to modify it. currently_fluffed = reward.fulfilled_at is not None - @modal.submit_callback() - async def on_editor_submit(interaction: discord.Interaction): - update_args = {} - - if modal.flufbox.component.value and not currently_fluffed: + update_args = {} + if fulfilled is not None: + if fulfilled and not currently_fluffed: # Reward has been fluffed 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 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 new_ref_value != reward.reference: - update_args["reference"] = new_ref_value + if update_args: + await ctx.interaction.response.defer(thinking=True, ephemeral=True) + 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 - if new_notes_value != reward.modnote: - update_args["modnote"] = new_notes_value + @modal.submit_callback() + async def on_editor_submit(interaction: discord.Interaction): + update_args = {} - 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) + if modal.flufbox.component.value and not currently_fluffed: + # Reward has been fluffed + update_args["fulfilled_at"] = utc_now() + elif currently_fluffed and not modal.flufbox.component.value: + # Reward has been unfluffed + update_args["fulfilled_at"] = None - 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( self, campaign: RewardCampaign, reward: EarnedReward