/// <summary> /// Builds and adds role to server. IF the operation fails, an exception will be thrown /// with the error message. /// </summary> public Discord.Rest.RestRole Build() { bool hexColorUsed = false; bool positionedByIndex = false; if (altColor != null) { hexColorUsed = true; } if (pos != -1) { positionedByIndex = true; } else if (upperRole != "" || lowerRole != "") { this.pos = GetIndexForRelativePos(); positionedByIndex = true; } try { GeneratePermRawValue(); } catch (Exception e) { throw e; } GuildPermissions perms = new GuildPermissions(permVal); Discord.Rest.RestRole role = null; if (hexColorUsed) { try { Color localColor = new Color(altColor[0], altColor[1], altColor[2]); role = guild.CreateRoleAsync( name, perms, localColor, isHoisted ).Result; }catch (Exception e) { throw e; } } else { try { role = guild.CreateRoleAsync( name, perms, color, isHoisted ).Result; }catch (Exception e) { throw e; } } if (positionedByIndex) { //(roles count - pos) since this class rests on supposition //that top most role is 0, and not bottom as discord API does ReorderRoleProperties x = new ReorderRoleProperties(role.Id, guild.Roles.Count() - pos); IEnumerable <ReorderRoleProperties> roleNewPos = (IEnumerable <ReorderRoleProperties>) (new List <ReorderRoleProperties> { x }); guild.ReorderRolesAsync(roleNewPos); } return(role); }
public virtual Task ReorderRolesAsync(IEnumerable <ReorderRoleProperties> args, RequestOptions?options = null) { return(_socketGuild.ReorderRolesAsync(args, options)); }
public Task ReorderRolesAsync(IEnumerable <ReorderRoleProperties> args, RequestOptions options = null) { return(Guild.ReorderRolesAsync(args, options)); }
public bool Enable(SocketGuild guild, GuildLanguage lang) { if (guild == null || !guild.CurrentUser.GuildPermissions.ManageRoles || !guild.CurrentUser.GuildPermissions.ManageNicknames) { return(false); } var reorder2 = new List <ReorderRoleProperties>(); { var discordServer = _uow.Db <DiscordServer>().GetById(guild.Id.ToString()); GuildConfig gConfig = null; if (discordServer == null) { gConfig = AddOrGetGuild(guild.Id.ToString(), lang).Value; } else { gConfig = AddOrGetGuildConfig(guild.Id.ToString()); } var list = guild.GetMissingMapRolesAsync(gConfig.Owner.DefaultLanguage, out reorder2).Result; if (list == null || list.Count < 4) { return(false); } try { foreach (var crole in list) { crole.Value.SetMapRolePermissionsAsync(); } } catch (AggregateException e) { try { guild.Owner.GetOrCreateDMChannelAsync(Core.Utils.RequestOption) .ContinueWith((p1) => { p1.Result.SendMessageAsync(e.Message) .ContinueWith((p2) => { p1.Result.CloseAsync(Core.Utils.RequestOption).Wait(); }); }); } catch (Exception) { } } catch (Exception) { } try { if (reorder2.Count >= 4) { guild.ReorderRolesAsync(reorder2, Core.Utils.RequestOption).Wait(); } } catch (Exception) { }; } return(true); }