Preserve Invocation Context#3377
Conversation
|
@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). |
|
Perhaps we can send the user the link to delete the paste? You can largely copy the code here: bot/bot/exts/utils/attachment_pastebin_uploader.py Lines 130 to 133 in cb4401b |
Head branch was pushed to by a user without write access
Added. |
| 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." |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yeah, Just saw the lint errors, pushed a commit.
wookie184
left a comment
There was a problem hiding this comment.
Mostly looks good, thanks for the PR.
MarkKoz
left a comment
There was a problem hiding this comment.
Thanks. Looks good besides the comment about exception handling.
Maybe we should only be doing this when RedirectOutput.delete_invocation is true. But in practice this is a global option and the default is true, so it's probably not worth our time. I'm not sure why we even have a config option for that.
If we have the option we may as well implement the functionality. I think just wrapping the network request section in an if statement should cover it? Once the definition for |
So an |
Yes, as well as the variable declaration. |
Co-authored-by: Joe Banks <joe@jb3.dev>
Co-authored-by: Joe Banks <joe@jb3.dev>
Co-authored-by: Joe Banks <joe@jb3.dev>
ea39656 to
0ea257b
Compare
| # Send a DM to the user about the redirect and paste removal | ||
| await ctx.author.send( | ||
| f"Your command output was redirected to <#{Channels.bot_commands}>." | ||
| f" [Click here](<{paste_response.removal}>) to delete the pasted" |
There was a problem hiding this comment.
this will break if paste_response is None
There was a problem hiding this comment.
I think the logs stop it from executing?
There was a problem hiding this comment.
They don't, as mentioned in wookie's previous review (logs explicitly do not stop execution, nor do we want them to).
This will need wrapping with an if paste_response:
There was a problem hiding this comment.
then no else or is there a fallback option?
There was a problem hiding this comment.
We don't need an else because if there isn't a paste_response then we didn't upload their paste.
|
Thanks for the merge @jb3 ! |
| await ctx.send(f"Here's the output of your command, {ctx.author.mention}") | ||
| paste_response = None | ||
| if RedirectOutput.delete_invocation: | ||
| async with ClientSession() as session: |
There was a problem hiding this comment.
this should use ctx.bot.http_session rather than creating a whole new session.
Added:
Closes #3376