예제 #1
0
        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);
        }
예제 #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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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;
        }
예제 #5
0
        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;
        }
예제 #6
0
        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));
        }
예제 #7
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;
        }
예제 #8
0
 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));
 }
예제 #9
0
 public void DeleteRole(DiscordRole role)
 {
     string url = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.id}" + Endpoints.Roles + $"/{role.id}";
     WebWrapper.Delete(url, DiscordClient.token);
 }
예제 #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;
        }
예제 #11
0
        public void DeleteRole(DiscordRole role)
        {
            string url = Endpoints.BaseAPI + Endpoints.Guilds + $"/{this.id}" + Endpoints.Roles + $"/{role.id}";

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