Skip to content

Commit

Permalink
Expose the internal entity type readers (discord-net#986)
Browse files Browse the repository at this point in the history
* Expose the internal entity type readers

* Add BestMatch property to TypeReaderResult for easily accessing the parsed object
  • Loading branch information
Joe4evr authored and foxbot committed Apr 29, 2018
1 parent 6a7810b commit 660fec0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Discord.Net.Commands/Readers/ChannelTypeReader.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;

namespace Discord.Commands
{
internal class ChannelTypeReader<T> : TypeReader
public class ChannelTypeReader<T> : TypeReader
where T : class, IChannel
{
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.Commands/Readers/MessageTypeReader.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System;
using System.Globalization;
using System.Threading.Tasks;

namespace Discord.Commands
{
internal class MessageTypeReader<T> : TypeReader
public class MessageTypeReader<T> : TypeReader
where T : class, IMessage
{
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.Commands/Readers/RoleTypeReader.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;

namespace Discord.Commands
{
internal class RoleTypeReader<T> : TypeReader
public class RoleTypeReader<T> : TypeReader
where T : class, IRole
{
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
Expand Down
4 changes: 2 additions & 2 deletions src/Discord.Net.Commands/Readers/UserTypeReader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Globalization;
Expand All @@ -7,7 +7,7 @@

namespace Discord.Commands
{
internal class UserTypeReader<T> : TypeReader
public class UserTypeReader<T> : TypeReader
where T : class, IUser
{
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
Expand Down
6 changes: 5 additions & 1 deletion src/Discord.Net.Commands/Results/TypeReaderResult.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;

namespace Discord.Commands
{
Expand Down Expand Up @@ -30,6 +31,9 @@ public struct TypeReaderResult : IResult
public string ErrorReason { get; }

public bool IsSuccess => !Error.HasValue;
public object BestMatch => IsSuccess
? (Values.Count == 1 ? Values.Single().Value : Values.OrderByDescending(v => v.Score).First().Value)
: throw new InvalidOperationException("TypeReaderResult was not successful.");

private TypeReaderResult(IReadOnlyCollection<TypeReaderValue> values, CommandError? error, string errorReason)
{
Expand Down

0 comments on commit 660fec0

Please sign in to comment.