fix (timers): Dynamic timer locale.
This commit is contained in:
@@ -20,8 +20,7 @@ from .graphics import get_timer_card
|
||||
from .lib import TimerRole, channel_name_keys, focus_alert_path, break_alert_path
|
||||
from .options import TimerConfig, TimerOptions
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from babel.cog import LocaleSettings
|
||||
from babel.settings import LocaleSettings
|
||||
|
||||
_p, _np = babel._p, babel._np
|
||||
|
||||
@@ -34,7 +33,6 @@ class Timer:
|
||||
'bot',
|
||||
'data',
|
||||
'lguild',
|
||||
'locale',
|
||||
'config',
|
||||
'last_seen',
|
||||
'status_view',
|
||||
@@ -56,7 +54,6 @@ class Timer:
|
||||
self.bot = bot
|
||||
self.data = data
|
||||
self.lguild = lguild
|
||||
self.locale: LocaleSettings.GuildLocale = lguild.config.get('guild_locale')
|
||||
self.config = TimerConfig(data.channelid, data)
|
||||
|
||||
log_context.set(f"tid: {self.data.channelid}")
|
||||
@@ -96,7 +93,10 @@ class Timer:
|
||||
">"
|
||||
)
|
||||
|
||||
# Consider exposing configurable settings through a Settings interface, for ease of formatting.
|
||||
@property
|
||||
def locale(self) -> LocaleSettings.GuildLocale:
|
||||
return self.lguild.config.get(LocaleSettings.GuildLocale.setting_id)
|
||||
|
||||
@property
|
||||
def auto_restart(self) -> bool:
|
||||
"""
|
||||
|
||||
@@ -30,8 +30,7 @@ class TimerStatusUI(LeoUI):
|
||||
def __init__(self, bot: LionBot, timer: 'Timer', channel: discord.abc.GuildChannel, show_present=True, **kwargs):
|
||||
# Set the locale context before it is copied in LeoUI
|
||||
# This is propagated via dispatch to component handlers
|
||||
self.locale = timer.locale.value
|
||||
ctx_locale.set(self.locale)
|
||||
ctx_locale.set(timer.locale.value)
|
||||
super().__init__(timeout=None, **kwargs)
|
||||
|
||||
self.bot = bot
|
||||
@@ -39,6 +38,10 @@ class TimerStatusUI(LeoUI):
|
||||
self.channel = channel
|
||||
self.show_present = show_present
|
||||
|
||||
@property
|
||||
def locale(self):
|
||||
return self.timer.locale.value
|
||||
|
||||
@button(label="PRESENT_PLACEHOLDER", emoji=conf.emojis.tick, style=ButtonStyle.green)
|
||||
async def present_button(self, press: discord.Interaction, pressed: Button):
|
||||
"""
|
||||
@@ -46,6 +49,7 @@ class TimerStatusUI(LeoUI):
|
||||
|
||||
Does not send a visible response.
|
||||
"""
|
||||
ctx_locale.set(self.locale)
|
||||
t = self.bot.translator.t
|
||||
member: discord.Member = press.user
|
||||
if member.voice and member.voice.channel and member.voice.channel.id == self.timer.data.channelid:
|
||||
@@ -83,6 +87,7 @@ class TimerStatusUI(LeoUI):
|
||||
"""
|
||||
Pressed to edit the timer. Response depends on role-level of user.
|
||||
"""
|
||||
ctx_locale.set(self.locale)
|
||||
role = self.timer.get_member_role(press.user)
|
||||
if role >= TimerRole.OWNER:
|
||||
# Open ephemeral config UI
|
||||
@@ -119,6 +124,7 @@ class TimerStatusUI(LeoUI):
|
||||
"""
|
||||
Start a stopped timer.
|
||||
"""
|
||||
ctx_locale.set(self.locale)
|
||||
t = self.bot.translator.t
|
||||
|
||||
if self.timer.running:
|
||||
@@ -169,6 +175,7 @@ class TimerStatusUI(LeoUI):
|
||||
|
||||
Note that unlike starting, stopping is allowed to be idempotent.
|
||||
"""
|
||||
ctx_locale.set(self.locale)
|
||||
t = self.bot.translator.t
|
||||
role = self.timer.get_member_role(press.user)
|
||||
if role >= TimerRole.MANAGER:
|
||||
@@ -201,6 +208,7 @@ class TimerStatusUI(LeoUI):
|
||||
"""
|
||||
Refresh the internal UI components based on the current state of the Timer.
|
||||
"""
|
||||
ctx_locale.set(self.locale)
|
||||
await asyncio.gather(
|
||||
self.refresh_present_button(),
|
||||
self.refresh_edit_button(),
|
||||
|
||||
Reference in New Issue
Block a user