public override object ExecuteHaveAuth()
        {
            AppInfo appInfo = this.App.Library.AppInfo;

            // 获取用来撤回消息的机器人QQ
            QQ qq = this.Simulator.DataPool.RobotQQ;
            // 根据消息 Id 查询是否存在目标消息
            Message msg = this.Simulator.DataPool.MessageCollection.Where(p => p.Id == this.MsgId).FirstOrDefault();

            if (msg == null)
            {
                Logger.Instance.Info(appInfo.Name, TYPE_MSG_UNDO, $"无法撤回消息 [ID: {this.MsgId}], 指定的消息不存在");
                return(RESULT_MSG_NOT_FOUND);
            }
            else
            {
                bool result = false;

                // 如果是群消息
                if (msg.FromGroup != null && msg.FromGroup == null)
                {
                    // 获取当前机器人QQ在这个群的群成员信息
                    GroupMember robotMember = msg.FromGroup.MemberCollection.Where(p => p.Id == qq.Id).FirstOrDefault();
                    // 获取当前消息发送者QQ的群成员信息
                    GroupMember fromMember = msg.FromQQ as GroupMember;

                    if (!robotMember.Equals(fromMember))
                    {
                        // 如果 机器人QQ是管理并且消息来源QQ是群主
                        if (robotMember.MemberType == GroupMemberType.Manager && fromMember.MemberType == GroupMemberType.Creator)
                        {
                            Logger.Instance.Info(appInfo.Name, TYPE_MSG_UNDO, $"无法撤回消息");
                            return(RESULT_MSG_NOT_AUTHORIZE);
                        }

                        // 如果 机器人QQ是群主并且消息来源QQ是管理或群成员 或者 机器人QQ是管理并且消息来源QQ是群成员
                        if ((robotMember.MemberType == GroupMemberType.Creator && (fromMember.MemberType == GroupMemberType.Normal || fromMember.MemberType == GroupMemberType.Manager)) || (robotMember.MemberType == GroupMemberType.Manager && (fromMember.MemberType == GroupMemberType.Normal)))
                        {
                            // 强制撤回消息
                            result = msg.Revocation(true);
                        }
                    }
                }
                else
                {
                    result = msg.Revocation(false);
                }

                if (result)
                {
                    Logger.Instance.InfoSuccess(appInfo.Name, TYPE_MSG_UNDO, $"已撤回消息 [ID: {msg.Id}]");
                    return(RESULT_SUCCESS);
                }
                else
                {
                    Logger.Instance.Info(appInfo.Name, TYPE_MSG_UNDO, $"撤回消息 [ID: {msg.Id}] 失败, 消息已发送超过 2分钟");
                    return(RESULT_MSG_OVERDUE);
                }
            }
        }
Exemplo n.º 2
0
        public void TestNotEquals2()
        {
            GroupMember member1 = new GroupMember(validGuid, "Name", GroupMemberTypes.OnPremAd);
            GroupMember member2 = new GroupMember(validGuid, "Name", GroupMemberTypes.AzureAd);

            Assert.False(member1.Equals(member2));
        }
Exemplo n.º 3
0
        private bool IsMemberGroup(Group group, GroupMember memberGroup, int recursionCount)
        {
            if (recursionCount > MaxGroupNestingRecursion)
            {
                throw new InvalidOperationException("The maximum depth of group nesting has been exceeded, stopping recursive function.");
            }

            bool isMember = false;

            foreach (GroupMember member in group.GroupMembers.Where(x => x.IsGroup))
            {
                if (memberGroup.Equals(member))
                {
                    isMember = true;
                }
                else
                {
                    Group nestedGroup = this.groupRepository.GroupNamed(member.TenantId, member.Name);
                    if (nestedGroup != null)
                    {
                        int nextRecursionCount = (recursionCount + 1);

                        isMember = this.IsMemberGroup(nestedGroup, memberGroup, nextRecursionCount);
                    }
                }

                if (isMember)
                {
                    break;
                }
            }

            return(isMember);
        }
Exemplo n.º 4
0
        public void TestEquals()
        {
            GroupMember member1 = new GroupMember(validGuid, "Name", GroupMemberTypes.OnPremAd);
            GroupMember member2 = new GroupMember(validGuid, "Different name", GroupMemberTypes.OnPremAd);

            Assert.True(member1.Equals(member2));
        }