Exemple #1
0
        /// <summary>
        /// Save role settings to DB
        /// </summary>
        /// <param name="guild">Discord guild containing role</param>
        /// <returns>True on success modify/insert</returns>
        public bool Save(DW.SocketGuild guild = null)
        {
            if (!string.IsNullOrWhiteSpace(this.Path))
            {
                this.Path = "/" + string.Join(
                    '/',
                    this.Path.Trim().Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)
                    .Select(folder => Regex.Replace(folder, "^[0-9A-Za-z ]+$", string.Empty).Trim())
                    .Where(folder => !string.IsNullOrWhiteSpace(folder)));

                if (string.IsNullOrWhiteSpace(this.Path) || !this.Path.StartsWith('/'))
                {
                    this.Path = "/";
                }
            }

            Role.UpdateDatabase(ulong.Parse(this.Identifier), this.Path, ulong.Parse(this.GuildIdentifier));

            if (guild != null)
            {
                if (this.Identifier == "0" || string.IsNullOrWhiteSpace(this.Identifier))
                {
                    // Create role
                    DNET.Color?color = null;

                    if (this.Color != null && this.Color.Count == 3)
                    {
                        color = new DNET.Color(this.Color[0], this.Color[1], this.Color[2]);
                    }

                    Task.Run(() => guild.CreateRoleAsync(this.Name, this.Permissions, color));
                    return(true);
                }
                else
                {
                    // Modify role
                    DW.SocketRole role = guild.GetRole(ulong.Parse(this.Identifier));

                    if (role != null)
                    {
                        Task.Run(() => role.ModifyAsync(changed =>
                        {
                            changed.Name        = this.Name;
                            changed.Permissions = this.Permissions;

                            if (this.Color != null && this.Color.Count == 3)
                            {
                                changed.Color = new DNET.Optional <DNET.Color>(new DNET.Color(this.Color[0], this.Color[1], this.Color[2]));
                            }
                        }));

                        return(true);
                    }
                }
            }

            return(false);
        }
Exemple #2
0
 /// <inheritdoc />
 public Task ModifyAsync(Action <RoleProperties> func, RequestOptions options = null)
 => SocketRole.ModifyAsync(func, options);