From 5a152e9be7bee32721e6e98f952e0b64c6da5dc1 Mon Sep 17 00:00:00 2001 From: Conatum Date: Mon, 28 Aug 2023 22:04:36 +0300 Subject: [PATCH] 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 )