Пример #1
0
        private static void UpdateGroupList(int i)
        {
            List <GroupInfo>            list    = CqApi.GetGroupList().Data;
            List <GroupMemberGroupInfo> newList = new List <GroupMemberGroupInfo>();

            foreach (var groupInfo in list)
            {
                try
                {
                    GroupInfoV2 v2 = CqApi.GetGroupInfoV2(groupInfo.GroupId.ToString()).Data;
                    v2.Members = CqApi.GetGroupMemberList(v2.GroupId.ToString()).Data /*.Where(q => q.Role == "member")*/.ToList();
                    if (i % 6 == 0)
                    {
                        foreach (var groupMember in v2.Members)
                        {
                            var user = newList.FirstOrDefault(m => m.UserId == groupMember.UserId);
                            if (user == null)
                            {
                                newList.Add(new GroupMemberGroupInfo(groupMember.UserId));
                            }
                            user = newList.FirstOrDefault(m => m.UserId == groupMember.UserId);
                            if (!user.GroupIdList.Contains(groupInfo.GroupId))
                            {
                                user.GroupIdList.Add(groupInfo.GroupId);
                            }
                        }
                    }
                    CoolQDispatcher.SessionInfo.AddOrUpdateGroup(v2);
                    Logger.Success($"{groupInfo.GroupName} ({groupInfo.GroupId}): 管理{v2.Admins.Count}人, 成员{v2.Members.Count}人.");
                }
                catch (Exception)
                {
                    Logger.Error($"{groupInfo.GroupName} ({groupInfo.GroupId}) 加载失败。");
                }
            }

            string[] oldGroups  = CoolQDispatcher.SessionInfo.Sessions.Select(k => k.Value.Id).ToArray();
            string[] newGroups  = list.Select(k => k.GroupId.ToString()).ToArray();
            string[] noUseGroup = oldGroups.Where(k => !newGroups.Contains(k)).ToArray();
            foreach (var groupId in noUseGroup)
            {
                try
                {
                    CoolQDispatcher.SessionInfo.RemoveGroup(groupId);
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            if (i % 6 == 0)
            {
                CoolQDispatcher.GroupMemberGroupInfo = newList;
            }
        }
Пример #2
0
        public override CommonMessageResponse Message_Received(CommonMessage messageObj)
        {
            string sessionId   = null;
            var    sessionType = MessageType.Private;

            if (messageObj.PermissionLevel != PermissionLevel.Root)
            {
                return(new CommonMessageResponse(LoliReply.RootOnly, messageObj));
            }
            if (Message == null)
            {
                return(new CommonMessageResponse("你要说什么……", messageObj));
            }
            if (GroupId != null && DiscussId != null)
            {
                return(new CommonMessageResponse("不能同时选择群和讨论组……", messageObj));
            }

            string innerMessage = Decode(Message);

            if (UseAllGroup)
            {
                sessionType = MessageType.Group;
                List <GroupInfo> list       = CqApi.GetGroupList().Data;
                List <string>    failedList = new List <string>();
                string           ok         = $"◈◈ {DateTime.Now:M月d日 H:mm}公告 ◈◈{Environment.NewLine}";
                string           msg        = ok + innerMessage;
                if (list?.Count > 0)
                {
                    foreach (var groupInfo in list)
                    {
                        try
                        {
                            sessionId = groupInfo.GroupId.ToString();
                            SendMessage(new CommonMessageResponse(msg, new Identity(sessionId, sessionType)));
                            Thread.Sleep(3000);
                        }
                        catch
                        {
                            failedList.Add($"({groupInfo.GroupId}) {groupInfo.GroupName}");
                        }
                    }
                }
                else
                {
                    return(new CommonMessageResponse("无有效群。", messageObj));
                }

                SaveLogs(msg, "announcement");
                if (failedList.Count == 0)
                {
                    return(new CommonMessageResponse("已成功发送至" + list.Count + "个群。", messageObj));
                }
                else
                {
                    return(new CommonMessageResponse(string.Format("有以下{0}个群未成功发送: {1}{2}", failedList.Count,
                                                                   Environment.NewLine, string.Join(Environment.NewLine, failedList)), messageObj));
                }
            }
            if (DiscussId != null)
            {
                sessionId   = DiscussId;
                sessionType = MessageType.Discuss;
            }
            else if (GroupId != null)
            {
                sessionId   = GroupId;
                sessionType = MessageType.Group;
            }
            if (UserId != null)
            {
                sessionId = UserId;
            }

            if (DiscussId == null && GroupId == null && UserId == null)
            {
                return(new CommonMessageResponse(Decode(messageObj.ArgString), messageObj));
            }

            SendMessage(new CommonMessageResponse(innerMessage, new Identity(sessionId, sessionType)));
            return(null);
        }