Skip to content
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

Resolve #936 #941

Merged
merged 2 commits into from
Mar 8, 2018
Merged

Resolve #936 #941

merged 2 commits into from
Mar 8, 2018

Conversation

Joe4evr
Copy link
Contributor

@Joe4evr Joe4evr commented Jan 28, 2018

Since #936 has been open for over a week now, I decided to take a stab at this. I'm pretty sure the logic is sound?

Copy link
Member

@foxbot foxbot left a comment

Choose a reason for hiding this comment

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

Maybe I'm reading this incorrectly, but this PR seems to favor the default TypeReader over any custom TypeReaders a user would have added?

@FiniteReality
Copy link
Member

I don't think it would, but it would be worthwhile to test just to be certain.

@Joe4evr
Copy link
Contributor Author

Joe4evr commented Feb 3, 2018

@foxbot Only if TypeReader was not set before-hand by use of [OverrideTypeReader]. In that case, this consults the lib's built-in set of type readers first, and then look for a type reader added to the CommandService by the user.

@foxbot foxbot merged commit 170a2e0 into discord-net:dev Mar 8, 2018
@Joe4evr Joe4evr deleted the issue-936 branch March 8, 2018 21:47
@Nensec
Copy link

Nensec commented Mar 17, 2018

This seems to break overriding of the default type readers at the commandservice registration level and will always take the build in default rather than a newly registered one. I have a custom typereader for IUser (in order to do levensthein distance stuff) which is now no longer called

@Joe4evr
Copy link
Contributor Author

Joe4evr commented Mar 17, 2018

@Nensec #975 and #976.

@Nensec
Copy link

Nensec commented Mar 17, 2018

#975 will not solve the issue I am facing with this change. I am using my own UserTypeReader which will call the original TypeReader for User (which I get through reflection by calling GetDefaultTypeReader() on CommandService) and only runs my code when the original type reader fails to produce a result.

var knownTypeReader = _commandService.GetDefaultTypeReader(typeof(IUser));
if (knownTypeReader == null)
    return TypeReaderResult.FromError(CommandError.ParseFailed, $"No typereader found for type {typeof(IUser)}");
else
{
    var knownParseResult = await knownTypeReader.ReadAsync(context, input, services);

    if (knownParseResult.IsSuccess)
    {
        return TypeReaderResult.FromSuccess(knownParseResult.Values);
    }
    else { ... }

The reason I am doing this is so I don't have to copy-paste the code from the original type reader. I would prefer to just inherit it so I can just call base.ReadAsync() rather than do this reflection though, it would also make #975 work as proposed.

@Joe4evr
Copy link
Contributor Author

Joe4evr commented Mar 17, 2018

I am using my own UserTypeReader which will call the original TypeReader for User (which I get through reflection by calling GetDefaultTypeReader() on CommandService)

Well, you shouldn't be using reflection to get at the internal methods and classes in the first place.

I think the best thing to do is to just copy the UserTypeReader code, modify it to do your thing, and using the replace method once #975 is merged in. That way it's both faster and more correct.

Also, in the future please use codeblocks for code samples. Reading unformatted code is disgusting. 🤢

@Nensec
Copy link

Nensec commented Mar 17, 2018

Why are the typereaders internal anyway? What is the added benefit of it over making them inheritable?

@Joe4evr
Copy link
Contributor Author

Joe4evr commented Mar 19, 2018

That is a good question. I also have a scenario where I want to piggyback off of an internal type reader, so maybe we should just open them up.

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.

4 participants