feat(discord): Inline reward editing

This commit is contained in:
2026-07-30 14:40:58 +03:00
parent f2e8852d45
commit 8189eeec05
+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