Update economy.py
Refactor buy_card and add buy card-by-id
This commit is contained in:
parent
e2e114d06a
commit
726f8324ed
145
cogs/economy.py
145
cogs/economy.py
@ -53,6 +53,67 @@ class Economy(commands.Cog):
|
|||||||
async def on_app_command_error(self, interaction: discord.Interaction, error: discord.app_commands.AppCommandError):
|
async def on_app_command_error(self, interaction: discord.Interaction, error: discord.app_commands.AppCommandError):
|
||||||
await interaction.channel.send(f'{error}')
|
await interaction.channel.send(f'{error}')
|
||||||
|
|
||||||
|
async def buy_card(self, interaction: discord.Interaction, this_player: dict, owner_team: dict):
|
||||||
|
c_query = await db_get('cards',
|
||||||
|
params=[('player_id', this_player['player_id']), ('team_id', owner_team["id"])])
|
||||||
|
num_copies = c_query['count'] if c_query else 0
|
||||||
|
|
||||||
|
if not this_player['cardset']['for_purchase']:
|
||||||
|
await interaction.response.send_message(
|
||||||
|
content=f'Ope - looks like singles from the {this_player["cardset"]["name"]} cardset are not available '
|
||||||
|
f'for purchase.'
|
||||||
|
)
|
||||||
|
return
|
||||||
|
if this_player['cost'] > owner_team['wallet']:
|
||||||
|
await interaction.response.send_message(
|
||||||
|
content=None,
|
||||||
|
embeds=await get_card_embeds(get_blank_team_card(this_player))
|
||||||
|
)
|
||||||
|
await interaction.channel.send(
|
||||||
|
content=f'You currently have {num_copies} cop{"ies" if num_copies != 1 else "y"} of this card.\n\n'
|
||||||
|
f'Your Wallet: {owner_team["wallet"]}₼\n'
|
||||||
|
f'Card Price: {this_player["cost"]}₼\n'
|
||||||
|
f'After Purchase: {await get_emoji(interaction.guild, "dead", False)}\n\n'
|
||||||
|
f'You will have to save up a little more.'
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
view = Confirm(responders=[interaction.user])
|
||||||
|
await interaction.response.send_message(
|
||||||
|
content=None,
|
||||||
|
embeds=await get_card_embeds(get_blank_team_card(this_player))
|
||||||
|
)
|
||||||
|
question = await interaction.channel.send(
|
||||||
|
content=f'You currently have {num_copies} cop{"ies" if num_copies != 1 else "y"} of this card.\n\n'
|
||||||
|
f'Your Wallet: {owner_team["wallet"]}₼\n'
|
||||||
|
f'Card Price: {this_player["cost"]}₼\n'
|
||||||
|
f'After Purchase: {owner_team["wallet"] - this_player["cost"]}₼\n\n'
|
||||||
|
f'Would you like to make this purchase?',
|
||||||
|
view=view
|
||||||
|
)
|
||||||
|
await view.wait()
|
||||||
|
|
||||||
|
if not view.value:
|
||||||
|
await question.edit(
|
||||||
|
content='Saving that money. Smart.',
|
||||||
|
view=None
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
purchase = await db_get(
|
||||||
|
f'teams/{owner_team["id"]}/buy/players',
|
||||||
|
params=[('ts', team_hash(owner_team)), ('ids', f'{this_player["player_id"]}')],
|
||||||
|
timeout=10
|
||||||
|
)
|
||||||
|
if not purchase:
|
||||||
|
await question.edit(
|
||||||
|
content=f'That didn\'t go through for some reason. If this happens again, go ping the shit out of Cal.',
|
||||||
|
view=None
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
await question.edit(content=f'It\'s all yours!', view=None)
|
||||||
|
|
||||||
# async def slash_error(self, ctx, error):
|
# async def slash_error(self, ctx, error):
|
||||||
# await ctx.send(f'{error}')
|
# await ctx.send(f'{error}')
|
||||||
|
|
||||||
@ -662,7 +723,28 @@ class Economy(commands.Cog):
|
|||||||
|
|
||||||
group_buy = app_commands.Group(name='buy', description='Make a purchase from the marketplace')
|
group_buy = app_commands.Group(name='buy', description='Make a purchase from the marketplace')
|
||||||
|
|
||||||
@group_buy.command(name='card', description='Buy a player card from the marketplace')
|
@group_buy.command(name='card-by-id', description='Buy a player card from the marketplace')
|
||||||
|
@app_commands.checks.has_any_role(PD_PLAYERS)
|
||||||
|
async def buy_card_id_slash(self, interaction: discord.Interaction, player_id: int):
|
||||||
|
if interaction.channel.name in ['paper-dynasty-chat', 'pd-news-ticker', 'pd-network-news']:
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f'Please head to down to {get_channel(interaction, "pd-bot-hole")} to run this command.',
|
||||||
|
ephemeral=True
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
owner_team = await get_team_by_owner(interaction.user.id)
|
||||||
|
if not owner_team:
|
||||||
|
await interaction.response.send_message(
|
||||||
|
f'I don\'t see a team for you, yet. You can sign up with the `/newteam` command!'
|
||||||
|
)
|
||||||
|
|
||||||
|
p_query = await db_get('players', object_id=player_id, none_okay=False)
|
||||||
|
logging.debug(f'this_player: {p_query}')
|
||||||
|
|
||||||
|
await self.buy_card(interaction, p_query, owner_team)
|
||||||
|
|
||||||
|
@group_buy.command(name='card-by-name', description='Buy a player card from the marketplace')
|
||||||
@app_commands.checks.has_any_role(PD_PLAYERS)
|
@app_commands.checks.has_any_role(PD_PLAYERS)
|
||||||
@app_commands.describe(
|
@app_commands.describe(
|
||||||
player_name='Name of the player you want to purchase',
|
player_name='Name of the player you want to purchase',
|
||||||
@ -711,66 +793,7 @@ class Economy(commands.Cog):
|
|||||||
this_player = p_query['players'][0]
|
this_player = p_query['players'][0]
|
||||||
logging.debug(f'this_player: {this_player}')
|
logging.debug(f'this_player: {this_player}')
|
||||||
|
|
||||||
c_query = await db_get('cards',
|
await self.buy_card(interaction, this_player, owner_team)
|
||||||
params=[('player_id', this_player['player_id']), ('team_id', owner_team["id"])])
|
|
||||||
num_copies = c_query['count'] if c_query else 0
|
|
||||||
|
|
||||||
if not this_player['cardset']['for_purchase']:
|
|
||||||
await interaction.response.send_message(
|
|
||||||
content=f'Ope - looks like singles from the {this_player["cardset"]["name"]} cardset are not available '
|
|
||||||
f'for purchase.'
|
|
||||||
)
|
|
||||||
return
|
|
||||||
if this_player['cost'] > owner_team['wallet']:
|
|
||||||
await interaction.response.send_message(
|
|
||||||
content=None,
|
|
||||||
embeds=await get_card_embeds(get_blank_team_card(this_player))
|
|
||||||
)
|
|
||||||
await interaction.channel.send(
|
|
||||||
content=f'You currently have {num_copies} cop{"ies" if num_copies != 1 else "y"} of this card.\n\n'
|
|
||||||
f'Your Wallet: {owner_team["wallet"]}₼\n'
|
|
||||||
f'Card Price: {this_player["cost"]}₼\n'
|
|
||||||
f'After Purchase: {await get_emoji(interaction.guild, "dead", False)}\n\n'
|
|
||||||
f'You will have to save up a little more.'
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
view = Confirm(responders=[interaction.user])
|
|
||||||
await interaction.response.send_message(
|
|
||||||
content=None,
|
|
||||||
embeds=await get_card_embeds(get_blank_team_card(this_player))
|
|
||||||
)
|
|
||||||
question = await interaction.channel.send(
|
|
||||||
content=f'You currently have {num_copies} cop{"ies" if num_copies != 1 else "y"} of this card.\n\n'
|
|
||||||
f'Your Wallet: {owner_team["wallet"]}₼\n'
|
|
||||||
f'Card Price: {this_player["cost"]}₼\n'
|
|
||||||
f'After Purchase: {owner_team["wallet"] - this_player["cost"]}₼\n\n'
|
|
||||||
f'Would you like to make this purchase?',
|
|
||||||
view=view
|
|
||||||
)
|
|
||||||
await view.wait()
|
|
||||||
|
|
||||||
if not view.value:
|
|
||||||
await question.edit(
|
|
||||||
content='Saving that money. Smart.',
|
|
||||||
view=None
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
purchase = await db_get(
|
|
||||||
f'teams/{owner_team["id"]}/buy/players',
|
|
||||||
params=[('ts', team_hash(owner_team)), ('ids', f'{this_player["player_id"]}')],
|
|
||||||
timeout=10
|
|
||||||
)
|
|
||||||
if not purchase:
|
|
||||||
await question.edit(
|
|
||||||
content=f'That didn\'t go through for some reason. If this happens again, go ping the shit out of Cal.',
|
|
||||||
view=None
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
await question.edit(content=f'It\'s all yours!', view=None)
|
|
||||||
await refresh_sheet(owner_team, self.bot)
|
|
||||||
|
|
||||||
@group_buy.command(name='pack', description='Buy a pack or 7 from the marketplace')
|
@group_buy.command(name='pack', description='Buy a pack or 7 from the marketplace')
|
||||||
@app_commands.checks.has_any_role(PD_PLAYERS)
|
@app_commands.checks.has_any_role(PD_PLAYERS)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user