Skip to content

Commit

Permalink
Added XML doc above all public API
Browse files Browse the repository at this point in the history
  • Loading branch information
gehongyan committed Mar 18, 2023
1 parent bfc038e commit 2ad3301
Show file tree
Hide file tree
Showing 80 changed files with 1,383 additions and 111 deletions.
33 changes: 31 additions & 2 deletions src/Kook.Net.Commands/Results/PreconditionGroupResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,55 @@

namespace Kook.Commands;

/// <summary>
/// Represents the result of a grouped precondition check.
/// </summary>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class PreconditionGroupResult : PreconditionResult
{
/// <summary>
/// Gets the results of the precondition checks.
/// </summary>
public IReadOnlyCollection<PreconditionResult> PreconditionResults { get; }

/// <summary>
/// Creates a new <see cref="PreconditionGroupResult"/> with the specified error, reason, and precondition results.
/// </summary>
/// <param name="error"> The error that occurred. </param>
/// <param name="errorReason"> The reason for the error. </param>
/// <param name="preconditions"> The results of the precondition checks. </param>
protected PreconditionGroupResult(CommandError? error, string errorReason, ICollection<PreconditionResult> preconditions)
: base(error, errorReason)
{
PreconditionResults = (preconditions ?? new List<PreconditionResult>(0)).ToReadOnlyCollection();
}

/// <summary>
/// Returns a <see cref="PreconditionResult" /> with no errors.
/// </summary>
public new static PreconditionGroupResult FromSuccess()
=> new PreconditionGroupResult(null, null, null);
/// <summary>
/// Returns a <see cref="PreconditionResult" /> with the reason and precondition results.
/// </summary>
/// <param name="reason"> The reason for the error. </param>
/// <param name="preconditions"> The results of the precondition checks. </param>
public static PreconditionGroupResult FromError(string reason, ICollection<PreconditionResult> preconditions)
=> new PreconditionGroupResult(CommandError.UnmetPrecondition, reason, preconditions);
public static new PreconditionGroupResult FromError(Exception ex)
/// <summary>
/// Returns a <see cref="PreconditionResult" /> with an exception.
/// </summary>
/// <param name="ex"> The exception that occurred. </param>
public new static PreconditionGroupResult FromError(Exception ex)
=> new PreconditionGroupResult(CommandError.Exception, ex.Message, null);
public static new PreconditionGroupResult FromError(IResult result) //needed?
/// <summary>
/// Returns a <see cref="PreconditionResult" /> with the specified result.
/// </summary>
/// <param name="result"> The result of failure. </param>
public new static PreconditionGroupResult FromError(IResult result) //needed?
=> new PreconditionGroupResult(result.Error, result.ErrorReason, null);

/// <inheritdoc />
public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
private string DebuggerDisplay => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
}
4 changes: 4 additions & 0 deletions src/Kook.Net.Commands/Results/PreconditionResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public static PreconditionResult FromSuccess()
/// <param name="reason">The reason of failure.</param>
public static PreconditionResult FromError(string reason)
=> new PreconditionResult(CommandError.UnmetPrecondition, reason);
/// <summary>
/// Returns a <see cref="PreconditionResult" /> with an exception.
/// </summary>
/// <param name="ex"> The exception that occurred. </param>
public static PreconditionResult FromError(Exception ex)
=> new PreconditionResult(CommandError.Exception, ex.Message);
/// <summary>
Expand Down
4 changes: 4 additions & 0 deletions src/Kook.Net.Commands/Results/RuntimeResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Kook.Commands;

/// <summary>
/// Represents the runtime result of a command execution.
/// </summary>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public abstract class RuntimeResult : IResult
{
Expand All @@ -27,6 +30,7 @@ protected RuntimeResult(CommandError? error, string reason)
/// <inheritdoc/>
string IResult.ErrorReason => Reason;

/// <inheritdoc />
public override string ToString() => Reason ?? (IsSuccess ? "Successful" : "Unsuccessful");
private string DebuggerDisplay => IsSuccess ? $"Success: {Reason ?? "No Reason"}" : $"{Error}: {Reason}";
}
29 changes: 29 additions & 0 deletions src/Kook.Net.Commands/Results/SearchResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,19 @@

namespace Kook.Commands;

/// <summary>
/// Represents the result of a command search.
/// </summary>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public struct SearchResult : IResult
{
/// <summary>
/// Gets the text that was searched in.
/// </summary>
public string Text { get; }
/// <summary>
/// Gets the commands that were found.
/// </summary>
public IReadOnlyList<CommandMatch> Commands { get; }

/// <inheritdoc/>
Expand All @@ -24,15 +33,35 @@ private SearchResult(string text, IReadOnlyList<CommandMatch> commands, CommandE
ErrorReason = errorReason;
}

/// <summary>
/// Returns a <see cref="SearchResult" /> with no errors.
/// </summary>
/// <param name="text"> The text that was searched in. </param>
/// <param name="commands"> The commands that were found. </param>
public static SearchResult FromSuccess(string text, IReadOnlyList<CommandMatch> commands)
=> new SearchResult(text, commands, null, null);
/// <summary>
/// Returns a <see cref="SearchResult" /> with a <see cref="CommandError"/>.
/// </summary>
/// <param name="error"> The type of failure. </param>
/// <param name="reason"> The reason of failure. </param>
/// <returns></returns>
public static SearchResult FromError(CommandError error, string reason)
=> new SearchResult(null, null, error, reason);
/// <summary>
/// Returns a <see cref="SearchResult" /> with an exception.
/// </summary>
/// <param name="ex"> The exception that occurred. </param>
public static SearchResult FromError(Exception ex)
=> FromError(CommandError.Exception, ex.Message);
/// <summary>
/// Returns a <see cref="SearchResult" /> with the specified <paramref name="result"/> type.
/// </summary>
/// <param name="result"> The result of failure. </param>
public static SearchResult FromError(IResult result)
=> new SearchResult(null, null, result.Error, result.ErrorReason);

/// <inheritdoc />
public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
private string DebuggerDisplay => IsSuccess ? $"Success ({Commands.Count} Results)" : $"{Error}: {ErrorReason}";
}
53 changes: 52 additions & 1 deletion src/Kook.Net.Commands/Results/TypeReaderResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,46 @@

namespace Kook.Commands;

/// <summary>
/// Represents a parsing result of a type reader.
/// </summary>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public struct TypeReaderValue
{
/// <summary>
/// Gets the parsed value.
/// </summary>
public object Value { get; }
/// <summary>
/// Gets the confidence score of the parsing.
/// </summary>
public float Score { get; }

/// <summary>
/// Initializes a new instance of the <see cref="TypeReaderValue"/> struct.
/// </summary>
/// <param name="value"> The parsed value. </param>
/// <param name="score"> The confidence score of the parsing. </param>
public TypeReaderValue(object value, float score)
{
Value = value;
Score = score;
}

/// <inheritdoc />
public override string ToString() => Value?.ToString();
private string DebuggerDisplay => $"[{Value}, {Math.Round(Score, 2)}]";
}

/// <summary>
/// Represents a parsing result of a type reader.
/// </summary>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public struct TypeReaderResult : IResult
{
/// <summary>
/// Gets the parsed values.
/// </summary>
public IReadOnlyCollection<TypeReaderValue> Values { get; }

/// <inheritdoc/>
Expand All @@ -34,7 +55,11 @@ public struct TypeReaderResult : IResult

/// <exception cref="InvalidOperationException">TypeReaderResult was not successful.</exception>
public object BestMatch => IsSuccess
? (Values.Count == 1 ? Values.Single().Value : Values.OrderByDescending(v => v.Score).First().Value)
#if NET5_0_OR_GREATER
? Values.Count == 1 ? Values.Single().Value : Values.MaxBy(v => v.Score).Value
#else
? Values.Count == 1 ? Values.Single().Value : Values.OrderByDescending(v => v.Score).First().Value
#endif
: throw new InvalidOperationException("TypeReaderResult was not successful.");

private TypeReaderResult(IReadOnlyCollection<TypeReaderValue> values, CommandError? error, string errorReason)
Expand All @@ -44,19 +69,45 @@ private TypeReaderResult(IReadOnlyCollection<TypeReaderValue> values, CommandErr
ErrorReason = errorReason;
}

/// <summary>
/// Returns a <see cref="TypeReaderResult" /> with no errors.
/// </summary>
/// <param name="value"> The parsed value. </param>
public static TypeReaderResult FromSuccess(object value)
=> new TypeReaderResult(ImmutableArray.Create(new TypeReaderValue(value, 1.0f)), null, null);
/// <summary>
/// Returns a <see cref="TypeReaderResult" /> with no errors.
/// </summary>
/// <param name="value"> The parsed value. </param>
public static TypeReaderResult FromSuccess(TypeReaderValue value)
=> new TypeReaderResult(ImmutableArray.Create(value), null, null);
/// <summary>
/// Returns a <see cref="TypeReaderResult" /> with no errors.
/// </summary>
/// <param name="values"> The parsed values. </param>
public static TypeReaderResult FromSuccess(IReadOnlyCollection<TypeReaderValue> values)
=> new TypeReaderResult(values, null, null);
/// <summary>
/// Returns a <see cref="TypeReaderResult" /> with a specified error.
/// </summary>
/// <param name="error"> The error. </param>
/// <param name="reason"> The reason for the error. </param>
public static TypeReaderResult FromError(CommandError error, string reason)
=> new TypeReaderResult(null, error, reason);
/// <summary>
/// Returns a <see cref="TypeReaderResult" /> with an exception.
/// </summary>
/// <param name="ex"> The exception that occurred. </param>
public static TypeReaderResult FromError(Exception ex)
=> FromError(CommandError.Exception, ex.Message);
/// <summary>
/// Returns a <see cref="TypeReaderResult" /> with an specified result.
/// </summary>
/// <param name="result"> The result. </param>
public static TypeReaderResult FromError(IResult result)
=> new TypeReaderResult(null, result.Error, result.ErrorReason);

/// <inheritdoc />
public override string ToString() => IsSuccess ? "Success" : $"{Error}: {ErrorReason}";
private string DebuggerDisplay => IsSuccess ? $"Success ({string.Join(", ", Values)})" : $"{Error}: {ErrorReason}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Kook;
public enum GameCreationSource
{
/// <summary>
/// Represents that the game was created by myself.
/// Represents that the game was created by the current user.
/// </summary>
SelfUser = 1,

Expand Down
14 changes: 14 additions & 0 deletions src/Kook.Net.Core/Entities/Activities/Music.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
namespace Kook;

/// <summary>
/// Represents a music activity.
/// </summary>
public class Music
{
/// <summary>
/// Gets or sets the music provider.
/// </summary>
public MusicProvider Provider { get; set; }

/// <summary>
/// Gets or sets the music ID.
/// </summary>
public string Name { get; set; }

/// <summary>
/// Gets or sets the singer.
/// </summary>
public string Singer { get; set; }
}
2 changes: 1 addition & 1 deletion src/Kook.Net.Core/Entities/Activities/MusicProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public enum MusicProvider
/// </summary>
NetEaseCloudMusic = 1,
/// <summary>
/// Specifies that the music provider is QQ.
/// Specifies that the music provider is Tencent QQ.
/// </summary>
TencentMusic = 2,
/// <summary>
Expand Down
9 changes: 8 additions & 1 deletion src/Kook.Net.Core/Entities/Emotes/Emoji.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static bool TryParse(string text, out Emoji result)
public static Emoji Parse(string emojiStr)
{
if (!TryParse(emojiStr, out var emoji))
throw new FormatException("String is not emoji name or unicode!");
throw new FormatException("String is not emoji name or unicode.");

return emoji;
}
Expand Down Expand Up @@ -1845,5 +1845,12 @@ private static IReadOnlyDictionary<string, ReadOnlyCollection<string>> UnicodesA
}
}

/// <summary>
/// Parses the given string into an <see cref="Emoji" />.
/// </summary>
/// <param name="s"> The string to parse. </param>
/// <returns> The parsed <see cref="Emoji" />. </returns>
/// <exception cref="FormatException"> The provided string is not emoji name or unicode. </exception>
/// <seealso cref="Parse"/>
public static implicit operator Emoji(string s) => Parse(s);
}
22 changes: 18 additions & 4 deletions src/Kook.Net.Core/Entities/Emotes/Emote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

namespace Kook;

/// <summary>
/// Represents a guild emote.
/// </summary>
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class Emote : IEmote
{
Expand All @@ -13,10 +16,19 @@ public class Emote : IEmote
internal static readonly Regex KMarkdownEmojiRegex = new Regex(@"(\(emj\))(?<name>[^\(\)]{1,32}?)\1\[(?<id>\d{1,20}\/\w{1,20})\]",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.Singleline);

/// <summary>
/// Gets the identifier of this emote.
/// </summary>
public string Id { get; }

/// <summary>
/// Gets the name of this emote.
/// </summary>
public string Name { get; }

/// <summary>
/// Gets whether this emote is animated.
/// </summary>
public bool? Animated { get; }

internal Emote(string id, string name, bool? animated = null)
Expand All @@ -26,6 +38,7 @@ internal Emote(string id, string name, bool? animated = null)
Animated = animated;
}

/// <inheritdoc />
public override bool Equals(object other)
{
if (other == null)
Expand All @@ -39,14 +52,15 @@ public override bool Equals(object other)
return Id == otherEmote.Id;
}

/// <inheritdoc />
public override int GetHashCode()
=> Id.GetHashCode();

/// <summary> Parses an <see cref="Emote"/> from its raw format. </summary>
/// <param name="text">
/// The raw encoding of an emote; for example,
/// [:djbigfan:1990044438283387/hvBcVC4nHX03k03k] when <paramref name="tagMode"/> is <c>TagMode.PlainText</c>,
/// or (emj)djbigfan(emj)[1990044438283387/hvBcVC4nHX03k03k] when <paramref name="tagMode"/> is <c>TagMode.KMarkdown</c>.
/// [:emotename:1991895624896587/hbCFVWhu923k03k] when <paramref name="tagMode"/> is <c>TagMode.PlainText</c>,
/// or (emj)emotename(emj)[1991895624896587/hbCFVWhu923k03k] when <paramref name="tagMode"/> is <c>TagMode.KMarkdown</c>.
/// </param>
/// <param name="tagMode"></param>
/// <returns>An emote.</returns>
Expand All @@ -61,8 +75,8 @@ public static Emote Parse(string text, TagMode tagMode)
/// <summary> Tries to parse an <see cref="Emote"/> from its raw format. </summary>
/// <param name="text">
/// The raw encoding of an emote; for example,
/// [:djbigfan:1990044438283387/hvBcVC4nHX03k03k] when <paramref name="tagMode"/> is <c>TagMode.PlainText</c>,
/// or (emj)djbigfan(emj)[1990044438283387/hvBcVC4nHX03k03k] when <paramref name="tagMode"/> is <c>TagMode.KMarkdown</c>.
/// [:emotename:1991895624896587/hbCFVWhu923k03k] when <paramref name="tagMode"/> is <c>TagMode.PlainText</c>,
/// or (emj)emotename(emj)[1991895624896587/hbCFVWhu923k03k] when <paramref name="tagMode"/> is <c>TagMode.KMarkdown</c>.
/// </param>
/// <param name="result">An emote.</param>
/// <param name="tagMode"></param>
Expand Down
2 changes: 1 addition & 1 deletion src/Kook.Net.Core/Entities/Guilds/IGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public interface IGuild : IEntity<ulong>
/// <summary>
/// Bans the user from this guild and optionally prunes their recent messages.
/// </summary>
/// <param name="userId">The snowflake ID of the user to ban.</param>
/// <param name="userId">The identifier of the user to ban.</param>
/// <param name="pruneDays">The number of days to remove messages from this user for, and this number must be between [0, 7].</param>
/// <param name="reason">The reason of the ban to be written in the audit log.</param>
/// <param name="options">The options to be used when sending the request.</param>
Expand Down
Loading

0 comments on commit 2ad3301

Please sign in to comment.