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