feat(seautils): add an embed to the dig command

This commit is contained in:
Seaswimmer 2024-05-28 16:33:15 -04:00
parent e2059eac77
commit 8867cc627f
Signed by untrusted user: cswimr
GPG key ID: 5D671B5D03D65A7F

View file

@ -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'))