public DiscordRole EditRole(DiscordRole role)
        {
            if (Unavailable)
            {
                throw new Exception("Server is currently unavailable!");
            }

            string url     = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.ID}" + Endpoints.Roles + $"/{role.ID}";
            string request = JsonConvert.SerializeObject(
                new
            {
                color       = decimal.Parse(role.Color.ToDecimal().ToString()),
                hoist       = role.Hoist,
                name        = role.Name,
                permissions = role.Permissions.GetRawPermissions()
            }
                );

            var result = JObject.Parse(WebWrapper.Patch(url, DiscordClient.token, request));

            if (result != null)
            {
                DiscordRole d = new DiscordRole
                {
                    Color       = new Color(result["color"].ToObject <int>().ToString("x")),
                    Hoist       = result["hoist"].ToObject <bool>(),
                    ID          = result["id"].ToString(),
                    Managed     = result["managed"].ToObject <bool>(),
                    Name        = result["name"].ToString(),
                    Permissions = new DiscordPermission(result["permissions"].ToObject <uint>()),
                    Position    = result["position"].ToObject <int>()
                };

                this.Roles.Remove(d);
                this.Roles.Add(d);
                return(d);
            }

            return(null);
        }
Exemple #2
0
        public DiscordRole CreateRole()
        {
            string url    = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.id}" + Endpoints.Roles;
            var    result = JObject.Parse(WebWrapper.Post(url, DiscordClient.token, ""));

            if (result != null)
            {
                DiscordRole d = new DiscordRole
                {
                    color       = new Color(result["color"].ToObject <int>().ToString("x")),
                    hoist       = result["hoist"].ToObject <bool>(),
                    id          = result["id"].ToString(),
                    managed     = result["managed"].ToObject <bool>(),
                    name        = result["name"].ToString(),
                    permissions = new DiscordPermission(result["permissions"].ToObject <uint>()),
                    position    = result["position"].ToObject <int>()
                };

                this.roles.Add(d);
                return(d);
            }
            return(null);
        }
        public void DeleteRole(DiscordRole role)
        {
            if (Unavailable)
                throw new Exception("Server is currently unavailable!");

            string url = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.ID}" + Endpoints.Roles + $"/{role.ID}";
            WebWrapper.Delete(url, DiscordClient.token);
        }
        public DiscordRole EditRole(DiscordRole role)
        {
            if (Unavailable)
                throw new Exception("Server is currently unavailable!");

            string url = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.ID}" + Endpoints.Roles + $"/{role.ID}";
            string request = JsonConvert.SerializeObject(
                new
                {
                    color = decimal.Parse(role.Color.ToDecimal().ToString()),
                    hoist = role.Hoist,
                    name = role.Name,
                    permissions = role.Permissions.GetRawPermissions()
                }
            );

            var result = JObject.Parse(WebWrapper.Patch(url, DiscordClient.token, request));
            if (result != null)
            {
                DiscordRole d = new DiscordRole
                {
                    Color = new Color(result["color"].ToObject<int>().ToString("x")),
                    Hoist = result["hoist"].ToObject<bool>(),
                    ID = result["id"].ToString(),
                    Managed = result["managed"].ToObject<bool>(),
                    Name = result["name"].ToString(),
                    Permissions = new DiscordPermission(result["permissions"].ToObject<uint>()),
                    Position = result["position"].ToObject<int>()
                };

                this.Roles.Remove(d);
                this.Roles.Add(d);
                return d;
            }

            return null;
        }
        public DiscordRole CreateRole()
        {
            if (Unavailable)
                throw new Exception("Server is currently unavailable!");

            string url = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.ID}" + Endpoints.Roles;
            var result = JObject.Parse(WebWrapper.Post(url, DiscordClient.token, ""));

            if (result != null)
            {
                DiscordRole d = new DiscordRole
                {
                    Color = new Color(result["color"].ToObject<int>().ToString("x")),
                    Hoist = result["hoist"].ToObject<bool>(),
                    ID = result["id"].ToString(),
                    Managed = result["managed"].ToObject<bool>(),
                    Name = result["name"].ToString(),
                    Permissions = new DiscordPermission(result["permissions"].ToObject<uint>()),
                    Position = result["position"].ToObject<int>()
                };

                this.Roles.Add(d);
                return d;
            }
            return null;
        }
        public void AssignRoleToMember(DiscordRole role, DiscordMember member)
        {
            if (Unavailable)
                throw new Exception("Server is currently unavailable!");

            string url = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.ID}" + Endpoints.Members + $"/{member.ID}";
            string message = JsonConvert.SerializeObject(new { roles = new string[] { role.ID } });
            Console.WriteLine(WebWrapper.Patch(url, DiscordClient.token, message));
        }
        public DiscordRole CreateRole()
        {
            string url = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.id}" + Endpoints.Roles;
            var result = JObject.Parse(WebWrapper.Post(url, DiscordClient.token, ""));

            if (result != null)
            {
                DiscordRole d = new DiscordRole
                {
                    color = new Color(result["color"].ToObject<int>().ToString("x")),
                    hoist = result["hoist"].ToObject<bool>(),
                    id = result["id"].ToString(),
                    managed = result["managed"].ToObject<bool>(),
                    name = result["name"].ToString(),
                    permissions = new DiscordPermission(result["permissions"].ToObject<uint>()),
                    position = result["position"].ToObject<int>()
                };

                this.roles.Add(d);
                return d;
            }
            return null;
        }
 public void AssignRoleToMember(DiscordRole role, DiscordMember member)
 {
     string url = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.id}" + Endpoints.Members + $"/{member.ID}";
     string message = JsonConvert.SerializeObject(new { roles = new string[] { role.id } });
     Console.WriteLine(WebWrapper.Patch(url, DiscordClient.token, message));
 }
 public void DeleteRole(DiscordRole role)
 {
     string url = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.id}" + Endpoints.Roles + $"/{role.id}";
     WebWrapper.Delete(url, DiscordClient.token);
 }
Exemple #10
0
        public DiscordRole EditRole(DiscordRole role)
        {
            string url = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.id}" + Endpoints.Roles + $"/{role.id}";
            string request = JsonConvert.SerializeObject(
                new
                {
                    color = decimal.Parse(role.color.ToDecimal().ToString()),
                    hoist = role.hoist,
                    name = role.name,
                    permissions = role.permissions.GetRawPermissions()
                }
            );

            var result = JObject.Parse(WebWrapper.Patch(url, DiscordClient.token, request));
            if (result != null)
            {
                DiscordRole d = new DiscordRole
                {
                    color = new Color(result["color"].ToObject<int>().ToString("x")),
                    hoist = result["hoist"].ToObject<bool>(),
                    id = result["id"].ToString(),
                    managed = result["managed"].ToObject<bool>(),
                    name = result["name"].ToString(),
                    permissions = new DiscordPermission(result["permissions"].ToObject<uint>()),
                    position = result["position"].ToObject<int>()
                };

                this.roles.Remove(d);
                this.roles.Add(d);
                return d;
            }

            return null;
        }
Exemple #11
0
        public void DeleteRole(DiscordRole role)
        {
            string url = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.id}" + Endpoints.Roles + $"/{role.id}";

            WebWrapper.Delete(url, DiscordClient.token);
        }