EleCho.GoCqHttpSdk.MessageMatching 1.0.6

Prefix Reserved
dotnet add package EleCho.GoCqHttpSdk.MessageMatching --version 1.0.6                
NuGet\Install-Package EleCho.GoCqHttpSdk.MessageMatching -Version 1.0.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EleCho.GoCqHttpSdk.MessageMatching" Version="1.0.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EleCho.GoCqHttpSdk.MessageMatching --version 1.0.6                
#r "nuget: EleCho.GoCqHttpSdk.MessageMatching, 1.0.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EleCho.GoCqHttpSdk.MessageMatching as a Cake Addin
#addin nuget:?package=EleCho.GoCqHttpSdk.MessageMatching&version=1.0.6

// Install EleCho.GoCqHttpSdk.MessageMatching as a Cake Tool
#tool nuget:?package=EleCho.GoCqHttpSdk.MessageMatching&version=1.0.6                

EleCho.GoCqHttpSdk.MessageMatching

EleCho.GoCqHttpSdk 的消息匹配拓展

功能:

提供基于正则匹配的消息上报处理拓展以及插件基类

使用:

包提供了拓展的中间件处理拓展, 你可以这样使用:

CqWsSession session;   // 需要添加处理中间件的会话

// 匹配开头是 `echo` 和空格的消息
session.UseGroupMessageMatch("$echo ", async (context, next) =>
{
    // 发送复读消息
    await session.SendGroupMessage(context.GroupId, context.Message.GetText()[5..];
});

包提供了插件基类, 你可以这样使用:

public class MyMessageMatchPlugin : CqMessageMatchPostPlugin
{
    public MyMessageMatchPlugin(ICqActionSession actionSession)
    {
        ActionSession = actionSession;
    }

    public ICqActionSession ActionSession { get; }

    // 通过 CqMessageMatch 来指定匹配规则 (例如这里非贪婪匹配两个中括号之间的任意内容, 并命名为 content 组)
    [CqMessageMatch(@"\[(?<content>.*?)\]")]
    public async Task MyMessageMatchPluginMethod(CqGroupMessagePostContext context, Match match, string content)
    {
        // 你可以在参数中指定一个合适的 CqMessagePostContext 用来接收消息上报数据
        //   它可以是 CqMessagePostContext, CqPrivateMessagePostContext, CqGroupMessagePostContext
        
        // 如果你指定了一个 Match 类型的参数, 正则匹配返回的 Match 会被传入
        // 如果你指定了字符串类型的参数, 则会自动从正则的 Groups 中取值, 并传入
    
        // 将接收到的内容所匹配到的 context 值发送到消息所在群组
        await ActionSession.SendGroupMessageAsync(context.GroupId, $"Captured content: {content}, index: {match.Index}");
        
        // 如果当前方法的返回值是一个 Task, 那么这个 Task 会被等待, 如果你不希望它被等待, 你可以指定 void 作为返回值
    }

    // 类中所有带有 CqMessageMatch 特性的方法都会被插件处理, 例如这里匹配所有消息并打印到控制台
    [CqMessageMatch(@"")]
    public void LogAllMessages()
    {
        // 即便你不在参数中指定 CqMessagePostContext, 你也可以通过插件的公开属性来获取当前上下文
        // 需要注意的是, 如果没有特意指定是群聊消息上下文或私聊消息上下文, 插件会处理任何消息

        Console.WriteLine(CurrentContext.Message.GetText());
    }
}

使用插件, 只需要调用 UseMessageMatchPlugin 拓展方法即可


EleCho.GoCqHttpSdk 提供了甚至令人难以坐和放宽的拓展功能,从此再也不需要使用令人难以琢磨的标记,按下功率,享受轻松光亮的拓展背包吧

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.6 237 10/5/2023
1.0.5 192 7/15/2023
1.0.4 186 5/12/2023
1.0.3 257 3/19/2023
1.0.2 260 3/8/2023
1.0.1 281 2/23/2023
1.0.0 356 2/12/2023
1.0.0-alpha1 144 2/4/2023