Exemplo n.º 1
0
        public static bool IsPermitted(Member member, string command)
        {
            IEnumerable<List<string>> roleCommands =
                from memberRole in member.Roles
                join role in Role.RoleList
                    on memberRole equals role.Name
                select role.Commands;

            IEnumerable<string> commands =
                from roleCommand in roleCommands
                from sCommand in roleCommand
                where sCommand == command || sCommand == "*"
                select sCommand;

            return commands.Any();
        }
Exemplo n.º 2
0
        public static void ReloadMembers()
        {
            if (MemberList.Count > 0)
            {
                MemberList.RemoveAll(v => true);
            }

            JObject config = JObject.Parse(File.ReadAllText("permissions.json"));

            foreach (JProperty userId in ((JObject)config.SelectToken("Members")).Properties())
            {
                Member newMember = new Member(userId.Name);
                foreach (JToken role in config.SelectToken($"Members.{userId.Name}"))
                {
                    newMember.Roles.Add(role.ToString());
                }
                MemberList.Add(newMember);
            }
        }