From 67ac3900282743387f598723de71c01cb45416b3 Mon Sep 17 00:00:00 2001 From: Valerie Date: Mon, 26 May 2025 09:17:11 -0400 Subject: [PATCH] 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. --- levelup/commands/owner.py | 5 +++-- levelup/common/models.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/levelup/commands/owner.py b/levelup/commands/owner.py index 401c260..73a9c5f 100644 --- a/levelup/commands/owner.py +++ b/levelup/commands/owner.py @@ -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'}." ) diff --git a/levelup/common/models.py b/levelup/common/models.py index 22fd3bd..df7d5e3 100644 --- a/levelup/common/models.py +++ b/levelup/common/models.py @@ -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"""