/// <summary> /// 自身事件处理和分发 /// </summary> /// <param name="messageJson">消息</param> /// <param name="connection">连接GUID</param> private async void SelfMessageAdapter(JObject messageJson, Guid connection) { switch (GetMessageType(messageJson)) { case "group": { ApiGroupMsgEventArgs groupMsg = messageJson.ToObject <ApiGroupMsgEventArgs>(); if (groupMsg == null) { break; } Log.Debug("Sora", $"Group self msg[{groupMsg.GroupId}] -> {groupMsg.RawMessage}"); //执行回调 if (OnSelfMessage == null) { break; } await OnSelfMessage("Message", new GroupMessageEventArgs(connection, "group", groupMsg)); break; } default: Log.Warning("Sora|Message", $"接收到未知事件[{GetMessageType(messageJson)}]"); break; } }
/// <summary> /// 初始化 /// </summary> /// <param name="connectionGuid">服务器链接标识</param> /// <param name="eventName">事件名</param> /// <param name="groupMsgArgs">群消息事件参数</param> internal GroupMessageEventArgs(Guid connectionGuid, string eventName, ApiGroupMsgEventArgs groupMsgArgs ) : base(connectionGuid, eventName, groupMsgArgs.SelfID, groupMsgArgs.Time) { this.IsAnonymousMessage = groupMsgArgs.Anonymous == null; this.Message = new Message(connectionGuid, groupMsgArgs.MessageId, groupMsgArgs.RawMessage, MessageParse.ParseMessageList(groupMsgArgs.MessageList), groupMsgArgs.Time, groupMsgArgs.Font); this.Sender = new User(connectionGuid, groupMsgArgs.UserId); this.SourceGroup = new Group(connectionGuid, groupMsgArgs.GroupId); this.SenderInfo = groupMsgArgs.SenderInfo; }
/// <summary> /// 初始化 /// </summary> /// <param name="connectionGuid">服务器链接标识</param> /// <param name="eventName">事件名</param> /// <param name="groupMsgArgs">群消息事件参数</param> internal GroupMessageEventArgs(Guid connectionGuid, string eventName, ApiGroupMsgEventArgs groupMsgArgs ) : base(connectionGuid, eventName, groupMsgArgs.SelfID, groupMsgArgs.Time) { this.IsAnonymousMessage = groupMsgArgs.Anonymous != null; //将api消息段转换为CQ码 this.Message = new Message(connectionGuid, groupMsgArgs.MessageId, groupMsgArgs.RawMessage, MessageParse.Parse(groupMsgArgs.MessageList), groupMsgArgs.Time, groupMsgArgs.Font, groupMsgArgs.MessageSequence); this.Sender = new User(connectionGuid, groupMsgArgs.UserId); this.SourceGroup = new Group(connectionGuid, groupMsgArgs.GroupId); this.SenderInfo = groupMsgArgs.SenderInfo; this.Anonymous = IsAnonymousMessage ? groupMsgArgs.Anonymous : null; }
/// <summary> /// 消息事件处理和分发 /// </summary> /// <param name="messageJson">消息</param> /// <param name="connection">连接GUID</param> private async void MessageAdapter(JObject messageJson, Guid connection) { switch (GetMessageType(messageJson)) { //私聊事件 case "private": ApiPrivateMsgEventArgs privateMsg = messageJson.ToObject <ApiPrivateMsgEventArgs>(); if (privateMsg == null) { break; } ConsoleLog.Debug("Sora", $"Private msg {privateMsg.SenderInfo.Nick}({privateMsg.UserId}) : {privateMsg.RawMessage}"); //执行回调函数 if (OnPrivateMessage == null) { break; } await OnPrivateMessage(typeof(EventInterface), new PrivateMessageEventArgs(connection, "private", privateMsg)); break; //群聊事件 case "group": ApiGroupMsgEventArgs groupMsg = messageJson.ToObject <ApiGroupMsgEventArgs>(); if (groupMsg == null) { break; } ConsoleLog.Debug("Sora", $"Group msg[{groupMsg.GroupId}] form {groupMsg.SenderInfo.Nick}[{groupMsg.UserId}] : {groupMsg.RawMessage}"); //执行回调函数 if (OnGroupMessage == null) { break; } await OnGroupMessage(typeof(EventInterface), new GroupMessageEventArgs(connection, "group", groupMsg)); break; default: ConsoleLog.Warning("Sora", $"接收到未知事件[{GetMessageType(messageJson)}]"); break; } }
/// <summary> /// 消息事件处理和分发 /// </summary> /// <param name="messageJson">消息</param> /// <param name="connection">连接GUID</param> private async void MessageAdapter(JObject messageJson, Guid connection) { switch (GetMessageType(messageJson)) { //私聊事件 case "private": { var privateMsg = messageJson.ToObject<ApiPrivateMsgEventArgs>(); if (privateMsg == null) break; Log.Debug("Sora", $"Private msg {privateMsg.SenderInfo.Nick}({privateMsg.UserId}) <- {privateMsg.RawMessage}"); var eventArgs = new PrivateMessageEventArgs(connection, "private", privateMsg); //处理指令 if (!await CommandManager.CommandAdapter(eventArgs)) break; //执行回调 if (OnPrivateMessage == null) break; await OnPrivateMessage("Message", eventArgs); break; } //群聊事件 case "group": { ApiGroupMsgEventArgs groupMsg = messageJson.ToObject<ApiGroupMsgEventArgs>(); if (groupMsg == null) break; Log.Debug("Sora", $"Group msg[{groupMsg.GroupId}] form {groupMsg.SenderInfo.Nick}[{groupMsg.UserId}] <- {groupMsg.RawMessage}"); var eventArgs = new GroupMessageEventArgs(connection, "group", groupMsg); //处理指令 if (!await CommandManager.CommandAdapter(eventArgs)) break; //执行回调 if (OnGroupMessage == null) break; await OnGroupMessage("Message", eventArgs); break; } default: Log.Warning("Sora|Message", $"接收到未知事件[{GetMessageType(messageJson)}]"); break; } }