-
-
Notifications
You must be signed in to change notification settings - Fork 734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change priority to user type readers and implement user entity readers #1487
base: dev
Are you sure you want to change the base?
Conversation
Bump - any status updates on this? |
Had to change the way to add entity readers since there's no way for type readers to know what kind of object is being expected to be returned. This could cause an unexpected error when converting types (like a SocketGuildUser to a RestGuildUser). Now they will need to be added with
This will make the creation of entity type readers a bit more complex so they can know what kind of Type is being expected. Entity type readers will need to inherit from TypeReader (like usual) but will required to have a single generic argument that has at least a reference type constraint, e.g. To add it to the command service, it'll be needed to pass the generic type definition of the TypeReader, e.g. Another way would be adding a |
Tagging @Still34 for review 🙃 |
Fix the build errors first. |
Done, missed a bracket in the example. |
@Cenngo Can you look at this? |
I need to go over this to see whats the state of this pr but ill try to wrap this up. |
Summary
This change will rollback the change from #941 that gave priority to default type readers instead of the ones added by the user while also fixing the issue that PR was merged for by creating a specific list for override type readers (so it isn't added like a global one).
It will also give the user the ability to add entity type readers of their own (example: a global IChannel type reader that applies to IMessageChannel etc, like the default one).
Changes
AddEntityTypeReader<T>(Type typeReaderGenericType)
andAddEntityTypeReader(Type type, Type typeReaderGenericType)
toCommandService
AddTypeReader<T>(TypeReader reader, bool replaceDefault)
andAddTypeReader(Type type, TypeReader reader, bool replaceDefault)
(not needed anymore since default type readers don't have priority over the ones added by the user.How to use
TypeReader
with a single generic argument that has at least a reference type constraint, e.g.class CustomUserTypeReader<T> : TypeReader where T : class, IUser
AddEntityTypeReader<IUser>(typeof(CustomUserTypeReader<>))
Examples (with test cases done)
The examples will say what type reader were added (following the order that they were added), the argument used, and the type reader assigned to them. Following this format:
Argument type: Type Reader used
.Note: default = default Discord.Net type reader, otherwise it's the one added by the user.
Adding IChannel type reader and IMessageChannel type reader
Adding only IMessageChannel type reader
Adding IVoiceChannel type reader and IMessageChannel type reader
Notes
This PR includes the change in #1486, so if accepted, please merge that one first since they are the one that fixed and deserve the credit for finding it.
If you have any test case that you want to be done, please comment it here and I can do it since this change might have something I didn't expect and didn't test.