feat: allow file uploads for cvar, uvar, svar, gvar and alias, servalias, snippet, servsnippet#2207
Conversation
|
I believe the changes to the read_file_from_message function will break viewing cvars, uvars, and svars. |
Yea honestly, woulda removed that if I wasn't fixing it in a hurry, other than that, any other suggestions? I'll make this point to your fork? |
54b75dd to
848d810
Compare
848d810 to
4dca4dc
Compare
|
I'd personally keep the check. Raising the index error ourselves allows it to return a better error message than "Index out of bounds for attachments". |
The IndexError happens naturally at |
We're not actually returning this error either way, it needs to be converted into an InvalidArgument error before being raised any further to avoid the error appearing as a bot error rather than an argument error. I suppose explicitly raising the error could make it clearer to any other readers/users of the function that the IndexError is intetional and meant to caught. |
@LazyDope Good point. Also, wrt catching all Exceptions in cvar/svar/uvar. Won't it be better to only catch IndexError there as well? And let other errors go through, coz say, the Discord CDN fails during a file upload, we won't be sending the "Error in Discord API. Try again" msg Avrae usually shows right? And all other sys errs go through as well. |
My initial thought was if fetching the attachment failed then to just continue as if it didn't exist, however you're probably right that we should only catch IndexErrors |
|
Also, what are your thoughts on merging the PRs into this one? |
Sure yea, that works too |
|
It's already technically merged tho lol, this PR contains all your commits too |
Just update the title and description to clarify that it covers both features. |
- style: also added thousands separators to size limit err msgs
cogsmisc/customization.py
Outdated
| except InvalidArgument as e: | ||
| raise e | ||
| except Exception: | ||
| value = await _get_value_or_file(ctx, None, CVAR_FILE_SIZE_LIMIT, allow_empty=True) |
There was a problem hiding this comment.
With the addition of this helper function, we could probably just move this outside of the if value is None check, since that check is a bit redundant
There was a problem hiding this comment.
Right, but the code readability is crystal clear here with that flow, making it self documenting. Removing that check would make it slightly obfuscated.
I'm open to removing tho if that tradeoff is fine.
There was a problem hiding this comment.
I agree with @LazyDope. The name _get_value_or_file() is self documenting and cleans a level of nesting in the different places it's called
There was a problem hiding this comment.
Sure, done. This was just me being overtly KISS at the cost of a little DRYness.
codybanman
left a comment
There was a problem hiding this comment.
This looks great and works well for the various cases I tested. As I mentioned in the thread, I agree with @LazyDope’s suggestion on the use of use _get_value_or_file(). Once that change is in, we can test it out on nightly.
cogsmisc/customization.py
Outdated
| except InvalidArgument as e: | ||
| raise e | ||
| except Exception: | ||
| value = await _get_value_or_file(ctx, None, CVAR_FILE_SIZE_LIMIT, allow_empty=True) |
There was a problem hiding this comment.
I agree with @LazyDope. The name _get_value_or_file() is self documenting and cleans a level of nesting in the different places it's called
fd5d15c to
5139e74
Compare
5139e74 to
569b713
Compare
Summary
gvar,alias,servalias,snippet, andservsnippetcreate/edit commands to accept file attachments, following the same pattern ascvar,uvar, andsvar.From PR #2206:
Depends on PR #2206 - This PR builds on @LazyDope's cvar/uvar/svar file upload implementation. Please merge #2206 first to avoid conflicts.(both PRs merged into this now)Changelog Entry
!cvar,!uvar,!svar,!gvar,!alias,!servalias,!snippet, and!servsnippetnow support uploading file attachments.Checklist
PR Type
Other