From 5a152e9be7bee32721e6e98f952e0b64c6da5dc1 Mon Sep 17 00:00:00 2001 From: Conatum Date: Mon, 28 Aug 2023 22:04:36 +0300 Subject: [PATCH 1/2] fix (config): Control dash field lengths. --- src/constants.py | 2 ++ src/core/setting_types.py | 2 +- src/modules/config/dashboard.py | 34 +++++++++++++++++++++++---- src/modules/member_admin/settingui.py | 32 +++++++++++++++++++++++++ src/utils/ui/config.py | 12 ++++++++-- 5 files changed, 75 insertions(+), 7 deletions(-) diff --git a/src/constants.py b/src/constants.py index 5c85e741..87b445d1 100644 --- a/src/constants.py +++ b/src/constants.py @@ -2,3 +2,5 @@ CONFIG_FILE = "config/bot.conf" DATA_VERSION = 13 MAX_COINS = 2147483647 - 1 + +HINT_ICON = "https://projects.iamcal.com/emoji-data/img-apple-64/1f4a1.png" diff --git a/src/core/setting_types.py b/src/core/setting_types.py index fdfb26ac..7bc1710d 100644 --- a/src/core/setting_types.py +++ b/src/core/setting_types.py @@ -262,7 +262,7 @@ class MessageSetting(StringSetting): value = cls._data_to_value(parent_id, data, **kwargs) content = value.get('content', "") - if 'embed' in value or 'embeds' in value or len(content) > 1024: + if 'embed' in value or 'embeds' in value or len(content) > 100: t = ctx_translator.get().t formatted = t(_p( 'settype:message|format:too_long', diff --git a/src/modules/config/dashboard.py b/src/modules/config/dashboard.py index fb67069a..63e5c9b5 100644 --- a/src/modules/config/dashboard.py +++ b/src/modules/config/dashboard.py @@ -4,8 +4,9 @@ import discord from discord.ui.select import select, Select, SelectOption from discord.ui.button import button, Button, ButtonStyle +from constants import HINT_ICON from meta import conf, LionBot -from utils.lib import MessageArgs +from utils.lib import MessageArgs, utc_now from utils.ui import BasePager from modules.economy.settingui import EconomyDashboard @@ -72,6 +73,16 @@ class GuildDashboard(BasePager): instance.deregister_callback(self.id) self._listening.clear() + try: + if self._original is not None and not self._original.is_expired(): + await self._original.edit_original_response(view=None) + self._original = None + if self._message is not None: + await self._message.edit(view=None) + self._message = None + except discord.HTTPException: + pass + await super().cleanup() # ----- Pager Control ----- @@ -80,10 +91,24 @@ class GuildDashboard(BasePager): if (page := self._cached_pages.get(page_id, None)) is not None: pass else: + t = self.bot.translator.t # Format settings into a dashboard embed + dashboard_title = t(_p( + 'ui:dashboard|title', + "Guild Dashboard (Page {page}/{total})" + )).format(page=page_id + 1, total=len(self.pages)) + embed = discord.Embed( - title="Guild Dashboard", - colour=discord.Colour.orange() + title=dashboard_title, + colour=discord.Colour.orange(), + timestamp=utc_now() + ) + embed.set_footer( + text=t(_p( + 'ui:dashboard|footer', + "Hover over setting names for a brief description" + )), + icon_url=HINT_ICON ) section_classes = self.pages[page_id] @@ -160,7 +185,8 @@ class GuildDashboard(BasePager): # ----- UI Control ----- async def reload(self, *args): self._cached_pages.clear() - await self.redraw() + if not self._original.is_expired(): + await self.redraw() async def refresh(self): await super().refresh() diff --git a/src/modules/member_admin/settingui.py b/src/modules/member_admin/settingui.py index 5c9959cb..cf08a161 100644 --- a/src/modules/member_admin/settingui.py +++ b/src/modules/member_admin/settingui.py @@ -262,3 +262,35 @@ class MemberAdminDashboard(DashboardSection): ) configui = MemberAdminUI setting_classes = MemberAdminUI.setting_classes + + def apply_to(self, page: discord.Embed): + """ + Overriding DashboardSection apply_to to split into two sections. + """ + t = self.bot.translator.t + sections = [ + self.instances[:3], + self.instances[3:] + ] + + # Greeting messages + table = self._make_table(sections[0]) + page.add_field( + name=t(_p( + 'dash:member_admin|section:greeting_messages|name', + "Greeting Messages ({commands[configure welcome]})" + )).format(commands=self.bot.core.mention_cache), + value=table, + inline=False + ) + + # Initial Roles + table = self._make_table(sections[1]) + page.add_field( + name=t(_p( + 'dash:member_admin|section:initial_roles|name', + "Initial Roles ({commands[configure welcome]})" + )).format(commands=self.bot.core.mention_cache), + value=table, + inline=False + ) diff --git a/src/utils/ui/config.py b/src/utils/ui/config.py index a126c0cd..59dd4a98 100644 --- a/src/utils/ui/config.py +++ b/src/utils/ui/config.py @@ -300,7 +300,6 @@ class DashboardSection: commands=self.bot.core.mention_cache ) - async def load(self): """ Initialise the contained settings. @@ -322,9 +321,18 @@ class DashboardSection: # TODO: Header/description field table = self.make_table() + if len(table) > 1024: + value = t(_p( + 'ui:dashboard|error:section_too_long', + "Oops, the settings in this configuration section are too large, " + "and I can not display them here! " + "Please view the settings in the linked configuration panel instead." + )) + else: + value = table page.add_field( name=t(self.section_name).format(bot=self.bot, commands=self.bot.core.mention_cache), - value=table, + value=value, inline=False ) From 6da2c762adf096877e9612adf491206057b8e99c Mon Sep 17 00:00:00 2001 From: Conatum Date: Mon, 28 Aug 2023 22:41:25 +0300 Subject: [PATCH 2/2] fix (babel): Fix missing localisations. --- src/babel/cog.py | 2 +- src/babel/enums.py | 3 +++ src/modules/pomodoro/timer.py | 19 ++++++++++++++----- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/babel/cog.py b/src/babel/cog.py index e25e945c..bd535a3e 100644 --- a/src/babel/cog.py +++ b/src/babel/cog.py @@ -230,7 +230,7 @@ class BabelCog(LionCog): supported = self.bot.translator.supported_locales formatted = [] for locale in supported: - name = locale_names.get(locale, None) + name = locale_names.get(locale.replace('_', '-'), None) if name: localestr = f"{locale} ({t(name)})" else: diff --git a/src/babel/enums.py b/src/babel/enums.py index 90285985..6ab77a74 100644 --- a/src/babel/enums.py +++ b/src/babel/enums.py @@ -35,6 +35,7 @@ class LocaleMap(Enum): turkish = 'tr' ukrainian = 'uk' vietnamese = 'vi' + hebrew = 'he-IL' locale_names = { @@ -68,4 +69,6 @@ locale_names = { 'tr': _p('localenames|locale:tr', "Turkish"), 'uk': _p('localenames|locale:uk', "Ukrainian"), 'vi': _p('localenames|locale:vi', "Vietnamese"), + 'he': _p('localenames|locale:he', "Hebrew"), + 'he-IL': _p('localenames|locale:he_IL', "Hebrew (Israel)"), } diff --git a/src/modules/pomodoro/timer.py b/src/modules/pomodoro/timer.py index f199931c..b53ecc96 100644 --- a/src/modules/pomodoro/timer.py +++ b/src/modules/pomodoro/timer.py @@ -142,14 +142,22 @@ class Timer: if not hook: # Attempt to create and save webhook # TODO: Localise + t = self.bot.translator.t + ctx_locale.set(self.locale.value) try: if channel.permissions_for(channel.guild.me).manage_webhooks: avatar = self.bot.user.avatar avatar_data = (await avatar.to_file()).fp.read() if avatar else None webhook = await channel.create_webhook( avatar=avatar_data, - name=f"{self.bot.user.name} Pomodoro", - reason="Pomodoro Notifications" + name=t(_p( + 'timer|webhook|name', + "{bot_name} Pomodoro" + )).format(bot_name=self.bot.user.name), + reason=t(_p( + 'timer|webhook|audit_reason', + "Pomodoro Notifications" + )) ) hook = await self.bot.core.data.LionHook.create( channelid=channel.id, @@ -157,9 +165,10 @@ class Timer: webhookid=webhook.id ) elif channel.permissions_for(channel.guild.me).send_messages: - await channel.send( - "I require the `manage_webhooks` permission to send pomodoro notifications here!" - ) + await channel.send(t(_p( + 'timer|webhook|error:insufficient_permissions', + "I require the `MANAGE_WEBHOOKS` permission to send pomodoro notifications here!" + ))) except discord.HTTPException: logger.warning( "Unexpected Exception caught while creating timer notification webhook "