Merge branch 'rewrite' into release
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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)"),
|
||||
}
|
||||
|
||||
@@ -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,6 +185,7 @@ class GuildDashboard(BasePager):
|
||||
# ----- UI Control -----
|
||||
async def reload(self, *args):
|
||||
self._cached_pages.clear()
|
||||
if not self._original.is_expired():
|
||||
await self.redraw()
|
||||
|
||||
async def refresh(self):
|
||||
|
||||
@@ -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
|
||||
)
|
||||
|
||||
@@ -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 "
|
||||
|
||||
@@ -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