public async Task <IClaimCollection?> GetClaimCollectionAsync(GuildSubject subject, CancellationToken cancellationToken) { if (!AllowedSubjectTypes.Contains(subject.Type)) { throw new ArgumentException("Invalid subject type for claims", nameof(subject)); } using var dbContext = _dbFactory(); var dbPermissions = dbContext.Permissions.AsNoTracking().Where(p => (p.ServerId == subject.GuildId) && (p.SubjectId == subject.Id) && (p.SubjectType == subject.Type)); var claims = await dbPermissions.Select(p => new Claim(p.Identifier, p.Allow)).ToListAsync(cancellationToken); return(new ClaimCollection(subject, claims)); }
public async Task IsAllowed(SocketGuildUser user, string permission) { var subject = GuildSubject.FromGuildUser(user); var claims = await _claimProvider.GetClaimCollectionAsync(user); var allowed = ClaimChecker.IsAllowed(claims !, permission, true); if (allowed) { await ReplyAsync($"{subject.MentionString} is allowed permission `{permission}`", allowedMentions : AllowedMentions.None); } else { await ReplyAsync($"{subject.MentionString} is not allowed permission `{permission}`", allowedMentions : AllowedMentions.None); } }
public async Task DeletePermissionClaimAsync(GuildSubject subject, string claimIdentifier, CancellationToken cancellationToken) { if (!AllowedSubjectTypes.Contains(subject.Type)) { throw new ArgumentException("Invalid subject type for claims", nameof(subject)); } using var dbContext = _dbFactory(); var dbPermissions = dbContext.Permissions.AsNoTracking().Where(p => (p.ServerId == subject.GuildId) && (p.SubjectId == subject.Id) && (p.SubjectType == subject.Type)); var dbPermission = await dbPermissions.FirstOrDefaultAsync(p => p.Identifier == claimIdentifier, cancellationToken); if (dbPermission is null) { return; } dbContext.Permissions.Remove(dbPermission); await dbContext.SaveChangesAsync(cancellationToken); }
public async Task ListAsync(SocketGuildUser user) { var claims = await _claimManager.GetClaimCollectionAsync(GuildSubject.FromGuildUser(user), default); await ReplyPermissions(claims !); }
public async Task KickAsync(SocketGuildUser user, string?reason = null) { await user.KickAsync(reason); await ReplyAsync($"{GuildSubject.FromGuildUser(user).MentionString} was kicked"); }
public async Task YeetAsync(SocketGuildUser user, string?reason = null) { await Context.Guild.AddBanAsync(user, 0, reason); await ReplyAsync($"{GuildSubject.FromGuildUser(user).MentionString} was yeeted"); }
public async Task ListAsync(SocketRole role) { var claims = await _claimManager.GetClaimCollectionAsync(GuildSubject.FromRole(role), default); await ReplyPermissions(claims !); }