From 8867cc627f8c107f99fbcbace6a0ebcbd2e7b2ba Mon Sep 17 00:00:00 2001 From: Seaswimmer Date: Tue, 28 May 2024 16:33:15 -0400 Subject: [PATCH] feat(seautils): add an embed to the dig command --- seautils/seautils.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/seautils/seautils.py b/seautils/seautils.py index d2c42b3..15362a7 100644 --- a/seautils/seautils.py +++ b/seautils/seautils.py @@ -8,9 +8,11 @@ import asyncio import inspect import operator +from datetime import datetime from functools import partial, partialmethod from typing import Any +import yaml from discord import Embed, app_commands from discord.utils import CachedSlotProperty, cached_property from redbot.core import commands @@ -99,6 +101,31 @@ class SeaUtils(commands.Cog): process = await asyncio.create_subprocess_exec(*command_opts, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) stdout, stderr = await process.communicate() if stderr: - await ctx.send(content=cf.box(text=stderr.decode())) + await ctx.maybe_send_embed(content= "An error was encountered!\n" + cf.box(text=stderr.decode())) else: - await ctx.send(content=cf.box(text=stdout.decode(), lang='yaml')) + data = yaml.safe_load(stdout.decode()) + message_data = data[0]['message'] + response_data = message_data['response_message_data'] + timestamp = datetime.fromisoformat(message_data['response_time'].replace('Z', '+00:00')) + if ctx.embed_requested(): + embed = Embed( + title="DNS Query Result", + description=f"Query for {response_data['QUESTION_SECTION'][0]}", + color=await ctx.embed_color(), + timestamp=timestamp + ) + embed.add_field(name="Response Address", value=message_data['response_address'], inline=True) + embed.add_field(name="Response Port", value=message_data['response_port'], inline=True) + embed.add_field(name="Query Address", value=message_data['query_address'], inline=True) + embed.add_field(name="Query Port", value=message_data['query_port'], inline=True) + embed.add_field(name="Status", value=response_data['status'], inline=True) + embed.add_field(name="Flags", value=response_data['flags'], inline=True) + + question_section = "\n".join(response_data['QUESTION_SECTION']) + embed.add_field(name="Question Section", value=f"```{question_section}```", inline=False) + + answer_section = "\n".join(response_data['ANSWER_SECTION']) + embed.add_field(name="Answer Section", value=f"```{answer_section}```", inline=False) + await ctx.send(embed=embed) + else: + await ctx.send(content=cf.box(text=stdout, lang='yaml'))