Skip to content

Conversation

DragonSenseiGuy
Copy link

@DragonSenseiGuy DragonSenseiGuy commented Aug 31, 2025

Added:

  • A link to the pastebin for commands executed outside of #bot-commands, to preserve invocation context

Closes #3376

@jb3 jb3 enabled auto-merge (squash) September 1, 2025 18:28
@jb3 jb3 disabled auto-merge September 1, 2025 18:29
@jb3 jb3 enabled auto-merge (squash) September 1, 2025 18:29
@jb3 jb3 disabled auto-merge September 1, 2025 18:29
@jb3 jb3 enabled auto-merge (squash) September 1, 2025 18:30
Comment on lines 163 to 164
files=[PasteFile(content=ctx.message.content, lexer="markdown")],
http_session=session,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like these lines are indented an extra level.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

log.exception(
"Failed to upload message %d in channel %d to paste service when redirecting output",
ctx.message.channel.id, ctx.message.id
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one line should be indented one level less.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Comment on lines 178 to 183
msg += "Here's the output of "

if paste_link:
msg += f"[your command]({paste_link}):"
else:
msg += "your command:"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be one line using a ternary condition.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@swfarnsworth
Copy link
Member

@jb3, am I correct in my understanding that this copies messages from the server to our pastebin, possibly unexpectedly?

else:
msg += "your command:"

await ctx.send(msg)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this potentially send an empty message?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved with the ternary changes.

if ping_user:
await ctx.send(f"Here's the output of your command, {ctx.author.mention}")
msg += f"{ctx.author.mention}, "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we changing the order and putting the mention first?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want it changed? It can be done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong preference, but I figure we should leave it alone if there is no compelling reason to change it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this was probably something I changed inadvertedly when I wrote something on mobile, it can be changed back.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I change and commit then? Or should we just leave it as is?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change it back, there's no reason to alter it from what already exists.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@jb3
Copy link
Member

jb3 commented Sep 2, 2025

@jb3, am I correct in my understanding that this copies messages from the server to our pastebin, possibly unexpectedly?

Yes, but with it being a bot command I'm less worried about that. Previously we've worried about that when things such as automatically uploading unformatted code have been mentioned, or when we are talking about uploading messages which are not direct interactions with the bot.

In this case, it's reasonable to temporarily upload after a user has directly used our features (bear in mind we automatically upload the results if they are too long).

@swfarnsworth
Copy link
Member

Perhaps we can send the user the link to delete the paste? You can largely copy the code here:

# Send the user a DM with the delete link for the paste.
# The angle brackets around the remove link are required to stop Discord from visiting the URL to produce a
# preview, thereby deleting the paste
await message.author.send(content=f"[Click here](<{paste_response.removal}>) to delete your recent paste.")

auto-merge was automatically disabled September 2, 2025 19:44

Head branch was pushed to by a user without write access

@DragonSenseiGuy
Copy link
Author

Perhaps we can send the user the link to delete the paste? You can largely copy the code here:

# Send the user a DM with the delete link for the paste.
# The angle brackets around the remove link are required to stop Discord from visiting the URL to produce a
# preview, thereby deleting the paste
await message.author.send(content=f"[Click here](<{paste_response.removal}>) to delete your recent paste.")

Added.

Comment on lines 183 to 184
content=
f"Your command output was redirected to <#{Channels.bot_commands}>. [Click here](<{paste_response.removal}>) to delete the automatically uploaded copy of your original command."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When a string is too long, the preferred format is like this

content = (
    "Lorem ipsum dolor sit amet, consectetur "
    f"adipiscing {elit}, sed do eiusmod tempor "
    "incididunt ut labore et dolore magna aliqua."
)

This leverages implicit string concatenation. Note that segments using f-string need to start with an f. The trailing spaces at the end of each line are literal single spaces that are not line breaks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, Just saw the lint errors, pushed a commit.

Copy link
Member

@jb3 jb3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting and wording.

Co-authored-by: Joe Banks <[email protected]>
Co-authored-by: Joe Banks <[email protected]>
" copy of your original command."
)
except discord.Forbidden:
log.warning("Redirect output: Failed to send DM to user. Forbidden.")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably isn't a warning really, it's expected behaviour that we are catching.

Suggested change
log.warning("Redirect output: Failed to send DM to user. Forbidden.")
log.info(
"Failed to DM %s with redirected command paste removal link, user has bot DMs disabled",
ctx.author.name
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.But this was your suggestion.

Co-authored-by: Joe Banks <[email protected]>
@jb3 jb3 requested review from swfarnsworth and MarkKoz September 5, 2025 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Preserve invocation context when redirecting output of command
4 participants