Rework server_logs with asyncpg and use Transformers for arguments
@@ -21,4 +21,24 @@ class TimeTransformer(app_commands.Transformer):
seconds = parse_time(value)
if seconds > 0:
return seconds
- raise app_commands.TransformerError("Invalid time format", discord.AppCommandOptionType.integer, cls)
+ raise app_commands.TransformerError("Invalid time format", discord.AppCommandOptionType.string, cls)
+
+
+class DateTransformer(app_commands.Transformer):
+ @classmethod
+ async def transform(cls, interaction: discord.Interaction, value: str) -> datetime:
+ if(datetime_obj := parse_date(value)) is not None:
+ return datetime_obj
+ raise app_commands.TransformerError("Invalid time format", discord.AppCommandOptionType.string, cls)
+
+
+# Javascript is a cursed language
+class HackIDTransformer(app_commands.Transformer):
+ @classmethod
+ async def transform(cls, interaction: discord.Interaction, value: str) -> int:
+ ctx = await commands.Context.from_interaction(interaction)
+ try:
+ discord_object = await commands.ObjectConverter().convert(ctx, value)
+ return discord_object.id
+ except commands.ObjectNotFound:
+ raise app_commands.TransformerError("Invalid ID", discord.AppCommandOptionType.string, cls)
