diff --git a/THIRD-PARTY-NOTICES.txt b/THIRD-PARTY-NOTICES.txt
index 204af25f..2fc68128 100644
--- a/THIRD-PARTY-NOTICES.txt
+++ b/THIRD-PARTY-NOTICES.txt
@@ -126,6 +126,13 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+License notice for MassTransit
+------------------------------------
+
+Licensed under the Apache License, Version 2.0.
+Available at
+https://github.com/MassTransit/MassTransit/blob/develop/LICENSE
+
License notice for Microsoft.NET.Test.Sdk
------------------------------------
diff --git a/docs/guides/voice/sending-voice.md b/docs/guides/voice/sending-voice.md
index d16181f4..31dafdde 100644
--- a/docs/guides/voice/sending-voice.md
+++ b/docs/guides/voice/sending-voice.md
@@ -66,7 +66,7 @@ opus 在同一位置),参见 [FFmpeg 的下载页面],或使用操作系
[IAudioClient]: xref:Kook.Audio.IAudioClient
[AudioOutStream]: xref:Kook.Audio.AudioOutStream
-[IAudioClient.CreatePCMStream]: xref:Kook.Audio.IAudioClient#Kook_Audio_IAudioClient_CreatePcmStream_Kook_Audio_AudioApplication_System_Int32_System_Int32_System_Int32_
+[IAudioClient.CreatePCMStream]: xref:Kook.Audio.IAudioClient#Kook_Audio_IAudioClient_CreatePcmStream_Kook_Audio_AudioApplication_System_Nullable_System_Int32__System_Int32_System_Int32_
最后,音频需要从 FFmpeg 的标准输出流传输到你的 AudioOutStream 对象中。
根据你的业务需要,这个步骤中间可能会进行某些处理,但在大多数情况下,使用 [Stream.CopyToAsync] 即可。
diff --git a/docs/quick_reference/http_api/oauth.md b/docs/quick_reference/http_api/oauth.md
index c86b1ce3..766c3014 100644
--- a/docs/quick_reference/http_api/oauth.md
+++ b/docs/quick_reference/http_api/oauth.md
@@ -16,10 +16,9 @@ readonly KookRestClient _restClient = null;
POST `/api/oauth2/token`
-无公开 API,请使用 `AspNet.Security.OAuth.Kook`,请参考:
+无公开 API。可参考以下类库:
-* NuGet:
-* GitHub:
-* 文档:
+- **AspNet.Security.OAuth.Kook**:[NuGet](https://www.nuget.org/packages/AspNet.Security.OAuth.Kook/),[GitHub](https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers),[文档](https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers/blob/dev/docs/kook.md)
+- **OpenIddict**:[NuGet](https://www.nuget.org/packages/OpenIddict/),[GitHub](https://github.com/openiddict/openiddict-core),[文档](https://documentation.openiddict.com/)
[获取 AccessToken]: https://developer.kookapp.cn/doc/http/oauth#获取AccessToken
diff --git a/samples/Kook.Net.Samples.Audio/Modules/MusicModule.cs b/samples/Kook.Net.Samples.Audio/Modules/MusicModule.cs
index 0ad8a7b1..65c0e883 100644
--- a/samples/Kook.Net.Samples.Audio/Modules/MusicModule.cs
+++ b/samples/Kook.Net.Samples.Audio/Modules/MusicModule.cs
@@ -17,8 +17,6 @@ public class MusicModule : ModuleBase
private readonly MusicService _musicService;
private readonly IHttpClientFactory _httpClientFactory;
-
-
///
/// Initializes a new instance of the class.
///
diff --git a/samples/Kook.Net.Samples.FSharp/Program.fs b/samples/Kook.Net.Samples.FSharp/Program.fs
index 3af8ffa8..902db2da 100644
--- a/samples/Kook.Net.Samples.FSharp/Program.fs
+++ b/samples/Kook.Net.Samples.FSharp/Program.fs
@@ -7,7 +7,7 @@ open Kook.WebSocket
// 这是一个使用 Kook.Net 的 F# 简单示例
// Kook.Net 的所有文档均以 C# 编写,但是 Kook.Net 也支持 F#
-// 如果要编写带有命令的机器人,我们建议使用 Kook.Net.Commands 框架
+// 如果要编写带有命令的 Bot,我们建议使用 Kook.Net.Commands 框架
// 而不是像在这个示例中一样自己处理它们。
// 您可以在以下位置找到使用命令框架的示例:
diff --git a/samples/Kook.Net.Samples.SimpleBot/Program.cs b/samples/Kook.Net.Samples.SimpleBot/Program.cs
index 2ba75246..f7cf24ed 100644
--- a/samples/Kook.Net.Samples.SimpleBot/Program.cs
+++ b/samples/Kook.Net.Samples.SimpleBot/Program.cs
@@ -3,7 +3,7 @@
// 这是一个使用 Kook.Net 的 C# 简单示例
-// 如果要编写带有命令的机器人,我们建议使用 Kook.Net.Commands 框架
+// 如果要编写带有命令的 Bot,我们建议使用 Kook.Net.Commands 框架
// 而不是像在这个示例中一样自己处理它们。
// 您可以在以下位置找到使用命令框架的示例:
diff --git a/samples/Kook.Net.Samples.VisualBasic/Program.vb b/samples/Kook.Net.Samples.VisualBasic/Program.vb
index 208e59e7..c3db07c6 100644
--- a/samples/Kook.Net.Samples.VisualBasic/Program.vb
+++ b/samples/Kook.Net.Samples.VisualBasic/Program.vb
@@ -4,7 +4,7 @@ Imports Kook.WebSocket
' 这是一个使用 Kook.Net 的 Visual Basic 简单示例
' Kook.Net 的所有文档均以 C# 编写,但是 Kook.Net 也支持 Visual Basic
-' 如果要编写带有命令的机器人,我们建议使用 Kook.Net.Commands 框架
+' 如果要编写带有命令的 Bot,我们建议使用 Kook.Net.Commands 框架
' 而不是像在这个示例中一样自己处理它们。
' 您可以在以下位置找到使用命令框架的示例:
diff --git a/src/Kook.Net.CardMarkup/CardMarkupSerializer.cs b/src/Kook.Net.CardMarkup/CardMarkupSerializer.cs
index c9becf83..11ed3255 100644
--- a/src/Kook.Net.CardMarkup/CardMarkupSerializer.cs
+++ b/src/Kook.Net.CardMarkup/CardMarkupSerializer.cs
@@ -7,20 +7,19 @@
namespace Kook.CardMarkup;
///
-/// Serializer for Card Message XML markup
+/// 提供用于从 XML 标记语言创建卡片消息的序列化器。
///
public static class CardMarkupSerializer
{
#region Async
///
- /// Deserialize a Card Message XML markup file to a list.
- /// One XML markup file has one card-message element, which can
- /// contain multiple card elements.
+ /// 将卡片消息 XML 标记文件反序列化为 列表,每个 XML 文件包含一个 card-message
+ /// 元素,可以包含多个 card 元素。
///
- /// UTF-8 encoded XML file
- /// Cancellation token
- /// enumerable
+ /// UTF-8 编码的 XML 文件
+ /// 取消令牌。
+ /// 一个表示异步解析操作的任务。任务的结果包含一个可用于枚举 成员的 。
public static async Task> DeserializeAsync(FileInfo file, CancellationToken token = default)
{
#if NETSTANDARD2_0 || NET462
@@ -32,13 +31,12 @@ public static async Task> DeserializeAsync(FileInfo file, Can
}
///
- /// Deserialize a Card Message XML markup text to a list.
- /// One XML markup file has one card-message element, which can
- /// contain multiple card elements.
+ /// 将卡片消息 XML 标记文本反序列化为 列表,每个 XML 文件包含一个 card-message
+ /// 元素,可以包含多个 card 元素。
///
- /// UTF-8 encoded XML text
- /// Cancellation token
- /// enumerable
+ /// UTF-8 编码的 XML 文本。
+ /// 取消令牌。
+ /// 一个表示异步解析操作的任务。任务的结果包含一个可用于枚举 成员的 。
public static async Task> DeserializeAsync(string xmlText, CancellationToken token = default)
{
using MemoryStream xmlStream = new(Encoding.UTF8.GetBytes(xmlText));
@@ -46,13 +44,12 @@ public static async Task> DeserializeAsync(string xmlText, Ca
}
///
- /// Deserialize a Card Message XML stream to a list.
- /// One XML markup file has one card-message element, which can
- /// contain multiple card elements.
+ /// 将卡片消息 XML 标记文本流反序列化为 列表,每个 XML 文件包含一个 card-message
+ /// 元素,可以包含多个 card 元素。
///
- /// UTF-8 encoded XML stream
- /// Cancellation token
- /// enumerable
+ /// UTF-8 编码的 XML 流。
+ /// 取消令牌。
+ /// 一个表示异步解析操作的任务。任务的结果包含一个可用于枚举 成员的 。
public static async Task> DeserializeAsync(Stream xmlStream, CancellationToken token = default)
{
using XmlReader xmlReader = XmlReader.Create(xmlStream, new XmlReaderSettings
@@ -121,12 +118,11 @@ public static async Task> DeserializeAsync(Stream xmlStream,
#region Sync
///
- /// Deserialize a Card Message XML markup file to a list.
- /// One XML markup file has one card-message element, which can
- /// contain multiple card elements.
+ /// 将卡片消息 XML 标记文件反序列化为 列表,每个 XML 文件包含一个 card-message
+ /// 元素,可以包含多个 card 元素。
///
- /// UTF-8 encoded XML file
- /// enumerable
+ /// UTF-8 编码的 XML 文件
+ /// 一个可用于枚举 成员的 。
public static IEnumerable Deserialize(FileInfo file)
{
using FileStream fs = file.OpenRead();
@@ -134,12 +130,11 @@ public static IEnumerable Deserialize(FileInfo file)
}
///
- /// Deserialize a Card Message XML markup text to a list.
- /// One XML markup file has one card-message element, which can
- /// contain multiple card elements.
+ /// 将卡片消息 XML 标记文本反序列化为 列表,每个 XML 文件包含一个 card-message
+ /// 元素,可以包含多个 card 元素。
///
- /// UTF-8 encoded XML text
- /// enumerable
+ /// UTF-8 编码的 XML 文本。
+ /// 一个可用于枚举 成员的 。
public static IEnumerable Deserialize(string xmlText)
{
using MemoryStream xmlStream = new(Encoding.UTF8.GetBytes(xmlText));
@@ -147,12 +142,11 @@ public static IEnumerable Deserialize(string xmlText)
}
///
- /// Deserialize a Card Message XML markup file to a list.
- /// One XML markup file has one card-message element, which can
- /// contain multiple card elements.
+ /// 将卡片消息 XML 标记文本流反序列化为 列表,每个 XML 文件包含一个 card-message
+ /// 元素,可以包含多个 card 元素。
///
- /// UTF-8 encoded XML stream
- /// enumerable
+ /// UTF-8 编码的 XML 流。
+ /// 一个可用于枚举 成员的 。
public static IEnumerable Deserialize(Stream xmlStream)
{
using XmlReader xmlReader = XmlReader.Create(xmlStream, new XmlReaderSettings
@@ -220,11 +214,14 @@ public static IEnumerable Deserialize(Stream xmlStream)
#nullable enable
///
- /// Try to deserialize a Card Message XML markup file to a list.
+ /// 尝试将卡片消息 XML 标记文件反序列化为 列表。
///
- /// UTF-8 encoded XML file
- /// enumerable, will be null if return value is false
- /// True if deserialization is successful, otherwise false
+ /// UTF-8 编码的 XML 文件。
+ ///
+ /// 如果反序列化操作成功,则为一个可用于枚举 成员的
+ /// ;否则为 null。
+ ///
+ /// 如果反序列化操作成功,则为 true;否则为 false。
public static bool TryDeserialize(FileInfo file, [NotNullWhen(true)] out IEnumerable? cards)
{
try
@@ -240,11 +237,14 @@ public static bool TryDeserialize(FileInfo file, [NotNullWhen(true)] out IEnumer
}
///
- /// Try to deserialize a Card Message XML markup file to a list.
+ /// 尝试将卡片消息 XML 标记文本反序列化为 列表。
///
- /// UTF-8 encoded XML text
- /// enumerable, will be null if return value is false
- /// True if deserialization is successful, otherwise false
+ /// UTF-8 编码的 XML 文本。
+ ///
+ /// 如果反序列化操作成功,则为一个可用于枚举 成员的
+ /// ;否则为 null。
+ ///
+ /// 如果反序列化操作成功,则为 true;否则为 false。
public static bool TryDeserialize(string xmlText, [NotNullWhen(true)] out IEnumerable? cards)
{
try
@@ -260,11 +260,14 @@ public static bool TryDeserialize(string xmlText, [NotNullWhen(true)] out IEnume
}
///
- /// Try to deserialize a Card Message XML markup file to a list.
+ /// 尝试将卡片消息 XML 标记文本流反序列化为 列表。
///
- /// UTF-8 encoded XML stream
- /// enumerable, will be null if return value is false
- /// True if deserialization is successful, otherwise false
+ /// UTF-8 编码的 XML 文本流。
+ ///
+ /// 如果反序列化操作成功,则为一个可用于枚举 成员的
+ /// ;否则为 null。
+ ///
+ /// 如果反序列化操作成功,则为 true;否则为 false。
public static bool TryDeserialize(Stream xmlStream, [NotNullWhen(true)] out IEnumerable? cards)
{
try
diff --git a/src/Kook.Net.Commands/Attributes/AliasAttribute.cs b/src/Kook.Net.Commands/Attributes/AliasAttribute.cs
index 564b2516..0a75e8f1 100644
--- a/src/Kook.Net.Commands/Attributes/AliasAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/AliasAttribute.cs
@@ -1,22 +1,19 @@
namespace Kook.Commands;
///
-/// Marks the aliases for a command.
+/// 为命令指定别名。
///
///
-/// This attribute allows a command to have one or multiple aliases. In other words, the base command can have
-/// multiple aliases when triggering the command itself, giving the end-user more freedom of choices when giving
-/// hot-words to trigger the desired command. See the example for a better illustration.
+/// 此特性允许命令具有一个或多个别名,在指定命令的基本名称的同时,还可以指定多个别名,以便用户可以使用多个熟悉的词汇来触发相同的命令。
///
///
-/// In the following example, the command can be triggered with the base name, "stats", or either "stat" or
-/// "info".
+/// 以下示例中,要调用此命令,除了可以使用基本名称“stats”,还使用“stat”或“info”。
///
/// [Command("stats")]
/// [Alias("stat", "info")]
-/// public async Task GetStatsAsync(IUser user)
+/// public async Task GetStatsAsync(IUser user)
/// {
-/// // ...pull stats
+/// await ReplyTextAsync($"{user.Username} has 1000 score!");
/// }
///
///
@@ -24,12 +21,12 @@ namespace Kook.Commands;
public class AliasAttribute : Attribute
{
///
- /// Gets the aliases which have been defined for the command.
+ /// 获取为命令定义的别名。
///
public string[] Aliases { get; }
///
- /// Creates a new with the given aliases.
+ /// 初始化一个 类的新实例。
///
public AliasAttribute(params string[] aliases)
{
diff --git a/src/Kook.Net.Commands/Attributes/CommandAttribute.cs b/src/Kook.Net.Commands/Attributes/CommandAttribute.cs
index c8d1e4d5..005966ee 100644
--- a/src/Kook.Net.Commands/Attributes/CommandAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/CommandAttribute.cs
@@ -1,73 +1,79 @@
namespace Kook.Commands;
///
-/// Marks the execution information for a command.
+/// 为命令标记执行信息。
///
[AttributeUsage(AttributeTargets.Method)]
public class CommandAttribute : Attribute
{
///
- /// Gets the text that has been set to be recognized as a command.
+ /// 获取此命令的基本名称。
///
+ ///
+ /// 特性重写此属性的值。
+ ///
public string? Text { get; }
///
- /// Specifies the of the command. This affects how the command is executed.
+ /// 获取或设置命令的运行模式。
///
+ ///
public RunMode RunMode { get; set; } = RunMode.Default;
///
- /// Indicates whether extra arguments should be ignored for this command.
+ /// 获取或设置是否忽略此命令的额外参数。
///
+ ///
public bool? IgnoreExtraArgs { get; }
///
- /// Attaches a summary to your command.
+ /// 获取或设置命令的摘要。
///
///
- /// overrides the value of this property if present.
+ /// 特性重写此属性的值。
///
public string? Summary { get; set; }
///
- /// Marks the aliases for a command.
+ /// 获取或设置命令的别名。
///
///
- /// extends the base value of this if present.
+ /// 特性的值会与此属性的值合并。
///
public string?[]? Aliases { get; set; }
///
- /// Attaches remarks to your commands.
+ /// 获取或设置命令的备注。
///
///
- /// overrides the value of this property if present.
+ /// 特性重写此属性的值。
///
public string? Remarks { get; set; }
- ///
+ ///
+ /// 初始化一个 类的新实例。
+ ///
public CommandAttribute()
{
}
///
- /// Initializes a new attribute with the specified name.
+ /// 初始化一个 类的新实例。
///
- /// The name of the command.
+ /// 命令的基本名称。
public CommandAttribute(string text)
{
Text = text;
}
///
- /// Initializes a new attribute with the specified name
- /// and mode of whether to ignore extra arguments.
+ /// 初始化一个 类的新实例。
///
- /// The name of the command.
- /// Whether to ignore extra arguments.
- /// The summary of the command.
- /// The aliases of the command.
- /// The remarks of the command.
+ /// 命令的基本名称。
+ /// 是否忽略此命令的额外参数。
+ /// 命令的摘要。
+ /// 命令的别名。
+ /// 命令的备注。
public CommandAttribute(string text, bool ignoreExtraArgs,
string? summary = null, string?[]? aliases = null, string? remarks = null)
{
diff --git a/src/Kook.Net.Commands/Attributes/DontAutoLoadAttribute.cs b/src/Kook.Net.Commands/Attributes/DontAutoLoadAttribute.cs
index cf689d2f..4703f3f1 100644
--- a/src/Kook.Net.Commands/Attributes/DontAutoLoadAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/DontAutoLoadAttribute.cs
@@ -1,12 +1,11 @@
namespace Kook.Commands;
///
-/// Prevents the marked module from being loaded automatically.
+/// 标记指定的模块不应被自动加载。
///
///
-/// This attribute tells to ignore the marked module from being loaded
-/// automatically (e.g. the method). If a non-public module marked
-/// with this attribute is attempted to be loaded manually, the loading process will also fail.
+/// 此属性告诉 在自动加载模块是忽略被此特性标记的模块。
+/// 需要注意的是,如果尝试手动加载被此特性标记的非公共模块,加载过程也会失败。
///
[AttributeUsage(AttributeTargets.Class)]
public class DontAutoLoadAttribute : Attribute;
diff --git a/src/Kook.Net.Commands/Attributes/DontInjectAttribute.cs b/src/Kook.Net.Commands/Attributes/DontInjectAttribute.cs
index c742cc76..83520d79 100644
--- a/src/Kook.Net.Commands/Attributes/DontInjectAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/DontInjectAttribute.cs
@@ -1,20 +1,18 @@
namespace Kook.Commands;
///
-/// Prevents the marked property from being injected into a module.
+/// 标记指定的成员不应被注入到其父模块。
///
///
-/// This attribute prevents the marked member from being injected into its parent module. Useful when you have a
-/// public property that you do not wish to invoke the library's dependency injection service.
+/// 此特性阻止被标记的成员被注入到其父模块。当存在一个公共属性但不希望为该属性自动注入服务时,请标记此特性。
///
///
-/// In the following example, DatabaseService will not be automatically injected into the module and will
-/// not throw an error message if the dependency fails to be resolved.
+/// 以下示例代码中,DatabaseService 将不会自动注入服务,如果依赖项无法解析,也不会抛出错误消息。
///
/// public class MyModule : ModuleBase
/// {
/// [DontInject]
-/// public DatabaseService DatabaseService;
+/// public DatabaseService DatabaseService { get; }
/// public MyModule()
/// {
/// DatabaseService = DatabaseFactory.Generate();
diff --git a/src/Kook.Net.Commands/Attributes/GroupAttribute.cs b/src/Kook.Net.Commands/Attributes/GroupAttribute.cs
index f6f29391..15519d33 100644
--- a/src/Kook.Net.Commands/Attributes/GroupAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/GroupAttribute.cs
@@ -1,26 +1,28 @@
namespace Kook.Commands;
///
-/// Marks the module as a command group.
+/// 标记模块为命令组。
///
[AttributeUsage(AttributeTargets.Class)]
public class GroupAttribute : Attribute
{
///
- /// Gets the prefix set for the module.
+ /// 获取模块组命令的前缀。
///
public string? Prefix { get; }
- ///
+ ///
+ /// 初始化一个 类的新实例。
+ ///
public GroupAttribute()
{
Prefix = null;
}
///
- /// Initializes a new with the provided prefix.
+ /// 初始化一个 类的新实例。
///
- /// The prefix of the module group.
+ /// 模块组命令的前缀。
public GroupAttribute(string prefix)
{
Prefix = prefix;
diff --git a/src/Kook.Net.Commands/Attributes/NameAttribute.cs b/src/Kook.Net.Commands/Attributes/NameAttribute.cs
index a5e289c8..1c9fea2a 100644
--- a/src/Kook.Net.Commands/Attributes/NameAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/NameAttribute.cs
@@ -1,21 +1,20 @@
namespace Kook.Commands;
-// Override public name of command/module
///
-/// Marks the public name of a command, module, or parameter.
+/// 标记命令、模块或参数的基本名称。
///
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter)]
public class NameAttribute : Attribute
{
///
- /// Gets the name of the command.
+ /// 获取基本名称。
///
public string Text { get; }
///
- /// Marks the public name of a command, module, or parameter with the provided name.
+ /// 标记命令、模块或参数的基本名称。
///
- /// The public name of the object.
+ /// 基本名称。
public NameAttribute(string text)
{
Text = text;
diff --git a/src/Kook.Net.Commands/Attributes/NamedArgumentTypeAttribute.cs b/src/Kook.Net.Commands/Attributes/NamedArgumentTypeAttribute.cs
index c464b170..a51f0c3c 100644
--- a/src/Kook.Net.Commands/Attributes/NamedArgumentTypeAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/NamedArgumentTypeAttribute.cs
@@ -1,8 +1,28 @@
namespace Kook.Commands;
///
-/// Instructs the command system to treat command parameters of this type
-/// as a collection of named arguments matching to its properties.
+/// 指示命令系统将此类型的命令参数视为与其属性匹配的命名参数集合。
///
+///
+/// 以下示例代码中,ArgumentType 中的各个属性将被视为所支持的命名参数。
+///
+/// [NamedArgumentType]
+/// public sealed class ArgumentType
+/// {
+/// public int? Foo { get; set; }
+/// public string? Bar { get; set; }
+/// public IEnumerable<int>? ManyInts { get; set; }
+/// }
+///
+/// 命令的参数中可以定义 ArgumentType 类型的参数。
+///
+/// [Command("test")]
+/// public Task TestCommand(ArgumentType arg) => Task.CompletedTask;
+///
+/// 则可以以以下的命名参数的形式传递参数,调用命令:
+///
+/// foo: 3 bar: hello manyints: "1, 2, 3, 4, 5, 6, 7"
+///
+///
[AttributeUsage(AttributeTargets.Class)]
public sealed class NamedArgumentTypeAttribute : Attribute;
diff --git a/src/Kook.Net.Commands/Attributes/OverrideTypeReaderAttribute.cs b/src/Kook.Net.Commands/Attributes/OverrideTypeReaderAttribute.cs
index 35e1c0ee..fa262109 100644
--- a/src/Kook.Net.Commands/Attributes/OverrideTypeReaderAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/OverrideTypeReaderAttribute.cs
@@ -3,26 +3,24 @@
namespace Kook.Commands;
///
-/// Marks the to be read by the specified .
+/// 标记指定的参数应有应由指定的 读取并解析。
///
///
-/// This attribute will override the to be used when parsing for the
-/// desired type in the command. This is useful when one wishes to use a particular
-/// without affecting other commands that are using the same target
-/// type.
+/// 此特性允许在解析命令参数时为指定的参数指定特定的
+/// ,可用于在不影响其他命令的情况下使用特定的命令解析器。
+///
///
-/// If the given type reader does not inherit from , an
-/// will be thrown.
+/// 标记此特性的类型解析器类型必须继承自 ,否则将引发
+/// 异常。
///
///
///
-/// In this example, the will be read by a custom
-/// , FriendlyTimeSpanTypeReader, instead of the
-/// shipped by Kook.Net.
+/// 在以下的示例中, 类型的 time 参数将由自定义的类型解析器 FriendlyTimeSpanTypeReader
+/// 解析,而不是由内置的 解析。
///
/// [Command("time")]
-/// public Task GetTimeAsync([OverrideTypeReader(typeof(FriendlyTimeSpanTypeReader))]TimeSpan time)
-/// => ReplyAsync(time);
+/// public Task GetTimeAsync([OverrideTypeReader(typeof(FriendlyTimeSpanTypeReader))] TimeSpan time)
+/// => ReplyTextAsync(time);
///
///
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property)]
@@ -31,17 +29,19 @@ public sealed class OverrideTypeReaderAttribute : Attribute
private static readonly TypeInfo TypeReaderTypeInfo = typeof(TypeReader).GetTypeInfo();
///
- /// Gets the specified of the parameter.
+ /// 获取解析此参数所使用的类型解析器的类型。
///
public Type TypeReader { get; }
- ///
- /// The to be used with the parameter.
- /// The given does not inherit from .
+ ///
+ /// 初始化一个 类的新实例。
+ ///
+ /// 解析此参数所使用的类型解析器的类型。
+ /// 所提供的类型解析器类型不是 的派生类。
public OverrideTypeReaderAttribute(Type overridenTypeReader)
{
if (!TypeReaderTypeInfo.IsAssignableFrom(overridenTypeReader.GetTypeInfo()))
- throw new ArgumentException($"{nameof(overridenTypeReader)} must inherit from {nameof(TypeReader)}.");
+ throw new InvalidOperationException($"{nameof(overridenTypeReader)} must inherit from {nameof(TypeReader)}.");
TypeReader = overridenTypeReader;
}
}
diff --git a/src/Kook.Net.Commands/Attributes/ParameterPreconditionAttribute.cs b/src/Kook.Net.Commands/Attributes/ParameterPreconditionAttribute.cs
index 5e387e7f..0d46c249 100644
--- a/src/Kook.Net.Commands/Attributes/ParameterPreconditionAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/ParameterPreconditionAttribute.cs
@@ -1,19 +1,20 @@
namespace Kook.Commands;
///
-/// Requires the parameter to pass the specified precondition before execution can begin.
+/// 表示一个命令中的参数在其所属命令执行前需要符合的先决条件的基类。
///
-///
+///
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = true)]
public abstract class ParameterPreconditionAttribute : Attribute
{
///
- /// Checks whether the condition is met before execution of the command.
+ /// 检查命令执行上下文中的此参数是否满足此先决条件。
///
- /// The context of the command.
- /// The parameter of the command being checked against.
- /// The raw value of the parameter.
- /// The service collection used for dependency injection.
+ /// 命令执行上下文。
+ /// 要检查的参数信息。
+ /// 参数的原始值。
+ /// 依赖注入服务容器。
+ /// 一个表示异步检查操作的任务。任务的结果包含先决条件的结果。
public abstract Task CheckPermissionsAsync(ICommandContext context,
ParameterInfo parameter, object? value, IServiceProvider services);
}
diff --git a/src/Kook.Net.Commands/Attributes/PreconditionAttribute.cs b/src/Kook.Net.Commands/Attributes/PreconditionAttribute.cs
index 367868b2..969aad7c 100644
--- a/src/Kook.Net.Commands/Attributes/PreconditionAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/PreconditionAttribute.cs
@@ -1,28 +1,28 @@
namespace Kook.Commands;
///
-/// Requires the module or class to pass the specified precondition before execution can begin.
+/// 表示一个模块或类中的命令在执行前需要符合的先决条件的基类。
///
-///
+///
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)]
public abstract class PreconditionAttribute : Attribute
{
///
- /// Specifies a group that this precondition belongs to.
+ /// 获取或设置此先决条件所属的分组。
///
///
- /// of the same group require only one of the preconditions to pass in order to
- /// be successful (A || B). Specifying = null or not at all will
- /// require *all* preconditions to pass, just like normal (A && B).
+ /// 此属性所设置的先决条件分组用于先决条件的析取。
+ /// 同属于相同分组的所有先决条件中,存在一个满足条件的先决条件,则该组先决条件满足条件,组内的其它先决条件将被忽略(A || B)。
+ /// 不设置此属性,或设置为 null,则表示该先决条件不属于任何分组,与其它的无分组先决条件或先决条件组的结果合取(A && B)。
///
public string? Group { get; set; }
///
- /// When overridden in a derived class, uses the supplied string
- /// as the error message if the precondition doesn't pass.
- /// Setting this for a class that doesn't override
- /// this property is a no-op.
+ /// 获取或设置错误消息。
///
+ ///
+ /// 当在派生类中重写此虚属性时,用户代码设置在此属性的值将用于在报告错误时携带的错误,在未重写此属性的派生类中设置此属性为空操作。
+ ///
public virtual string? ErrorMessage
{
get => null;
@@ -30,10 +30,11 @@ public virtual string? ErrorMessage
}
///
- /// Checks if the has the sufficient permission to be executed.
+ /// 检查命令执行上下文中的此命令是否满足此先决条件。
///
- /// The context of the command.
- /// The command being executed.
- /// The service collection used for dependency injection.
+ /// 命令执行上下文。
+ /// 要执行的命令。
+ /// 依赖注入服务容器。
+ /// 一个表示异步检查操作的任务。任务的结果包含先决条件的结果。
public abstract Task CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services);
}
diff --git a/src/Kook.Net.Commands/Attributes/Preconditions/RequireBotPermissionAttribute.cs b/src/Kook.Net.Commands/Attributes/Preconditions/RequireBotPermissionAttribute.cs
index 07805af6..883d8348 100644
--- a/src/Kook.Net.Commands/Attributes/Preconditions/RequireBotPermissionAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/Preconditions/RequireBotPermissionAttribute.cs
@@ -1,40 +1,38 @@
namespace Kook.Commands;
///
-/// Requires the bot to have a specific permission in the channel a command is invoked in.
+/// 要求当前用户在命令调用所在的的频道或服务器拥有指定的权限。
///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class RequireBotPermissionAttribute : PreconditionAttribute
{
///
- /// Gets the specified of the precondition.
+ /// 获取此先决条件所要求的服务器权限。
///
public GuildPermission? GuildPermission { get; }
///
- /// Gets the specified of the precondition.
+ /// 获取此先决条件所要求的频道权限。
///
public ChannelPermission? ChannelPermission { get; }
- ///
+ ///
+ /// 获取或设置错误消息。
+ ///
public override string? ErrorMessage { get; set; }
///
- /// Gets or sets the error message if the precondition
- /// fails due to being run outside a Guild channel.
+ /// 获取或设置由于在服务器频道外执行命令而导致的先决条件失败的错误消息。
///
public string? NotAGuildErrorMessage { get; set; }
///
- /// Requires the bot account to have a specific .
+ /// 初始化一个 类的新实例。
///
///
- /// This precondition will always fail if the command is being invoked in a .
+ /// 设置此先决条件将导致命令在私有频道中无法使用。
///
- ///
- /// The that the bot must have. Multiple permissions can be specified
- /// by ORing the permissions together.
- ///
+ /// 所要求当前用户需要在命令调用所在的的服务器拥有的权限。
public RequireBotPermissionAttribute(GuildPermission permission)
{
GuildPermission = permission;
@@ -42,12 +40,12 @@ public RequireBotPermissionAttribute(GuildPermission permission)
}
///
- /// Requires that the bot account to have a specific .
+ /// 初始化一个 类的新实例。
///
- ///
- /// The that the bot must have. Multiple permissions can be
- /// specified by ORing the permissions together.
- ///
+ ///
+ /// 设置此先决条件将导致命令在私有频道中无法使用。
+ ///
+ /// 所要求当前用户需要在命令调用所在的的服务器频道拥有的权限。
public RequireBotPermissionAttribute(ChannelPermission permission)
{
ChannelPermission = permission;
diff --git a/src/Kook.Net.Commands/Attributes/Preconditions/RequireContextAttribute.cs b/src/Kook.Net.Commands/Attributes/Preconditions/RequireContextAttribute.cs
index 9bc832f3..5abf29c3 100644
--- a/src/Kook.Net.Commands/Attributes/Preconditions/RequireContextAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/Preconditions/RequireContextAttribute.cs
@@ -1,48 +1,52 @@
namespace Kook.Commands;
///
-/// Defines the type of command context (i.e. where the command is being executed).
+/// 表示一个运行命令支持的上下文类型。
///
[Flags]
public enum ContextType
{
///
- /// Specifies the command to be executed within a guild.
+ /// 命令可以在服务器内执行。
///
Guild = 0x01,
///
- /// Specifies the command to be executed within a DM.
+ /// 命令可以在私聊频道中执行。
///
DM = 0x02
}
///
-/// Requires the command to be invoked in a specified context (e.g. in guild, DM).
+/// 要求命令在指定的上下文类型中(例如在服务器内、私聊频道中)执行。
///
+///
+///
+/// [Command("secret")]
+/// [RequireContext(ContextType.DM | ContextType.Group)]
+/// public Task PrivateOnlyAsync()
+/// {
+/// return ReplyTextAsync("shh, this command is a secret");
+/// }
+///
+///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class RequireContextAttribute : PreconditionAttribute
{
///
- /// Gets the context required to execute the command.
+ /// 获取命令执行所需的上下文类型。
///
public ContextType Contexts { get; }
- ///
+ ///
+ /// 获取或设置错误消息。
+ ///
public override string? ErrorMessage { get; set; }
- /// Requires the command to be invoked in the specified context.
- /// The type of context the command can be invoked in. Multiple contexts can be specified by ORing the contexts together.
- ///
- ///
- /// [Command("secret")]
- /// [RequireContext(ContextType.DM | ContextType.Group)]
- /// public Task PrivateOnlyAsync()
- /// {
- /// return ReplyAsync("shh, this command is a secret");
- /// }
- ///
- ///
+ ///
+ /// 初始化一个 类的新实例。
+ ///
+ /// 命令执行所需的上下文类型。
public RequireContextAttribute(ContextType contexts)
{
Contexts = contexts;
diff --git a/src/Kook.Net.Commands/Attributes/Preconditions/RequireRoleAttribute.cs b/src/Kook.Net.Commands/Attributes/Preconditions/RequireRoleAttribute.cs
index 9aa75148..b38c9595 100644
--- a/src/Kook.Net.Commands/Attributes/Preconditions/RequireRoleAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/Preconditions/RequireRoleAttribute.cs
@@ -1,14 +1,8 @@
namespace Kook.Commands;
///
-/// Requires the user invoking the command to have a specified role.
+/// 要求调用命令的用户在命令调用所在的服务器拥有指定的角色。
///
-///
-/// This precondition will restrict the access of the command or module to a user with the specified role.
-/// If the precondition fails to be met, an erroneous will be returned with the
-/// message "Command can only be run by the specified user." For example, you can pass the guild manager role
-/// to restrict the command to the guild managers to be able to use it.
-///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class RequireRoleAttribute : PreconditionAttribute
{
@@ -16,24 +10,23 @@ public class RequireRoleAttribute : PreconditionAttribute
private readonly uint? _roleId;
///
- /// Gets or sets the error message if the precondition
- /// fails due to being run outside a Guild channel.
+ /// 获取或设置由于在服务器频道外执行命令而导致的先决条件失败的错误消息。
///
public string? NotAGuildErrorMessage { get; set; }
///
- /// Requires that the user invoking the command to have a specific Role.
+ /// 初始化一个 类的新实例。
///
- /// Id of the role that the user must have.
+ /// 所要求调用命令的用户需要在命令调用所在的的服务器拥有的角色的 ID。
public RequireRoleAttribute(uint roleId)
{
_roleId = roleId;
}
///
- /// Requires that the user invoking the command to have a specific Role.
+ /// 初始化一个 类的新实例。
///
- /// Name of the role that the user must have.
+ /// 所要求调用命令的用户需要在命令调用所在的的服务器拥有的角色的名称。
public RequireRoleAttribute(string roleName)
{
_roleName = roleName;
diff --git a/src/Kook.Net.Commands/Attributes/Preconditions/RequireUserAttribute.cs b/src/Kook.Net.Commands/Attributes/Preconditions/RequireUserAttribute.cs
index c6f09089..c13d0a49 100644
--- a/src/Kook.Net.Commands/Attributes/Preconditions/RequireUserAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/Preconditions/RequireUserAttribute.cs
@@ -1,17 +1,10 @@
namespace Kook.Commands;
///
-/// Requires the command to be invoked by the specified user.
+/// 要求调用命令的用户具有指定的 ID。
///
-///
-/// This precondition will restrict the access of the command or module to a specified user.
-/// If the precondition fails to be met, an erroneous will be returned with the
-/// message "Command can only be run by the specified user." For example, you can pass the owner of this bot
-/// application to restrict the command to the bot owner to be able to use it.
-///
///
-/// The following example restricts the command to a set of sensitive commands that only the specified user
-/// should be able to access.
+/// 以下代码示例将 admin 命令组限制为仅允许用户 ID 为 2810246202 的用户可以调用。
///
/// [RequireUser(2810246202)]
/// [Group("admin")]
@@ -20,6 +13,7 @@ namespace Kook.Commands;
/// [Command("exit")]
/// public async Task ExitAsync()
/// {
+/// await ReplyTextAsync("Goodbye!");
/// Environment.Exit(0);
/// }
/// }
@@ -31,15 +25,17 @@ public class RequireUserAttribute : PreconditionAttribute
private readonly ulong _userId;
///
- /// Initializes a new attribute with the specified user identifier.
+ /// 初始化一个 类的新实例。
///
- /// The identifier of the user.
+ /// 所要求调用命令的用户应具有的 ID。
public RequireUserAttribute(ulong userId)
{
_userId = userId;
}
- ///
+ ///
+ /// 获取或设置错误消息。
+ ///
public override string? ErrorMessage { get; set; }
///
diff --git a/src/Kook.Net.Commands/Attributes/Preconditions/RequireUserPermissionAttribute.cs b/src/Kook.Net.Commands/Attributes/Preconditions/RequireUserPermissionAttribute.cs
index 5719597e..39a553c1 100644
--- a/src/Kook.Net.Commands/Attributes/Preconditions/RequireUserPermissionAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/Preconditions/RequireUserPermissionAttribute.cs
@@ -1,40 +1,38 @@
namespace Kook.Commands;
///
-/// Requires the user invoking the command to have a specified permission.
+/// 要求调用命令的用户在命令调用所在的的频道或服务器拥有指定的权限。
///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class RequireUserPermissionAttribute : PreconditionAttribute
{
///
- /// Gets the specified of the precondition.
+ /// 获取此先决条件所要求的服务器权限。
///
public GuildPermission? GuildPermission { get; }
///
- /// Gets the specified of the precondition.
+ /// 获取此先决条件所要求的频道权限。
///
public ChannelPermission? ChannelPermission { get; }
- ///
+ ///
+ /// 获取或设置错误消息。
+ ///
public override string? ErrorMessage { get; set; }
///
- /// Gets or sets the error message if the precondition
- /// fails due to being run outside of a Guild channel.
+ /// 获取或设置由于在服务器频道外执行命令而导致的先决条件失败的错误消息。
///
public string? NotAGuildErrorMessage { get; set; }
///
- /// Requires that the user invoking the command to have a specific .
+ /// 初始化一个 类的新实例。
///
///
- /// This precondition will always fail if the command is being invoked in a .
+ /// 设置此先决条件将导致命令在私有频道中无法使用。
///
- ///
- /// The that the user must have. Multiple permissions can be
- /// specified by ORing the permissions together.
- ///
+ /// 所要求调用命令的用户需要在命令调用所在的的服务器拥有的权限。
public RequireUserPermissionAttribute(GuildPermission permission)
{
GuildPermission = permission;
@@ -42,12 +40,12 @@ public RequireUserPermissionAttribute(GuildPermission permission)
}
///
- /// Requires that the user invoking the command to have a specific .
+ /// 初始化一个 类的新实例。
///
- ///
- /// The that the user must have. Multiple permissions can be
- /// specified by ORing the permissions together.
- ///
+ ///
+ /// 设置此先决条件将导致命令在私有频道中无法使用。
+ ///
+ /// 所要求当前用户需要在命令调用所在的的频道拥有的权限。
public RequireUserPermissionAttribute(ChannelPermission permission)
{
ChannelPermission = permission;
diff --git a/src/Kook.Net.Commands/Attributes/PriorityAttribute.cs b/src/Kook.Net.Commands/Attributes/PriorityAttribute.cs
index 1080cba6..b11b2d87 100644
--- a/src/Kook.Net.Commands/Attributes/PriorityAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/PriorityAttribute.cs
@@ -1,19 +1,27 @@
namespace Kook.Commands;
///
-/// Sets priority of commands.
+/// 标记指定的命令的优先级。
///
[AttributeUsage(AttributeTargets.Method)]
public class PriorityAttribute : Attribute
{
///
- /// Gets the priority which has been set for the command.
+ /// 获取为命令设置的优先级。
///
public int Priority { get; }
///
- /// Initializes a new attribute with the given priority.
+ /// 初始化一个 类的新实例。
///
+ /// 为命令设置的优先级。
+ ///
+ /// 更大的数值表示更高的优先级。
+ /// 命令系统在命令匹配时,会根据输入参数的相似度和优先级来选择最匹配的命令。
+ /// 例如,通过提及用户传入用户类型的参数,可以为该参数贡献 1.0 的匹配相似分,而仅通过用户昵称传入用户类型的参数则最低只贡献 0.5 的匹配相似分。
+ /// 一般地,各个参数的匹配相似分均为不超过 1.0 的正数,命令系统将会对各个匹配的匹配相似分统计算术平均值,此平均值通常不会超过 1.0。
+ /// 在此基础上,优先级分数值会被累加到匹配相似分算术平均值的 0.99 倍之上,这表示,通常情况下,为命令之间设置量级超过 1 的优先级均可以使自定义匹配优先级生效。
+ ///
public PriorityAttribute(int priority)
{
Priority = priority;
diff --git a/src/Kook.Net.Commands/Attributes/RemainderAttribute.cs b/src/Kook.Net.Commands/Attributes/RemainderAttribute.cs
index f9fe76a0..23a28e1e 100644
--- a/src/Kook.Net.Commands/Attributes/RemainderAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/RemainderAttribute.cs
@@ -1,7 +1,7 @@
namespace Kook.Commands;
///
-/// Marks the input to not be parsed by the parser.
+/// 标记指定的参数将接收剩余未解析的所有输入值。
///
[AttributeUsage(AttributeTargets.Parameter)]
public class RemainderAttribute : Attribute;
diff --git a/src/Kook.Net.Commands/Attributes/RemarksAttribute.cs b/src/Kook.Net.Commands/Attributes/RemarksAttribute.cs
index 15020f36..80cab83d 100644
--- a/src/Kook.Net.Commands/Attributes/RemarksAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/RemarksAttribute.cs
@@ -1,21 +1,20 @@
namespace Kook.Commands;
-// Extension of the Cosmetic Summary, for Groups, Commands, and Parameters
///
-/// Attaches remarks to your commands.
+/// 标记命令的备注。
///
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
public class RemarksAttribute : Attribute
{
///
- /// Gets the remarks of the command.
+ /// 获取命令的备注。
///
public string Text { get; }
///
- /// Initializes a new attribute with the specified remarks.
+ /// 初始化一个 类的新实例。
///
- ///
+ /// 命令的备注。
public RemarksAttribute(string text)
{
Text = text;
diff --git a/src/Kook.Net.Commands/Attributes/SummaryAttribute.cs b/src/Kook.Net.Commands/Attributes/SummaryAttribute.cs
index 16eb1d4a..3ce43d5b 100644
--- a/src/Kook.Net.Commands/Attributes/SummaryAttribute.cs
+++ b/src/Kook.Net.Commands/Attributes/SummaryAttribute.cs
@@ -1,21 +1,20 @@
namespace Kook.Commands;
-// Cosmetic Summary, for Groups and Commands
///
-/// Attaches a summary to your command.
+/// 标记命令的摘要。
///
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter)]
public class SummaryAttribute : Attribute
{
///
- /// Gets the summary of the command.
+ /// 获取命令的摘要。
///
public string Text { get; }
///
- /// Initializes a new attribute with the specified summary.
+ /// 初始化一个 类的新实例。
///
- ///
+ /// 命令的摘要。
public SummaryAttribute(string text)
{
Text = text;
diff --git a/src/Kook.Net.Commands/Builders/CommandBuilder.cs b/src/Kook.Net.Commands/Builders/CommandBuilder.cs
index 5baadfd2..5784090b 100644
--- a/src/Kook.Net.Commands/Builders/CommandBuilder.cs
+++ b/src/Kook.Net.Commands/Builders/CommandBuilder.cs
@@ -1,7 +1,7 @@
namespace Kook.Commands.Builders;
///
-/// Represents a command builder.
+/// 表示一个命令构建器。
///
public class CommandBuilder
{
@@ -13,67 +13,68 @@ public class CommandBuilder
private readonly List _aliases;
///
- /// Gets the module builder that this command builder belongs to.
+ /// 获取此命令构建器所属的模块构建器。
///
public ModuleBuilder Module { get; }
///
- /// Gets or sets the callback that is invoked when this command is executed.
+ /// 获取或设置当执行此命令时调用的回调。
///
internal Func? Callback { get; set; }
///
- /// Gets or sets the name of this command.
+ /// 获取或设置此命令的基本名称。
///
public string? Name { get; set; }
///
- /// Gets or sets the summary of this command.
+ /// 获取或设置此命令的摘要。
///
public string? Summary { get; set; }
///
- /// Gets or sets the remarks of this command.
+ /// 获取或设置此命令的备注。
///
public string? Remarks { get; set; }
///
- /// Gets or sets the primary alias of this command.
+ /// 获取或设置此命令的首要别名。
///
public string? PrimaryAlias { get; set; }
///
- /// Gets or sets the run mode of this command.
+ /// 获取或设置此命令的运行模式。
///
public RunMode RunMode { get; set; }
///
- /// Gets or sets the priority of this command.
+ /// 获取或设置此命令的优先级。
///
+ ///
public int Priority { get; set; }
///
- /// Gets or sets whether the extra arguments should be ignored.
+ /// 获取或设置此命令是否忽略额外的参数。
///
public bool IgnoreExtraArgs { get; set; }
///
- /// Gets the preconditions of this command.
+ /// 获取此命令的先决条件。
///
public IReadOnlyList Preconditions => _preconditions;
///
- /// Gets the parameters of this command.
+ /// 获取此命令的参数构建器。
///
public IReadOnlyList Parameters => _parameters;
///
- /// Gets the attributes of this command.
+ /// 获取此命令的特性。
///
public IReadOnlyList Attributes => _attributes;
///
- /// Gets the aliases of this command.
+ /// 获取此命令的别名。
///
public IReadOnlyList Aliases => _aliases;
@@ -81,10 +82,6 @@ public class CommandBuilder
#region Automatic
- ///
- /// Initializes a new instance of the class.
- ///
- /// The module builder that this command builder belongs to.
internal CommandBuilder(ModuleBuilder module)
{
Module = module;
@@ -99,11 +96,11 @@ internal CommandBuilder(ModuleBuilder module)
#region User-defined
///
- /// Initializes a new instance of the class.
+ /// 初始化一个 类的新实例。
///
- /// The module builder that this command builder belongs to.
- /// The primary alias of this command.
- /// The callback that is invoked when this command is executed.
+ /// 此命令构建器所属的模块构建器。
+ /// 此命令的首要别名。
+ /// 当执行此命令时调用的回调。
internal CommandBuilder(ModuleBuilder module, string? primaryAlias,
Func callback)
: this(module)
@@ -117,10 +114,10 @@ internal CommandBuilder(ModuleBuilder module, string? primaryAlias,
}
///
- /// Sets the name of this command.
+ /// 设置此命令的基本名称。
///
- /// The name of this command.
- /// This command builder.
+ /// 此命令的基本名称。
+ /// 当前命令构建器。
public CommandBuilder WithName(string name)
{
Name = name;
@@ -128,10 +125,10 @@ public CommandBuilder WithName(string name)
}
///
- /// Sets the summary of this command.
+ /// 设置此命令的摘要。
///
- /// The summary of this command.
- /// This command builder.
+ /// 此命令的摘要。
+ /// 当前命令构建器。
public CommandBuilder WithSummary(string summary)
{
Summary = summary;
@@ -139,10 +136,10 @@ public CommandBuilder WithSummary(string summary)
}
///
- /// Sets the remarks of this command.
+ /// 设置此命令的备注。
///
- /// The remarks of this command.
- /// This command builder.
+ /// 此命令的备注。
+ /// 当前命令构建器。
public CommandBuilder WithRemarks(string remarks)
{
Remarks = remarks;
@@ -150,10 +147,10 @@ public CommandBuilder WithRemarks(string remarks)
}
///
- /// Sets the run mode of this command.
+ /// 设置此命令的运行模式。
///
- /// The run mode of this command.
- /// This command builder.
+ /// 此命令的运行模式。
+ /// 当前命令构建器。
public CommandBuilder WithRunMode(RunMode runMode)
{
RunMode = runMode;
@@ -161,10 +158,11 @@ public CommandBuilder WithRunMode(RunMode runMode)
}
///
- /// Sets the priority of this command.
+ /// 设置此命令的优先级。
///
- /// The priority of this command.
- /// This command builder.
+ /// 此命令的优先级。
+ /// 当前命令构建器。
+ ///
public CommandBuilder WithPriority(int priority)
{
Priority = priority;
@@ -172,10 +170,10 @@ public CommandBuilder WithPriority(int priority)
}
///
- /// Adds aliases to this command.
+ /// 向此命令添加别名。
///
- /// An array containing the aliases to add.
- /// This command builder.
+ /// 包含要添加的别名的数组。
+ /// 当前命令构建器。
public CommandBuilder AddAliases(params string?[] aliases)
{
foreach (string? x in aliases)
@@ -189,10 +187,10 @@ public CommandBuilder AddAliases(params string?[] aliases)
}
///
- /// Adds attributes to this command.
+ /// 添加特性到此命令。
///
- /// An array containing the attributes to add.
- /// This command builder.
+ /// 要添加的特性。
+ /// 当前命令构建器。
public CommandBuilder AddAttributes(params Attribute[] attributes)
{
_attributes.AddRange(attributes);
@@ -200,10 +198,10 @@ public CommandBuilder AddAttributes(params Attribute[] attributes)
}
///
- /// Adds a precondition to this command.
+ /// 添加先决条件到此命令。
///
- /// The precondition to add.
- /// This command builder.
+ /// 要添加的先决条件。
+ /// 当前命令构建器。
public CommandBuilder AddPrecondition(PreconditionAttribute precondition)
{
_preconditions.Add(precondition);
@@ -211,12 +209,12 @@ public CommandBuilder AddPrecondition(PreconditionAttribute precondition)
}
///
- /// Adds a parameter to this command.
+ /// 添加参数到此命令。
///
- /// The name of the parameter.
- /// An action delegate that is invoked to create the parameter.
- /// The type of the parameter.
- /// This command builder.
+ /// 参数的名称。
+ /// 一个创建参数构建器的委托。
+ /// 参数的类型。
+ /// 当前命令构建器。
public CommandBuilder AddParameter(string name, Action createFunc)
{
ParameterBuilder param = new(this, name, typeof(T));
@@ -226,12 +224,12 @@ public CommandBuilder AddParameter(string name, Action crea
}
///
- /// Adds a parameter to this command.
+ /// 添加参数到此命令。
///
- /// The name of the parameter.
- /// The type of the parameter.
- /// An action delegate that is invoked to create the parameter.
- /// This command builder.
+ /// 参数的名称。
+ /// 参数的类型。
+ /// 一个创建参数构建器的委托。
+ /// 当前命令构建器。
public CommandBuilder AddParameter(string name, Type type, Action createFunc)
{
ParameterBuilder param = new(this, name, type);
@@ -241,10 +239,10 @@ public CommandBuilder AddParameter(string name, Type type, Action
- /// Adds a parameter to this command.
+ /// 添加参数到此命令。
///
- /// An action delegate that is invoked to create the parameter.
- /// This command builder.
+ /// 一个创建参数构建器的委托。
+ /// 当前命令构建器。
internal CommandBuilder AddParameter(Action createFunc)
{
ParameterBuilder param = new(this);
@@ -254,12 +252,12 @@ internal CommandBuilder AddParameter(Action createFunc)
}
///
- /// Builds the command.
+ /// 构建此命令构建器。
///
- /// The module info.
- /// The command service.
- /// The command info.
- /// Only the last parameter in a command may have the Remainder or Multiple flag.
+ /// 此命令所属的模块信息。
+ /// 此命令所属的命令服务。
+ /// 此命令构建器构建的命令信息。
+ /// 仅支持在最后一个参数上设置接收全部剩余参数或接收多个参数。
internal CommandInfo Build(ModuleInfo info, CommandService service)
{
// Default name to primary alias
diff --git a/src/Kook.Net.Commands/Builders/ModuleBuilder.cs b/src/Kook.Net.Commands/Builders/ModuleBuilder.cs
index d7c5ec1b..11c0f9ad 100644
--- a/src/Kook.Net.Commands/Builders/ModuleBuilder.cs
+++ b/src/Kook.Net.Commands/Builders/ModuleBuilder.cs
@@ -3,7 +3,7 @@
namespace Kook.Commands.Builders;
///
-/// Represents a module builder.
+/// 表示一个模块构建器。
///
public class ModuleBuilder
{
@@ -17,32 +17,32 @@ public class ModuleBuilder
private readonly List _aliases;
///
- /// Gets the command service that this module builder belongs to.
+ /// 获取此模块构建器所属的命令服务。
///
public CommandService Service { get; }
///
- /// Gets the parent module builder that this module builder belongs to.
+ /// 获取此模块构建器所属的父模块构建器。
///
public ModuleBuilder? Parent { get; }
///
- /// Gets or sets the name of this module.
+ /// 获取或设置此模块的基本名称。
///
public string? Name { get; set; }
///
- /// Gets or sets the summary of this module.
+ /// 获取或设置此模块的摘要。
///
public string? Summary { get; set; }
///
- /// Gets or sets the remarks of this module.
+ /// 获取或设置此模块的备注。
///
public string? Remarks { get; set; }
///
- /// Gets or sets the group of this module.
+ /// 获取或设置此模块的分组。
///
public string? Group
{
@@ -57,27 +57,27 @@ public string? Group
}
///
- /// Gets a read-only list of commands that this module builder contains.
+ /// 获取此模块的别名。
///
public IReadOnlyList Commands => _commands;
///
- /// Gets a read-only list of submodules that this module builder contains.
+ /// 获取此模块的子模块。
///
public IReadOnlyList Modules => _submodules;
///
- /// Gets a read-only list of preconditions that this module builder contains.
+ /// 获取此模块的先决条件。
///
public IReadOnlyList Preconditions => _preconditions;
///
- /// Gets a read-only list of attributes that this module builder contains.
+ /// 获取此模块的特性。
///
public IReadOnlyList Attributes => _attributes;
///
- /// Gets a read-only list of aliases that this module builder contains.
+ /// 获取此模块的别名。
///
public IReadOnlyList Aliases => _aliases;
@@ -87,11 +87,6 @@ public string? Group
#region Automatic
- ///
- /// Initializes a new instance of the class.
- ///
- /// The command service that this module builder belongs to.
- /// The parent module builder that this module builder belongs to.
internal ModuleBuilder(CommandService service, ModuleBuilder? parent)
{
Service = service;
@@ -109,11 +104,11 @@ internal ModuleBuilder(CommandService service, ModuleBuilder? parent)
#region User-defined
///
- /// Initializes a new instance of the class.
+ /// 初始化一个 类的新实例。
///
- /// The command service that this module builder belongs to.
- /// The parent module builder that this module builder belongs to.
- /// The primary alias of this module.
+ /// 此模块构建器所属的命令服务。
+ /// 此模块构建器所属的父模块构建器。
+ /// 此模块的首要别名。
internal ModuleBuilder(CommandService service, ModuleBuilder? parent, string primaryAlias)
: this(service, parent)
{
@@ -122,10 +117,10 @@ internal ModuleBuilder(CommandService service, ModuleBuilder? parent, string pri
}
///
- /// Sets the name of this module.
+ /// 设置此模块的名基本称。
///
- /// The name of this module.
- /// This module builder.
+ /// 此模块的基本名称。
+ /// 此模块构建器。
public ModuleBuilder WithName(string name)
{
Name = name;
@@ -133,10 +128,10 @@ public ModuleBuilder WithName(string name)
}
///
- /// Sets the summary of this module.
+ /// 设置此模块的摘要。
///
- /// The summary of this module.
- /// This module builder.
+ /// 此模块的摘要。
+ /// 此模块构建器。
public ModuleBuilder WithSummary(string summary)
{
Summary = summary;
@@ -144,10 +139,10 @@ public ModuleBuilder WithSummary(string summary)
}
///
- /// Sets the remarks of this module.
+ /// 设置此模块的备注。
///
- /// The remarks of this module.
- /// This module builder.
+ /// 此模块的备注。
+ /// 此模块构建器。
public ModuleBuilder WithRemarks(string remarks)
{
Remarks = remarks;
@@ -155,10 +150,10 @@ public ModuleBuilder WithRemarks(string remarks)
}
///
- /// Adds aliases to this module.
+ /// 添加别名到此模块。
///
- /// An array of aliases to add to this module.
- /// This module builder.
+ /// 要添加到此模块的别名数组。
+ /// 此模块构建器。
public ModuleBuilder AddAliases(params string?[] aliases)
{
foreach (string? x in aliases)
@@ -172,10 +167,10 @@ public ModuleBuilder AddAliases(params string?[] aliases)
}
///
- /// Adds a precondition to this module.
+ /// 添加特性到此模块。
///
- /// An array of attributes to add to this module.
- /// This module builder.
+ /// 要添加到此模块的特性数组。
+ /// 此模块构建器。
public ModuleBuilder AddAttributes(params Attribute[] attributes)
{
_attributes.AddRange(attributes);
@@ -183,10 +178,10 @@ public ModuleBuilder AddAttributes(params Attribute[] attributes)
}
///
- /// Adds a precondition to this module.
+ /// 添加先决条件到此模块。
///
- /// The precondition to add to this module.
- /// This module builder.
+ /// 要添加到此模块的先决条件。
+ /// 此模块构建器。
public ModuleBuilder AddPrecondition(PreconditionAttribute precondition)
{
_preconditions.Add(precondition);
@@ -194,12 +189,12 @@ public ModuleBuilder AddPrecondition(PreconditionAttribute precondition)
}
///
- /// Adds a command to this module.
+ /// 添加命令到此模块。
///
- /// The primary alias of this command.
- /// The callback of this command.
- /// The function delegate that creates this command.
- /// This module builder.
+ /// 此命令的首要别名。
+ /// 当执行此命令时调用的回调。
+ /// 一个创建命令构建器的委托。
+ /// 此模块构建器。
public ModuleBuilder AddCommand(string primaryAlias,
Func callback,
Action createFunc)
@@ -211,10 +206,10 @@ public ModuleBuilder AddCommand(string primaryAlias,
}
///
- /// Adds a command to this module.
+ /// 添加命令到此模块。
///
- /// The function delegate that creates this command.
- /// This module builder.
+ /// 一个创建命令构建器的委托。
+ /// 此模块构建器。
internal ModuleBuilder AddCommand(Action createFunc)
{
CommandBuilder builder = new(this);
@@ -224,11 +219,11 @@ internal ModuleBuilder AddCommand(Action createFunc)
}
///
- /// Adds a module to this module.
+ /// 添加子模块到此模块。
///
- /// The primary alias of this module.
- /// The function delegate that creates this module.
- /// This module builder.
+ /// 此模块的首要别名。
+ /// 一个创建模块构建器的委托。
+ /// 此模块构建器。
public ModuleBuilder AddModule(string primaryAlias, Action createFunc)
{
ModuleBuilder builder = new(Service, this, primaryAlias);
@@ -238,10 +233,10 @@ public ModuleBuilder AddModule(string primaryAlias, Action create
}
///
- /// Adds a module to this module.
+ /// 添加子模块到此模块。
///
- /// The function delegate that creates this module.
- /// This module builder.
+ /// 一个创建模块构建器的委托。
+ /// 此模块构建器。
internal ModuleBuilder AddModule(Action createFunc)
{
ModuleBuilder builder = new(Service, this);
@@ -250,13 +245,6 @@ internal ModuleBuilder AddModule(Action createFunc)
return this;
}
- ///
- /// Builds this module builder into a module.
- ///
- /// The command service that this module builder belongs to.
- /// The service provider that this module builder belongs to.
- /// The parent module that this module builder belongs to.
- /// The built module.
private ModuleInfo BuildImpl(CommandService service, IServiceProvider services, ModuleInfo? parent = null)
{
//Default name to first alias
@@ -272,20 +260,20 @@ private ModuleInfo BuildImpl(CommandService service, IServiceProvider services,
}
///
- /// Builds this module builder into a module.
+ /// 构建此模块构建器为模块。
///
- /// The command service that this module builder belongs to.
- /// The service provider that this module builder belongs to.
- /// The built module.
+ /// 此模块构建器所属的命令服务。
+ /// 此模块构建器所属的服务提供程序。
+ /// 构建的模块。
public ModuleInfo Build(CommandService service, IServiceProvider services) => BuildImpl(service, services);
///
- /// Builds this module builder into a module.
+ /// 构建此模块构建器为模块。
///
- /// The command service that this module builder belongs to.
- /// The service provider that this module builder belongs to.
- /// The parent module that this module builder belongs to.
- /// The built module.
+ /// 此模块构建器所属的命令服务。
+ /// 此模块构建器所属的服务提供程序。
+ /// 此模块构建器所属的父模块。
+ /// 构建的模块。
internal ModuleInfo Build(CommandService service, IServiceProvider services, ModuleInfo parent) => BuildImpl(service, services, parent);
#endregion
diff --git a/src/Kook.Net.Commands/Builders/ModuleClassBuilder.cs b/src/Kook.Net.Commands/Builders/ModuleClassBuilder.cs
index 64c04fd1..e64183d9 100644
--- a/src/Kook.Net.Commands/Builders/ModuleClassBuilder.cs
+++ b/src/Kook.Net.Commands/Builders/ModuleClassBuilder.cs
@@ -33,7 +33,6 @@ bool IsLoadableModule(TypeInfo info) =>
&& info.GetCustomAttribute() == null;
}
-
public static Task> BuildAsync(CommandService service,
IServiceProvider services, params TypeInfo[] validTypes) =>
BuildAsync(validTypes, service, services);
diff --git a/src/Kook.Net.Commands/Builders/ParameterBuilder.cs b/src/Kook.Net.Commands/Builders/ParameterBuilder.cs
index d5a148a3..3cfdf884 100644
--- a/src/Kook.Net.Commands/Builders/ParameterBuilder.cs
+++ b/src/Kook.Net.Commands/Builders/ParameterBuilder.cs
@@ -3,7 +3,7 @@
namespace Kook.Commands.Builders;
///
-/// Represents a parameter builder.
+/// 表示一个参数构建器。
///
public class ParameterBuilder
{
@@ -13,57 +13,57 @@ public class ParameterBuilder
private readonly List _attributes;
///
- /// Gets the command builder that this parameter builder belongs to.
+ /// 获取此参数构建器所属的命令构建器。
///
public CommandBuilder Command { get; }
///
- /// Gets the name of this parameter.
+ /// 获取或设置此参数的名称。
///
public string Name { get; internal set; }
///
- /// Gets the type of this parameter.
+ /// 获取或设置此参数的类型。
///
public Type? ParameterType { get; internal set; }
///
- /// Gets the type reader of this parameter.
+ /// 获取或设置此参数的类型读取器。
///
public TypeReader? TypeReader { get; set; }
///
- /// Gets or sets a value that indicates whether this parameter is an optional parameter or not.
+ /// 获取或设置此参数是否为可选参数。
///
public bool IsOptional { get; set; }
///
- /// Gets or sets a value that indicates whether this parameter is a remainder parameter or not.
+ /// 获取或设置此参数是否接收全部剩余参数。
///
public bool IsRemainder { get; set; }
///
- /// Gets or sets a value that indicates whether this parameter is a multiple parameter or not.
+ /// 获取或设置此参数是否为多值参数。
///
public bool IsMultiple { get; set; }
///
- /// Gets or sets the default value of this parameter.
+ /// 获取或设置此参数的默认值。
///
public object? DefaultValue { get; set; }
///
- /// Gets or sets the summary of this parameter.
+ /// 获取或设置此参数的摘要。
///
public string? Summary { get; set; }
///
- /// Gets a read-only collection containing the preconditions of this parameter.
+ /// 获取此参数的先决条件。
///
public IReadOnlyList Preconditions => _preconditions;
///
- /// Gets a read-only collection containing the attributes of this parameter.
+ /// 获取此参数的特性。
///
public IReadOnlyList Attributes => _attributes;
@@ -71,10 +71,6 @@ public class ParameterBuilder
#region Automatic
- ///
- /// Initializes a new instance of the class.
- ///
- /// The command builder that this parameter builder belongs to.
internal ParameterBuilder(CommandBuilder command)
{
_preconditions = [];
@@ -87,12 +83,6 @@ internal ParameterBuilder(CommandBuilder command)
#region User-defined
- ///
- /// Initializes a new instance of the class.
- ///
- /// The command builder that this parameter builder belongs to.
- /// The name of this parameter.
- /// The type of this parameter.
internal ParameterBuilder(CommandBuilder command, string name, Type type)
: this(command)
{
@@ -101,10 +91,6 @@ internal ParameterBuilder(CommandBuilder command, string name, Type type)
SetType(type);
}
- ///
- /// Sets the type of this parameter.
- ///
- /// The type of this parameter.
internal void SetType(Type type)
{
TypeReader = GetReader(type);
@@ -115,12 +101,6 @@ internal void SetType(Type type)
ParameterType = type;
}
- ///
- /// Gets the type reader of this parameter.
- ///
- /// The type of this parameter.
- /// The type reader of this parameter.
- /// The type for the command must be a class with a public parameterless constructor to use as a NamedArgumentType.
private TypeReader? GetReader(Type? type)
{
if (type is null) return null;
@@ -151,16 +131,15 @@ internal void SetType(Type type)
return reader;
}
-
IDictionary? readers = commands.GetTypeReaders(type);
return readers != null ? readers.FirstOrDefault().Value : commands.GetDefaultTypeReader(type);
}
///
- /// Sets the summary of this parameter.
+ /// 设置此参数的摘要。
///
- /// The summary of this parameter.
- /// This parameter builder.
+ /// 此参数的摘要。
+ /// 此参数构建器。
public ParameterBuilder WithSummary(string summary)
{
Summary = summary;
@@ -168,10 +147,10 @@ public ParameterBuilder WithSummary(string summary)
}
///
- /// Sets the default value of this parameter.
+ /// 设置此参数的默认值。
///
- /// The default value of this parameter.
- /// This parameter builder.
+ /// 此参数的默认值。
+ /// 此参数构建器。
public ParameterBuilder WithDefault(object defaultValue)
{
DefaultValue = defaultValue;
@@ -179,10 +158,10 @@ public ParameterBuilder WithDefault(object defaultValue)
}
///
- /// Sets whether this parameter is an optional parameter or not.
+ /// 设置此参数是否为可选参数。
///
- /// Whether this parameter is an optional parameter or not.
- /// This parameter builder.
+ /// 此参数是否为可选参数。
+ /// 此参数构建器。
public ParameterBuilder WithIsOptional(bool isOptional)
{
IsOptional = isOptional;
@@ -190,10 +169,10 @@ public ParameterBuilder WithIsOptional(bool isOptional)
}
///
- /// Sets whether this parameter is a remainder parameter or not.
+ /// 设置此参数是否接收全部剩余参数。
///
- /// Whether this parameter is a remainder parameter or not.
- /// This parameter builder.
+ /// 此参数是否接收全部剩余参数。
+ /// 此参数构建器。
public ParameterBuilder WithIsRemainder(bool isRemainder)
{
IsRemainder = isRemainder;
@@ -201,10 +180,10 @@ public ParameterBuilder WithIsRemainder(bool isRemainder)
}
///
- /// Sets whether this parameter is a multiple parameter or not.
+ /// 设置此参数是否为多值参数。
///
- /// Whether this parameter is a multiple parameter or not.
- /// This parameter builder.
+ /// 此参数是否为多值参数。
+ /// 此参数构建器。
public ParameterBuilder WithIsMultiple(bool isMultiple)
{
IsMultiple = isMultiple;
@@ -212,10 +191,10 @@ public ParameterBuilder WithIsMultiple(bool isMultiple)
}
///
- /// Adds attributes to this parameter.
+ /// 添加特性到此参数。
///
- /// An array containing the attributes to add.
- /// This parameter builder.
+ /// 要添加到此参数的特性数组。
+ /// 此参数构建器。
public ParameterBuilder AddAttributes(params Attribute[] attributes)
{
_attributes.AddRange(attributes);
@@ -223,22 +202,16 @@ public ParameterBuilder AddAttributes(params Attribute[] attributes)
}
///
- /// Adds a precondition to this parameter.
+ /// 添加先决条件到此参数。
///
- /// The precondition to add.
- /// This parameter builder.
+ /// 要添加到此参数的先决条件。
+ /// 此参数构建器。
public ParameterBuilder AddPrecondition(ParameterPreconditionAttribute precondition)
{
_preconditions.Add(precondition);
return this;
}
- ///
- /// Builds this parameter builder.
- ///
- /// The command info that this parameter belongs to.
- /// The built parameter info.
- /// No type reader was found for this parameter, which must be specified.
internal ParameterInfo Build(CommandInfo info)
{
if ((TypeReader ??= GetReader(ParameterType)) is null)
diff --git a/src/Kook.Net.Commands/CommandContext.cs b/src/Kook.Net.Commands/CommandContext.cs
index 65367507..29e2f617 100644
--- a/src/Kook.Net.Commands/CommandContext.cs
+++ b/src/Kook.Net.Commands/CommandContext.cs
@@ -1,6 +1,6 @@
namespace Kook.Commands;
-/// The context of a command which may contain the client, user, guild, channel, and message.
+///
public class CommandContext : ICommandContext
{
///
@@ -18,14 +18,16 @@ public class CommandContext : ICommandContext
///
public IUserMessage Message { get; }
- /// Indicates whether the channel that the command is executed in is a private channel.
+ ///
+ /// 获取当前上下文是否为私有的执行上下文。
+ ///
public bool IsPrivate => Channel is IPrivateChannel;
///
- /// Initializes a new class with the provided client and message.
+ /// 初始化一个包含指定客户端和消息的 类的新实例。
///
- /// The underlying client.
- /// The underlying message.
+ /// 命令执行时所使用的客户端。
+ /// 命令解析的源消息。
public CommandContext(IKookClient client, IUserMessage msg)
{
Client = client;
diff --git a/src/Kook.Net.Commands/CommandError.cs b/src/Kook.Net.Commands/CommandError.cs
index 605b035c..bef4b21e 100644
--- a/src/Kook.Net.Commands/CommandError.cs
+++ b/src/Kook.Net.Commands/CommandError.cs
@@ -1,52 +1,61 @@
namespace Kook.Commands;
-/// Defines the type of error a command can throw.
+///
+/// 表示命令执行的错误。
+///
public enum CommandError
{
- //Search
+ // 搜索
+
///
- /// Thrown when the command is unknown.
+ /// 当命令未知时引发。
///
UnknownCommand = 1,
- //Parse
+ // 解析
+
///
- /// Thrown when the command fails to be parsed.
+ /// 当命令解析失败时引发。
///
ParseFailed,
///
- /// Thrown when the input text has too few or too many arguments.
+ /// 当输入文本的参数过少或过多时引发。
///
BadArgCount,
- //Parse (Type Reader)
- //CastFailed,
+ // 解析
+
+ // CastFailed,
+
///
- /// Thrown when the object cannot be found by the .
+ /// 当对象未被 找到时引发。
///
ObjectNotFound,
///
- /// Thrown when more than one object is matched by .
+ /// 当 匹配到多个对象时引发。
///
MultipleMatches,
- //Preconditions
+ // 先决条件
+
///
- /// Thrown when the command fails to meet a 's conditions.
+ /// 当命令未满足先决条件时引发。
///
UnmetPrecondition,
- //Execute
+ // 执行
+
///
- /// Thrown when an exception occurs mid-command execution.
+ /// 当命令执行时发生异常时引发。
///
Exception,
- //Runtime
+ // 运行时
+
///
- /// Thrown when the command is not successfully executed on runtime.
+ /// 当命令在运行时未成功执行时引发。
///
Unsuccessful
}
diff --git a/src/Kook.Net.Commands/CommandException.cs b/src/Kook.Net.Commands/CommandException.cs
index ec8c0ac8..d07e2470 100644
--- a/src/Kook.Net.Commands/CommandException.cs
+++ b/src/Kook.Net.Commands/CommandException.cs
@@ -1,24 +1,26 @@
namespace Kook.Commands;
///
-/// The exception that is thrown if another exception occurs during a command execution.
+/// 表示一个命令执行过程中发生的异常。
///
public class CommandException : Exception
{
- /// Gets the command that caused the exception.
+ ///
+ /// 获取异常的命令信息。
+ ///
public CommandInfo Command { get; }
- /// Gets the command context of the exception.
+ ///
+ /// 获取异常的命令上下文。
+ ///
public ICommandContext Context { get; }
///
- /// Initializes a new instance of the class using a
- /// information, a context, and the exception that
- /// interrupted the execution.
+ /// 初始化一个 类的新实例。
///
- /// The command information.
- /// The context of the command.
- /// The exception that interrupted the command execution.
+ /// 引发异常的命令。
+ /// 引发异常的命令上下文。
+ /// 引发的异常。
public CommandException(CommandInfo command, ICommandContext context, Exception? ex)
: base($"Error occurred executing {command.GetLogText(context)}.", ex)
{
diff --git a/src/Kook.Net.Commands/CommandMatch.cs b/src/Kook.Net.Commands/CommandMatch.cs
index 73e2d4d7..bb6f6f9a 100644
--- a/src/Kook.Net.Commands/CommandMatch.cs
+++ b/src/Kook.Net.Commands/CommandMatch.cs
@@ -1,21 +1,25 @@
namespace Kook.Commands;
///
-/// Represents a matched command.
+/// 表示一个匹配的命令。
///
public struct CommandMatch
{
- /// The command that matches the search result.
+ ///
+ /// 获取与搜索结果相匹配的命令。
+ ///
public CommandInfo Command { get; }
- /// The alias of the command.
+ ///
+ /// 获取命令的别名。
+ ///
public string Alias { get; }
///
- /// Initializes a new instance of the struct.
+ /// 初始化一个 结构的新实例。
///
- /// The command that matches the search result.
- /// The alias of the command.
+ /// 与搜索结果相匹配的命令。
+ /// 命令的别名。
public CommandMatch(CommandInfo command, string alias)
{
Command = command;
@@ -23,46 +27,46 @@ public CommandMatch(CommandInfo command, string alias)
}
///
- /// Checks the preconditions of this command.
+ /// 检查此命令的先决条件。
///
- /// The context of the command.
- /// The services to use.
- /// The result of the precondition check.
+ /// 命令的上下文。
+ /// 用于检查先决条件的以来服务提供程序。
+ /// 一个表示异步检查操作的任务。任务的结果包含先决条件的结果。
public Task CheckPreconditionsAsync(ICommandContext context,
IServiceProvider? services = null) =>
Command.CheckPreconditionsAsync(context, services);
///
- /// Parses this command.
+ /// 解析此命令。
///
- /// The context of the command.
- /// The search result of the command.
- /// The result of the precondition check.
- /// The services to use.
- /// The result of the parse.
+ /// 命令的上下文。
+ /// 搜索结果。
+ /// 先决条件的结果。
+ /// 用于解析的服务提供程序。
+ /// 一个表示异步解析操作的任务。任务的结果包含解析的结果。
public Task ParseAsync(ICommandContext context, SearchResult searchResult,
PreconditionResult? preconditionResult = null, IServiceProvider? services = null) =>
Command.ParseAsync(context, Alias.Length, searchResult, preconditionResult, services);
///
- /// Executes this command.
+ /// 执行此命令。
///
- /// The context of the command.
- /// The arguments of the command.
- /// The parameters of the command.
- /// The services to use.
- /// The result of the execution.
+ /// 命令的上下文。
+ /// 命令的实参。
+ /// 命令的形参。
+ /// 用于执行的服务提供程序。
+ /// 一个表示异步执行操作的任务。任务的结果包含执行的结果。
public Task ExecuteAsync(ICommandContext context, IEnumerable