generated from HoloTech/holotech-plugin-template
feat(discord): Inline reward editing
This commit is contained in:
+55
-25
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user