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
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run
This commit is contained in:
parent
6cf3ff80ba
commit
67ac390028
2 changed files with 19 additions and 2 deletions
|
@ -308,12 +308,13 @@ class Owner(MixinMeta):
|
||||||
If no value is provided, shows the current setting.
|
If no value is provided, shows the current setting.
|
||||||
"""
|
"""
|
||||||
if enabled is None:
|
if enabled is None:
|
||||||
current = self.db.get_use_skia()
|
current = self.db.use_skia
|
||||||
return await ctx.send(
|
return await ctx.send(
|
||||||
f"Skia image generation is currently {'enabled' if current else 'disabled'}."
|
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(
|
await ctx.send(
|
||||||
f"Skia image generation has been {'enabled' if enabled else 'disabled'}."
|
f"Skia image generation has been {'enabled' if enabled else 'disabled'}."
|
||||||
)
|
)
|
||||||
|
|
|
@ -337,6 +337,7 @@ class DB(Base):
|
||||||
ignored_guilds: t.List[int] = []
|
ignored_guilds: t.List[int] = []
|
||||||
cache_seconds: int = 0 # How long generated profile images should be cached, 0 to disable
|
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
|
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
|
force_embeds: bool = False # Globally force embeds for leveling
|
||||||
internal_api_port: int = 0 # If specified, starts internal api subprocess
|
internal_api_port: int = 0 # If specified, starts internal api subprocess
|
||||||
external_api_url: str = "" # If specified, overrides internal api
|
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
|
gid = guild if isinstance(guild, int) else guild.id
|
||||||
return self.configs.setdefault(gid, GuildSettings())
|
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:
|
def run_migrations(settings: t.Dict[str, t.Any]) -> DB:
|
||||||
"""Sanitize old config data to be validated by the new schema"""
|
"""Sanitize old config data to be validated by the new schema"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue