generated from HoloTech/holotech-plugin-template
feat: Add delreward command.
This commit is contained in:
@@ -7,6 +7,7 @@ from discord.ext import commands as cmds
|
||||
from discord import Forbidden, User, app_commands as appcmds
|
||||
|
||||
from meta import LionBot, LionCog, LionContext
|
||||
from meta import logger
|
||||
from meta.errors import SafeCancellation, UserInputError
|
||||
from meta.logger import log_wrap
|
||||
from utils.lib import utc_now
|
||||
@@ -317,6 +318,53 @@ class CampaignCog(LionCog):
|
||||
|
||||
campaign_rewards_cmd.autocomplete("campaign_name")(_campaign_acmpl)
|
||||
|
||||
@campaign_group.command(
|
||||
name="delreward",
|
||||
description="Remove a campaign reward",
|
||||
)
|
||||
@appcmds.describe(
|
||||
rewardid="Earned reward to delete",
|
||||
)
|
||||
@appcmds.rename(rewardid="reward")
|
||||
async def campaign_delreward_cmd(
|
||||
self,
|
||||
ctx: LionContext,
|
||||
rewardid: str,
|
||||
):
|
||||
# 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():
|
||||
raise UserInputError(
|
||||
"Please enter the reward number or select a reward from the argument menu"
|
||||
)
|
||||
|
||||
reward = await EarnedReward.fetch(int(rewardid))
|
||||
if not reward:
|
||||
raise UserInputError(
|
||||
"Reward not found. Please enter the reward number or select a reward from the argument menu"
|
||||
)
|
||||
|
||||
# Fetch campaign and then do a perm check
|
||||
campaign = await self.campaigns.fetch_campaign(reward.campaign_id)
|
||||
if campaign is None:
|
||||
raise SafeCancellation("Something went wrong.. please try again soon.")
|
||||
if campaign.row.communityid != ctx.community.communityid:
|
||||
raise UserInputError("This reward doesn't belong to this community!")
|
||||
|
||||
if not await self.campaign_modcheck(campaign, ctx.author):
|
||||
await ctx.interaction.response.send_message(
|
||||
"You need to be an administrator or have the configured modrole to use that!",
|
||||
ephemeral=True,
|
||||
)
|
||||
return
|
||||
|
||||
# Okay, they have permission, let's delete the reward.
|
||||
await campaign.delete_reward(reward.earned_id)
|
||||
|
||||
# Ack
|
||||
await ctx.reply(content="Campaign reward deleted!", ephemeral=True)
|
||||
|
||||
|
||||
@campaign_group.command(
|
||||
name="editreward",
|
||||
description="Add or edit details for a given reward in a campaign (see also /campaign rewards)",
|
||||
@@ -432,6 +480,7 @@ class CampaignCog(LionCog):
|
||||
cname=campaign.row.campaign_name,
|
||||
)
|
||||
|
||||
@campaign_delreward_cmd.autocomplete("rewardid")
|
||||
@campaign_editreward_cmd.autocomplete("rewardid")
|
||||
async def _reward_acmpl(
|
||||
self, interaction: discord.Interaction, partial: str
|
||||
|
||||
Reference in New Issue
Block a user