fix (config): Control dash field lengths.
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user