(msgeditor): Support formatted timestamp.
This commit is contained in:
@@ -54,7 +54,10 @@ class MsgEditor(MessageUI):
|
|||||||
By default, uses the provided `formatter` callback (if provided).
|
By default, uses the provided `formatter` callback (if provided).
|
||||||
"""
|
"""
|
||||||
if self._formatter is not None:
|
if self._formatter is not None:
|
||||||
await self._formatter(data)
|
return await self._formatter(data)
|
||||||
|
else:
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def copy_data(self):
|
def copy_data(self):
|
||||||
return copy.deepcopy(self.history[-1])
|
return copy.deepcopy(self.history[-1])
|
||||||
@@ -78,7 +81,8 @@ class MsgEditor(MessageUI):
|
|||||||
|
|
||||||
if 'embed' in new_data:
|
if 'embed' in new_data:
|
||||||
try:
|
try:
|
||||||
discord.Embed.from_dict(new_data['embed'])
|
formatted_data = copy.deepcopy(new_data)
|
||||||
|
discord.Embed.from_dict(await self.format_data(formatted_data['embed']))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise UserInputError(
|
raise UserInputError(
|
||||||
t(_p(
|
t(_p(
|
||||||
@@ -445,8 +449,17 @@ class MsgEditor(MessageUI):
|
|||||||
embed_data.pop('footer', None)
|
embed_data.pop('footer', None)
|
||||||
|
|
||||||
if (ts := timestamp_field.value):
|
if (ts := timestamp_field.value):
|
||||||
|
if ts.isdigit():
|
||||||
|
# Treat as UTC timestamp
|
||||||
|
timestamp = dt.datetime.fromtimestamp(int(ts), dt.timezone.utc)
|
||||||
|
ts = timestamp.isoformat()
|
||||||
|
to_validate = ts
|
||||||
|
elif self._formatter:
|
||||||
|
to_validate = await self._formatter(ts)
|
||||||
|
else:
|
||||||
|
to_validate = ts
|
||||||
try:
|
try:
|
||||||
dt.datetime.fromisoformat(ts)
|
dt.datetime.fromisoformat(to_validate)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise UserInputError(
|
raise UserInputError(
|
||||||
t(_p(
|
t(_p(
|
||||||
|
|||||||
Reference in New Issue
Block a user