/// <summary> /// 处理临时会话消息 /// </summary> /// <param name="pollData"></param> /// <returns></returns> public QQNotifyEvent ProcessSessionMsg(JObject pollData) { // {"retcode":0,"result":[{"poll_type":"sess_message", // "value":{"msg_id":25144,"from_uin":167017143,"to_uin":1070772010,"msg_id2":139233,"msg_type":140,"reply_ip":176752037,"time":1365931836,"id":2581801127,"ruin":444674479,"service_type":1, // "flags":{"text":1,"pic":1,"file":1,"audio":1,"video":1},"content":[["font",{"size":9,"color":"000000","style":[0,0,0],"name":"Tahoma"}],"2\u8F7D3 ",["face",1]," "]}}]} try { var store = Context.Store; var msg = new QQMsg(); var fromUin = pollData["from_uin"].ToObject<long>(); var fromQQ = pollData["ruin"].ToObject<long>();// 真实QQ var serviceType = pollData["service_type"].ToObject<int>(); // Group:0,Discuss:1 var typeId = pollData["id"].ToObject<long>(); // Group ID or Discuss ID msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"])); msg.Type = QQMsgType.SESSION_MSG; msg.To = Context.Account; var ticks = pollData["time"].ToObject<long>() * 1000; msg.Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks); QQUser user = store.GetBuddyByUin(fromUin); // 首先看看是不是自己的好友 if (user != null) { msg.Type = QQMsgType.BUDDY_MSG; // 是自己的好友 } else { if (serviceType == 0) { // 是群成员 var group = store.GetGroupByCode(typeId); if (group == null) { group = new QQGroup(); group.Code = typeId; // 获取群信息 var groupModule = Context.GetModule<GroupModule>(QQModuleType.GROUP); groupModule.GetGroupInfo(group, null); } foreach (QQGroupMember u in group.Members) { if (u.Uin == fromUin) { user = u; break; } } } else if (serviceType == 1) { // 是讨论组成员 var discuz = store.GetDiscuzByDid(typeId); if (discuz == null) { discuz = new QQDiscuz { Did = typeId }; // 获取讨论组信息 var discuzModule = Context.GetModule<DiscuzModule>(QQModuleType.DISCUZ); discuzModule.GetDiscuzInfo(discuz, null); } foreach (QQDiscuzMember u in discuz.Members) { if (u.Uin == fromUin) { user = u; break; } } } else { user = store.GetStrangerByUin(fromUin); // 看看陌生人列表中有木有 } if (user == null) { // 还没有就新建一个陌生人,原理来说不应该这样。后面我就不知道怎么回复这消息了,但是消息是不能丢失的 user = new QQStranger { QQ = pollData["ruin"].ToObject<long>(), Uin = fromUin, Nickname = pollData["ruin"] + "" }; store.AddStranger((QQStranger)user); // 获取用户信息 var userModule = Context.GetModule<UserModule>(QQModuleType.USER); userModule.GetStrangerInfo(user, null); } } user.QQ = fromQQ; // 带上QQ号码 msg.From = user; return new QQNotifyEvent(QQNotifyEventType.CHAT_MSG, msg); } catch (Exception ex) { return new QQNotifyEvent(QQNotifyEventType.NET_ERROR, ex); } }
/// <summary> /// 处理群消息 /// </summary> /// <param name="pollData"></param> /// <returns></returns> public QQNotifyEvent ProcessGroupMsg(JObject pollData) { // {"retcode":0,"result":[{"poll_type":"group_message", // "value":{"msg_id":6175,"from_uin":3924684389,"to_uin":1070772010,"msg_id2":992858,"msg_type":43,"reply_ip":176621921, // "group_code":3439321257,"send_uin":1843694270,"seq":875,"time":1365934781,"info_seq":170125666,"content":[["font",{"size":10,"color":"3b3b3b","style":[0,0,0],"name":"\u5FAE\u8F6F\u96C5\u9ED1"}],"eeeeeeeee "]}}]} try { var store = Context.Store; var msg = new QQMsg { Id = pollData["msg_id"].ToObject<long>(), Id2 = pollData["msg_id2"].ToObject<long>() }; var fromUin = pollData["send_uin"].ToObject<long>(); var groupCode = pollData["group_code"].ToObject<long>(); var groupId = pollData["info_seq"].ToObject<long>(); // 真实群号码 var group = store.GetGroupByCode(groupCode); if (group == null) { var groupModule = Context.GetModule<GroupModule>(QQModuleType.GROUP); group = new QQGroup { Code = groupCode, Gid = groupId }; // put to store store.AddGroup(group); groupModule.GetGroupInfo(group, null); } if (group.Gid <= 0) { group.Gid = groupId; } msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"])); msg.Type = QQMsgType.GROUP_MSG; msg.To = Context.Account; var ticks = pollData["time"].ToObject<long>() * 1000; msg.Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks); msg.Group = group; msg.From = group.GetMemberByUin(fromUin); if (msg.From == null) { var member = new QQGroupMember { Uin = fromUin }; msg.From = member; group.Members.Add(member); // 获取用户信息 var userModule = Context.GetModule<UserModule>(QQModuleType.USER); userModule.GetUserInfo(member, null); } return new QQNotifyEvent(QQNotifyEventType.CHAT_MSG, msg); } catch (Exception ex) { return new QQNotifyEvent(QQNotifyEventType.NET_ERROR, ex); } }
/// <summary> /// 处理讨论组信息 /// </summary> /// <param name="pollData"></param> /// <returns></returns> public QQNotifyEvent ProcessDiscuzMsg(JObject pollData) { try { var store = Context.Store; var msg = new QQMsg(); var fromUin = pollData["send_uin"].ToObject<long>(); var did = pollData["did"].ToObject<long>(); msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"])); msg.Type = QQMsgType.DISCUZ_MSG; msg.Discuz = store.GetDiscuzByDid(did); msg.To = Context.Account; var ticks = pollData["time"].ToObject<long>() * 1000; msg.Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks); if (msg.Discuz == null) { var discuz = new QQDiscuz(); discuz.Did = did; store.AddDiscuz(discuz); msg.Discuz = store.GetDiscuzByDid(did); var discuzModule = Context.GetModule<DiscuzModule>(QQModuleType.DISCUZ); discuzModule.GetDiscuzInfo(discuz, null); } msg.From = msg.Discuz.GetMemberByUin(fromUin); if (msg.From == null) { var member = new QQDiscuzMember { Uin = fromUin }; msg.From = member; msg.Discuz.Members.Add(member); // 获取用户信息 var userModule = Context.GetModule<UserModule>(QQModuleType.USER); userModule.GetUserInfo(member, null); } return new QQNotifyEvent(QQNotifyEventType.CHAT_MSG, msg); } catch (Exception ex) { return new QQNotifyEvent(QQNotifyEventType.NET_ERROR, ex); } }
/// <summary> /// 处理好友信息 /// </summary> /// <param name="pollData"></param> /// <returns></returns> public QQNotifyEvent ProcessBuddyMsg(JObject pollData) { try { var store = Context.Store; var fromUin = pollData["from_uin"].ToObject<long>(); var msg = new QQMsg { Id = pollData["msg_id"].ToObject<long>(), Id2 = pollData["msg_id2"].ToObject<long>() }; msg.ParseContentList(JsonConvert.SerializeObject(pollData["content"])); msg.Type = QQMsgType.BUDDY_MSG; msg.To = Context.Account; msg.From = store.GetBuddyByUin(fromUin); var ticks = pollData["time"].ToObject<long>() * 1000; msg.Date = ticks > DateTime.MaxValue.Ticks ? DateTime.Now : new DateTime(ticks); if (msg.From == null) { QQUser member = store.GetStrangerByUin(fromUin); // 搜索陌生人列表 if (member == null) { member = new QQHalfStranger { Uin = fromUin }; store.AddStranger((QQStranger)member); // 获取用户信息 var userModule = Context.GetModule<UserModule>(QQModuleType.USER); userModule.GetUserInfo(member, null); } msg.From = member; } return new QQNotifyEvent(QQNotifyEventType.CHAT_MSG, msg); } catch (Exception ex) { return new QQNotifyEvent(QQNotifyEventType.NET_ERROR, ex); } }