diff --git a/src/cogs/net.py b/src/cogs/net.py index 188f096..7755d44 100644 --- a/src/cogs/net.py +++ b/src/cogs/net.py @@ -16,6 +16,25 @@ from rich.tree import Tree from conf import CONFIG +class GetFilteredTextView(discord.ui.View): + def __init__(self, text: str): + self.text = text + super().__init__(timeout=600) + + @discord.ui.button( + label="See filtered data", + emoji="\N{INBOX TRAY}" + ) + async def see_filtered_data(self, _, interaction: discord.Interaction): + await interaction.response.defer(ephemeral=True) + await interaction.followup.send( + file=discord.File( + io.BytesIO(self.text.encode()), + "filtered.txt" + ) + ) + + class NetworkCog(commands.Cog): def __init__(self, bot: commands.Bot): self.bot = bot @@ -107,14 +126,16 @@ class NetworkCog(commands.Cog): file.write(stderr) file.seek(0) return await ctx.respond( - "Seemingly all output was filtered. Returning raw command output.", file=discord.File(file, "whois.txt") + "Seemingly all output was filtered. Returning raw command output.", + file=discord.File(file, "whois.txt") ) + last: discord.Interaction | discord.WebhookMessage | None = None for page in paginator.pages: - await ctx.respond(page) - if redacted.getvalue(): - redacted.seek(0) - await ctx.respond(file=discord.File(redacted, "redacted.txt")) + last = await ctx.respond(page) + if last and redacted.tell(): + view = GetFilteredTextView(redacted.getvalue().decode()) + await last.edit(view=view) @commands.slash_command() async def dig( @@ -163,7 +184,7 @@ class NetworkCog(commands.Cog): with console.capture() as capture: console.print(tree) text = capture.get() - paginator = commands.Paginator(prefix="```", suffix="```") + paginator = commands.Paginator() for line in text.splitlines(): paginator.add_line(line) paginator.add_line(empty=True)