rewrite: New 'Member Admin' module.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from typing import NamedTuple, Optional, Sequence, Union, overload, List
|
||||
import collections
|
||||
import datetime
|
||||
import iso8601 # type: ignore
|
||||
import pytz
|
||||
@@ -788,3 +789,18 @@ def emojikey(emoji: discord.Emoji | discord.PartialEmoji | str):
|
||||
key = str(emoji)
|
||||
|
||||
return key
|
||||
|
||||
def recurse_map(func, obj, loc=[]):
|
||||
if isinstance(obj, dict):
|
||||
for k, v in obj.items():
|
||||
loc.append(k)
|
||||
obj[k] = recurse_map(func, v, loc)
|
||||
loc.pop()
|
||||
elif isinstance(obj, list):
|
||||
for i, item in enumerate(obj):
|
||||
loc.append(i)
|
||||
obj[i] = recurse_map(func, item)
|
||||
loc.pop()
|
||||
else:
|
||||
obj = func(loc, obj)
|
||||
return obj
|
||||
|
||||
@@ -56,6 +56,10 @@ class ConfigUI(LeoUI):
|
||||
def page_instances(self):
|
||||
return self.instances
|
||||
|
||||
def get_instance(self, setting_cls):
|
||||
setting_id = setting_cls.setting_id
|
||||
return next(instance for instance in self.instances if instance.setting_id == setting_id)
|
||||
|
||||
async def interaction_check(self, interaction: discord.Interaction):
|
||||
"""
|
||||
Default requirement for a Config UI is low management (i.e. manage_guild permissions).
|
||||
@@ -102,7 +106,7 @@ class ConfigUI(LeoUI):
|
||||
instances = self.page_instances
|
||||
items = [setting.input_field for setting in instances]
|
||||
# Filter out settings which don't have input fields
|
||||
items = [item for item in items if item]
|
||||
items = [item for item in items if item][:5]
|
||||
strings = [item.value for item in items]
|
||||
modal = ConfigEditor(*items, title=t(self.edit_modal_title))
|
||||
|
||||
@@ -313,8 +317,11 @@ class DashboardSection:
|
||||
)
|
||||
|
||||
def make_table(self):
|
||||
return self._make_table(self.instances)
|
||||
|
||||
def _make_table(self, instances):
|
||||
rows = []
|
||||
for setting in self.instances:
|
||||
for setting in instances:
|
||||
name = setting.display_name
|
||||
value = setting.formatted
|
||||
rows.append((name, value, setting.desc))
|
||||
|
||||
@@ -12,8 +12,6 @@ from discord.ui.text_input import TextInput, TextStyle
|
||||
|
||||
from meta import conf, LionBot
|
||||
from meta.errors import UserInputError, ResponseTimedOut
|
||||
from utils.lib import error_embed
|
||||
from babel.translator import ctx_translator, LazyStr
|
||||
|
||||
from ..lib import MessageArgs, utc_now
|
||||
|
||||
@@ -49,8 +47,14 @@ class MsgEditor(MessageUI):
|
||||
|
||||
# ----- API -----
|
||||
async def format_data(self, data):
|
||||
"""
|
||||
Format a MessageData dict for rendering.
|
||||
|
||||
May be extended or overridden for custom formatting.
|
||||
By default, uses the provided `formatter` callback (if provided).
|
||||
"""
|
||||
if self._formatter is not None:
|
||||
self._formatter(data)
|
||||
await self._formatter(data)
|
||||
|
||||
def copy_data(self):
|
||||
return copy.deepcopy(self.history[-1])
|
||||
@@ -567,12 +571,13 @@ class MsgEditor(MessageUI):
|
||||
style=TextStyle.short,
|
||||
required=True,
|
||||
max_length=256,
|
||||
default='True',
|
||||
)
|
||||
|
||||
modal = MsgEditorInput(
|
||||
position_field,
|
||||
name_field,
|
||||
value_field,
|
||||
position_field,
|
||||
inline_field,
|
||||
title=t(_p('ui:msg_editor|modal:add_field|title', "Add Embed Field"))
|
||||
)
|
||||
@@ -1005,6 +1010,7 @@ class MsgEditor(MessageUI):
|
||||
async def cont_button(interaction: discord.Interaction, pressed):
|
||||
await interaction.response.defer()
|
||||
await interaction.message.delete()
|
||||
nonlocal stopped
|
||||
stopped = True
|
||||
# TODO: Clean up this mess. It works, but needs to be refactored to a timeout confirmation mixin.
|
||||
# TODO: Consider moving the message to the interaction response
|
||||
|
||||
Reference in New Issue
Block a user