public async Task Tree(CommandContext ctx, Group group) { //Get teh user group if (group == null) { throw new ArgumentNullException($"The group does not exist."); } //Get the tree var tree = await TreeBranch.CreateTreeAsync(group); var sb = new StringBuilder(); tree.BuildTreeString(sb); var export = sb.ToString(); if (export.Length < 1980) { await ctx.ReplyAsync("```\n" + export + "\n```"); } else { string tmppath = "tree_" + ctx.Guild.Id + "_" + group.Name + ".txt"; try { await System.IO.File.WriteAllTextAsync(tmppath, export); await ctx.RespondWithFileAsync(tmppath, "Exported Groups:"); await ctx.ReplyReactionAsync(true); } catch (Exception) { await ctx.ReplyReactionAsync(false); } finally { if (System.IO.File.Exists(tmppath)) { System.IO.File.Delete(tmppath); } } } }
public async void EC02_RoleSubtraction() { var engine = new Engine(); await engine.ImportAsync(@" ::everyone|0 -group.contributor ::contributor +group.role.contributor ::role.builder +group.contributor ::user.vex +group.everyone +group.role.builder ::user.lachee +group.everyone ::user.nobody ::role.contributor "); var vex = await engine.GetGroupAsync("user.vex"); Assert.NotNull(vex); var lachee = await engine.GetGroupAsync("user.lachee"); Assert.NotNull(lachee); var nobody = await engine.GetGroupAsync("user.nobody"); Assert.NotNull(nobody); var tree = await TreeBranch.CreateTreeAsync(vex); Assert.Equal(StateType.Allow, await vex.EvaluatePermissionAsync("group.role.contributor")); Assert.Equal(StateType.Deny, await lachee.EvaluatePermissionAsync("group.role.contributor")); Assert.Equal(StateType.Unset, await nobody.EvaluatePermissionAsync("group.role.contributor")); }