-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a currency along with various uses #296
base: master
Are you sure you want to change the base?
Changes from all commits
de1ab70
ec7b71d
3c2d869
56d7b0e
c25a36a
ba3cb9a
d0398de
710c995
2c320a7
4650679
fb28805
c112f22
6e48da8
374a8ad
e412be0
ebc4fad
856287a
12163dc
710120e
1aaca24
0f4bfb7
e5663ea
b75d286
ab3f5d3
f432b4e
9a421ad
e076313
6c3fe13
f40926d
91c0b06
f3deb78
1034f6d
84b80ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,6 +316,7 @@ class PlayerResource(Model): | |
"balls", | ||
"donation_policy", | ||
"privacy_policy", | ||
"coins", | ||
] | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -90,6 +90,7 @@ def __init__(self, bot: "BallsDexBot"): | |||||||||||||
logs = app_commands.Group(name="logs", description="Bot logs management") | ||||||||||||||
history = app_commands.Group(name="history", description="Trade history management") | ||||||||||||||
info = app_commands.Group(name="info", description="Information Commands") | ||||||||||||||
coins = app_commands.Group(name=settings.currency_name, description="Coins management") | ||||||||||||||
|
||||||||||||||
@app_commands.command() | ||||||||||||||
@app_commands.checks.has_any_role(*settings.root_role_ids) | ||||||||||||||
|
@@ -1552,3 +1553,125 @@ async def user( | |||||||||||||
) | ||||||||||||||
embed.set_thumbnail(url=user.display_avatar) # type: ignore | ||||||||||||||
await interaction.followup.send(embed=embed, ephemeral=True) | ||||||||||||||
|
||||||||||||||
@coins.command() | ||||||||||||||
@app_commands.checks.has_any_role(*settings.root_role_ids) | ||||||||||||||
async def add( | ||||||||||||||
self, | ||||||||||||||
interaction: discord.Interaction, | ||||||||||||||
user: discord.User | None = None, | ||||||||||||||
user_id: str | None = None, | ||||||||||||||
amount: int = 0, | ||||||||||||||
Comment on lines
+1562
to
+1564
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||
): | ||||||||||||||
""" | ||||||||||||||
Add coins to a user. | ||||||||||||||
|
||||||||||||||
Parameters | ||||||||||||||
---------- | ||||||||||||||
user: discord.User | None | ||||||||||||||
The user you want to add coins to. | ||||||||||||||
user_id: str | None | ||||||||||||||
The ID of the user you want to add coins to. | ||||||||||||||
amount: int | ||||||||||||||
The number of coins to add. | ||||||||||||||
""" | ||||||||||||||
if (user is None and user_id is None) or (user is not None and user_id is not None): | ||||||||||||||
await interaction.response.send_message( | ||||||||||||||
"You must provide either `user` or `user_id`", ephemeral=True | ||||||||||||||
) | ||||||||||||||
return | ||||||||||||||
|
||||||||||||||
if amount < 0: | ||||||||||||||
await interaction.response.send_message( | ||||||||||||||
f"The amount of {settings.currency_name} " "to add cannot be negative.", | ||||||||||||||
ephemeral=True, | ||||||||||||||
) | ||||||||||||||
return | ||||||||||||||
|
||||||||||||||
if user_id is not None: | ||||||||||||||
try: | ||||||||||||||
user = await self.bot.fetch_user(int(user_id)) | ||||||||||||||
except ValueError: | ||||||||||||||
await interaction.response.send_message( | ||||||||||||||
"The user ID you provided is not valid.", ephemeral=True | ||||||||||||||
) | ||||||||||||||
return | ||||||||||||||
except discord.NotFound: | ||||||||||||||
await interaction.response.send_message( | ||||||||||||||
"The given user ID could not be found.", ephemeral=True | ||||||||||||||
) | ||||||||||||||
return | ||||||||||||||
|
||||||||||||||
assert user | ||||||||||||||
player, created = await Player.get_or_create(discord_id=user.id) | ||||||||||||||
await player.add_coins(amount) | ||||||||||||||
await interaction.response.send_message( | ||||||||||||||
f"Added {amount} {settings.currency_name} to {user.name}.", ephemeral=True | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
await log_action( | ||||||||||||||
f"{interaction.user} added {amount} {settings.currency_name} " | ||||||||||||||
f"to {user.name} ({user.id}).", | ||||||||||||||
self.bot, | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
@coins.command() | ||||||||||||||
@app_commands.checks.has_any_role(*settings.root_role_ids) | ||||||||||||||
async def remove( | ||||||||||||||
self, | ||||||||||||||
interaction: discord.Interaction, | ||||||||||||||
user: discord.User | None = None, | ||||||||||||||
user_id: str | None = None, | ||||||||||||||
amount: int = 0, | ||||||||||||||
Comment on lines
+1623
to
+1625
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here
Suggested change
|
||||||||||||||
): | ||||||||||||||
""" | ||||||||||||||
Remove coins from a user. | ||||||||||||||
|
||||||||||||||
Parameters | ||||||||||||||
---------- | ||||||||||||||
user: discord.User | None | ||||||||||||||
The user you want to remove coins from. | ||||||||||||||
user_id: str | None | ||||||||||||||
The ID of the user you want to remove coins from. | ||||||||||||||
amount: int | ||||||||||||||
The number of coins to remove. | ||||||||||||||
""" | ||||||||||||||
if (user is None and user_id is None) or (user is not None and user_id is not None): | ||||||||||||||
await interaction.response.send_message( | ||||||||||||||
"You must provide either `user` or `user_id`", ephemeral=True | ||||||||||||||
) | ||||||||||||||
return | ||||||||||||||
|
||||||||||||||
if amount < 0: | ||||||||||||||
await interaction.response.send_message( | ||||||||||||||
f"The amount of {settings.currency_name} " "to remove cannot be negative.", | ||||||||||||||
ephemeral=True, | ||||||||||||||
) | ||||||||||||||
return | ||||||||||||||
|
||||||||||||||
if user_id is not None: | ||||||||||||||
try: | ||||||||||||||
user = await self.bot.fetch_user(int(user_id)) | ||||||||||||||
except ValueError: | ||||||||||||||
await interaction.response.send_message( | ||||||||||||||
"The user ID you provided is not valid.", ephemeral=True | ||||||||||||||
) | ||||||||||||||
return | ||||||||||||||
except discord.NotFound: | ||||||||||||||
await interaction.response.send_message( | ||||||||||||||
"The given user ID could not be found.", ephemeral=True | ||||||||||||||
) | ||||||||||||||
return | ||||||||||||||
|
||||||||||||||
assert user | ||||||||||||||
player, created = await Player.get_or_create(discord_id=user.id) | ||||||||||||||
await player.remove_coins(amount) | ||||||||||||||
await interaction.response.send_message( | ||||||||||||||
f"Removed {amount} {settings.currency_name} to {user.name}.", ephemeral=True | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
await log_action( | ||||||||||||||
f"{interaction.user} removed {amount} {settings.currency_name} " | ||||||||||||||
f"to {user.name} ({user.id}).", | ||||||||||||||
self.bot, | ||||||||||||||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -660,3 +660,41 @@ async def count( | |
f"You have {balls} {special_str}{shiny_str}" | ||
f"{country}{settings.collectible_name}{plural}{guild}." | ||
) | ||
|
||
@app_commands.command() | ||
async def dispose(self, interaction: discord.Interaction, ball: BallInstanceTransform): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"""Dispose a countryball for coins. | ||
|
||
Parameters | ||
---------- | ||
ball: BallInstance | ||
The countryball you want to dispose of.""" | ||
if not ball: | ||
return | ||
if not ball.countryball.enabled or not ball.is_tradeable: | ||
await interaction.response.send_message( | ||
f"You cannot dispose of this {settings.collectible_name}.", ephemeral=True | ||
) | ||
return | ||
await interaction.response.defer() | ||
coins = ball.countryball.coin_amount // 2 | ||
view = ConfirmChoiceView(interaction) | ||
await interaction.followup.send( | ||
f"Are you sure you want to dispose of the {settings.collectible_name} " | ||
f"{ball.description(include_emoji=True, bot=self.bot)} " | ||
f"for {coins} {settings.currency_name}?", | ||
view=view, | ||
ephemeral=True, | ||
) | ||
await view.wait() | ||
if not view.value: | ||
return | ||
player = await Player.get(discord_id=interaction.user.id) | ||
await player.add_coins(coins) | ||
message = ( | ||
f"You disposed of the {settings.collectible_name} " | ||
f"{ball.description(include_emoji=True, bot=self.bot)} " | ||
f"for {coins} {settings.currency_name}." | ||
) | ||
await ball.delete() | ||
await interaction.followup.send(message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add_coins
andremove_coins
should probably return some output on its status as confirmation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think raising an error is appropriate as a way to confirm things went well