Refactor Skia image generation handling in DB model and Owner command to streamline property access and improve code clarity. Update the Owner command to directly manipulate the use_skia attribute, enhancing performance and maintainability.
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run

This commit is contained in:
Valerie 2025-05-26 09:17:11 -04:00
parent 6cf3ff80ba
commit 67ac390028
2 changed files with 19 additions and 2 deletions

View file

@ -308,12 +308,13 @@ class Owner(MixinMeta):
If no value is provided, shows the current setting.
"""
if enabled is None:
current = self.db.get_use_skia()
current = self.db.use_skia
return await ctx.send(
f"Skia image generation is currently {'enabled' if current else 'disabled'}."
)
self.db.set_use_skia(enabled)
self.db.use_skia = enabled
self.save()
await ctx.send(
f"Skia image generation has been {'enabled' if enabled else 'disabled'}."
)

View file

@ -337,6 +337,7 @@ class DB(Base):
ignored_guilds: t.List[int] = []
cache_seconds: int = 0 # How long generated profile images should be cached, 0 to disable
render_gifs: bool = False # Whether to render profiles as gifs
use_skia: bool = True # Whether to use Skia for image generation
force_embeds: bool = False # Globally force embeds for leveling
internal_api_port: int = 0 # If specified, starts internal api subprocess
external_api_url: str = "" # If specified, overrides internal api
@ -347,6 +348,21 @@ class DB(Base):
gid = guild if isinstance(guild, int) else guild.id
return self.configs.setdefault(gid, GuildSettings())
@property
def get_use_skia(self) -> bool:
"""Get whether to use Skia for image generation."""
return self.use_skia
@property
def set_use_skia(self) -> bool:
"""Get whether to use Skia for image generation."""
return self.use_skia
@set_use_skia.setter
def set_use_skia(self, value: bool):
"""Set whether to use Skia for image generation."""
self.use_skia = value
def run_migrations(settings: t.Dict[str, t.Any]) -> DB:
"""Sanitize old config data to be validated by the new schema"""