@@ -42,7 +42,7 @@ CqWsSession session = new CqWsSession(new CqWsSessionOptions()
4242 UseEventEndPoint = true , // 使用事件终结点
4343 });
4444
45- await session .StartAsync (); // 开始连接
45+ await session .StartAsync (); // 开始连接
4646```
4747
4848要等待一个会话结束, 你需要使用 ` CqWsSession ` 的 ` WaitForShutdownAsync ` 方法
@@ -70,7 +70,7 @@ await session.RunAsync();
7070` CqPostPipeline ` 是用户处理上报的途径, 它符合中间件设计模型, 你可以直接使用使用它添加中间件.
7171
7272``` csharp
73- CqWsSession session ; // 要处理上报数据的会话
73+ // CqWsSession session; // 要处理上报数据的会话
7474session .PostPipeline .Use (async (context , next ) =>
7575{
7676 // context 为上报数据的上下文, 其中包含了具体的信息
@@ -87,8 +87,8 @@ session.PostPipeline.Use(async (context, next) =>
8787上述订阅方法将会处理所有的上报, 我们更推荐使用 ` EleCho.GoCqHttpSdk.CqPostContextExtensions ` 类所提供的拓展方法, 通过它你可以非常便捷的处理任何具体类型的事件
8888
8989``` csharp
90- CqWsSession session ; // 要处理上报数据的会话
91- session .PostPipeline . UseGroupMessage (async (context , next ) =>
90+ // CqWsSession session; // 要处理上报数据的会话
91+ session .UseGroupMessage (async (context , next ) =>
9292{
9393 // context 为 CqGroupMessagePostContext, 其中包含了群聊消息的具体信息
9494
@@ -97,8 +97,8 @@ session.PostPipeline.UseGroupMessage(async (context, next) =>
9797 // 简单实现一个复读机:
9898 if (context .RawMessage .StartsWith (" echo " ))
9999 {
100- string msg = context .RawMessage .SubString (5 ); // 获取 "echo " 后的字符
101- context .SendGroupMessageAsync (context .GroupId , new CqMessage (msg )); // 发送它 (关于消息发送后面会详细讲解)
100+ string msg = context .RawMessage .Substring (5 ); // 获取 "echo " 后的字符
101+ await session .SendGroupMessageAsync (context .GroupId , new CqMessage (msg )); // 发送它 (关于消息发送后面会详细讲解)
102102 }
103103
104104 await next ();
@@ -112,15 +112,15 @@ session.PostPipeline.UseGroupMessage(async (context, next) =>
112112` CqActionSender ` 是程序向 go-cqhttp 发送 "Action" 的途径, 其中需要实现 ` CqAction ` 的发送逻辑以及响应逻辑, 你可以直接使用它来调用任何 ` CqAction `
113113
114114``` csharp
115- CqWsSession session ; // 要使用 Action 的会话
116- session .ActionSender .SendActionAsync (new CqSendGroupMessageAction (群聊ID , new CqMessage { new CqTextMsg (" 一个文本消息" ) }));
115+ // CqWsSession session; // 要使用 Action 的会话
116+ int groupID = default ; // 群聊ID
117+ session .ActionSender .SendActionAsync (new CqSendGroupMessageAction (groupID , new CqMessage { new CqTextMsg (" 一个文本消息" ) }));
117118```
118119
119120可以看到, 使用 * session.ActionSender* 直接发送 ` Action ` 的步骤比较繁琐, 所以同样的, 推荐使用拓展方法, 它们由 ` EleCho.GoCqHttpSdk.CqActionSessionExtensions ` 提供.
120121
121122``` csharp
122- CqWsSession session ; // 要使用 Action 的会话
123- context .SendGroupMessageAsync (群聊ID , new CqMessage (" 一个文本消息" )); // 发送它 (关于消息发送后面会详细讲解)
123+ session .SendGroupMessageAsync (groupID , new CqMessage (" 一个文本消息" )); // 发送它 (关于消息发送后面会详细讲解)
124124```
125125
126126> ` EleCho.GoCqHttpSdk.CqActionSessionExtensions ` 类不直接为 ` CqActionSender ` 类提供拓展, 你只能在实现了 ` ICqActionSession ` 接口的类上调用这些拓展方法
@@ -137,16 +137,16 @@ class MyPostPlugin : CqPostPlugin
137137 if (context .Session is not ICqActionSession actionSession ) // 判断是否能够发送 Action
138138 return ;
139139
140- string text = context .Message .GetText () ;
140+ string text = context .Message .Text ;
141141 if (text .StartsWith (" TTS:" , StringComparison .OrdinalIgnoreCase ))
142142 {
143- await actionSession .SendGroupMessageAsync (context .GroupId , new CqTtsMsg (text [4 .. ]));
143+ await actionSession .SendGroupMessageAsync (context .GroupId , new CqMessage ( new CqTtsMsg (text [4 .. ]) ));
144144 }
145145 else if (text .StartsWith (" ToFace:" ))
146146 {
147147 if (CqFaceMsg .FromName (text [7 .. ]) is CqFaceMsg face )
148148
149- await actionSession .SendGroupMessageAsync (context .GroupId , face );
149+ await actionSession .SendGroupMessageAsync (context .GroupId , new CqMessage ( face ) );
150150 }
151151 }
152152
@@ -175,13 +175,11 @@ session.UsePlugin(new MyPostPlugin());
175175使用 ` EleCho.GoCqHttpSdk.MessageMatching ` , 你可以轻松实现对消息的正则匹配. 首先, 其提供的最基本的拓展方法如下:
176176
177177``` csharp
178- CqWsSession session ; // 需要添加处理中间件的会话
179-
180178// 匹配开头是 `echo` 和空格的消息
181179session .UseGroupMessageMatch (" $echo " , async (context , next ) =>
182180{
183181 // 发送复读消息
184- await session .SendGroupMessage (context .GroupId , context .Message .GetText () [5 .. ];
182+ await session .SendGroupMessageAsync (context .GroupId , new CqMessage ( context .Message .Text [5 .. ])) ;
185183});
186184```
187185
@@ -209,7 +207,7 @@ public class MyMessageMatchPlugin : CqMessageMatchPostPlugin
209207 )
210208 {
211209 // 将接收到的内容所匹配到的 context 值发送到消息所在群组
212- await ActionSession .SendGroupMessageAsync (context .GroupId , $" Captured content: {content }, index: {match .Index }" );
210+ await ActionSession .SendGroupMessageAsync (context .GroupId , new CqMessage ( $" Captured content: {content }, index: {match .Index }" ) );
213211
214212 // 如果当前方法的返回值是一个 Task, 那么这个 Task 会被等待, 如果你不希望它被等待, 你可以指定 void 作为返回值
215213 }
@@ -221,7 +219,7 @@ public class MyMessageMatchPlugin : CqMessageMatchPostPlugin
221219 // 即便你不在参数中指定 CqMessagePostContext, 你也可以通过插件的公开属性来获取当前上下文
222220 // 需要注意的是, 如果没有特意指定是群聊消息上下文或私聊消息上下文, 插件会处理任何消息
223221
224- Console .WriteLine (CurrentContext .Message .GetText () );
222+ Console .WriteLine (CurrentContext .Message .Text );
225223 }
226224}
227225```
@@ -239,7 +237,7 @@ session.UseMessageMatchPlugin(new MyMessageMatchPlugin(session));
239237使用 ` EleCho.GoCqHttpSdk.CommandExecuting ` , 你可以轻松实现机器人的指令功能, 下面是一个基本示例, 定义自己的命令执行插件:
240238
241239``` csharp
242- class MyCommandExecutePlugin : CqCommandExecutePostPlugin
240+ public class MyCommandExecutePlugin : CqCommandExecutePostPlugin
243241{
244242 [Command ]
245243 public int Add (int a , int b )
0 commit comments