Skip to content

Commit

Permalink
[settings] make the favorited collectible emoji customisable (Ballsde…
Browse files Browse the repository at this point in the history
…x-Team#499)

* make the favorited countryball emoji customisable

* appease isort

* copy change to admin panel models too

---------

Co-authored-by: Jamie <[email protected]>
Co-authored-by: flaree <[email protected]>
  • Loading branch information
3 people authored Feb 6, 2025
1 parent d81e376 commit 7b525c2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
4 changes: 3 additions & 1 deletion admin_panel/bd_models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
from django.utils.safestring import SafeText, mark_safe
from django.utils.timezone import now

from ballsdex.settings import settings


def transform_media(path: str) -> str:
return path.replace("/static/uploads/", "").replace(
Expand Down Expand Up @@ -292,7 +294,7 @@ def __str__(self) -> str:
if self.locked and self.locked > now() - timedelta(minutes=30):
text += "🔒"
if self.favorite:
text += "❤️"
text += settings.favorited_collectible_emoji
if text:
text += " "
if self.special:
Expand Down
3 changes: 2 additions & 1 deletion ballsdex/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from tortoise.expressions import Q

from ballsdex.core.image_generator.image_gen import draw_card
from ballsdex.settings import settings

if TYPE_CHECKING:
from tortoise.backends.base.client import BaseDBAsyncClient
Expand Down Expand Up @@ -276,7 +277,7 @@ def to_string(self, bot: discord.Client | None = None, is_trade: bool = False) -
if bot and self.pk in bot.locked_balls and not is_trade: # type: ignore
emotes += "🔒"
if self.favorite and not is_trade:
emotes += "❤️"
emotes += settings.favorited_collectible_emoji
if emotes:
emotes += " "
if self.specialcard:
Expand Down
3 changes: 2 additions & 1 deletion ballsdex/packages/balls/countryballs_paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from ballsdex.core.models import BallInstance
from ballsdex.core.utils import menus
from ballsdex.core.utils.paginator import Pages
from ballsdex.settings import settings

if TYPE_CHECKING:
from ballsdex.core.bot import BallsDexBot
Expand All @@ -32,7 +33,7 @@ def set_options(self, balls: List[BallInstance]):
options: List[discord.SelectOption] = []
for ball in balls:
emoji = self.bot.get_emoji(int(ball.countryball.emoji_id))
favorite = "❤️ " if ball.favorite else ""
favorite = f"{settings.favorited_collectible_emoji} " if ball.favorite else ""
special = ball.special_emoji(self.bot, True)
options.append(
discord.SelectOption(
Expand Down
2 changes: 1 addition & 1 deletion ballsdex/packages/trade/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def set_options(self, balls: List[BallInstance]):
if ball.is_tradeable is False:
continue
emoji = self.bot.get_emoji(int(ball.countryball.emoji_id))
favorite = "❤️ " if ball.favorite else ""
favorite = f"{settings.favorited_collectible_emoji} " if ball.favorite else ""
special = ball.special_emoji(self.bot, True)
options.append(
discord.SelectOption(
Expand Down
9 changes: 8 additions & 1 deletion ballsdex/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class Settings:
Usually "BallsDex", can be replaced when possible
players_group_cog_name: str
Set the name of the base command of the "players" cog, /balls by default
max_favorites:
favorited_collectible_emoji: str
Set the emoji used to represent a favorited countryball, "❤️" by default.
max_favorites: int
Set the maximum amount of favorited countryballs a user can have, 50 by default.
max_attack_bonus:
Set the biggest/smallest attack bonus that a spawned countryball can have.
Expand Down Expand Up @@ -77,6 +79,7 @@ class Settings:
plural_collectible_name: str = "countryballs"
bot_name: str = "BallsDex"
players_group_cog_name: str = "balls"
favorited_collectible_emoji: str = "❤️"

max_favorites: int = 50
max_attack_bonus: int = 20
Expand Down Expand Up @@ -134,6 +137,7 @@ def read_settings(path: "Path"):
)
settings.bot_name = content["bot-name"]
settings.players_group_cog_name = content["players-group-cog-name"]
settings.favorited_collectible_emoji = content.get("favorited-collectible-emoji", "❤️")

settings.about_description = content["about"]["description"]
settings.github_link = content["about"]["github-link"]
Expand Down Expand Up @@ -221,6 +225,9 @@ def write_default_settings(path: "Path"):
# this is /balls by default, but you can change it for /animals or /rocks for example
players-group-cog-name: balls
# emoji used to represent a favorited collectible
favorited-collectible-emoji: ❤️
# maximum amount of favorites that are allowed
max-favorites: 50
Expand Down
5 changes: 5 additions & 0 deletions json-config-ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@
"description": "Maximum number of favorite countryballs allowed per player",
"minimum": 0
},
"favorited-collectible-emoji": {
"type": "string",
"default": "❤️",
"description": "The emoji used to represent a favorited countryball"
},
"max-attack-bonus": {
"type": "integer",
"description": "The biggest/smallest attack bonus that a spawned countryball can have.",
Expand Down

0 comments on commit 7b525c2

Please sign in to comment.