Esempio n. 1
0
        /// <summary>
        /// Revokes the given target permission from the given Discord user. If the user does not have the permission, no
        /// changes are made.
        /// </summary>
        /// <param name="db">The database.</param>
        /// <param name="discordServer">The Discord server the permission was revoked on.</param>
        /// <param name="discordUser">The Discord user.</param>
        /// <param name="permission">The permission to alter.</param>
        /// <param name="revokedTarget">The revoked permission.</param>
        /// <returns>A task wrapping the revoking of the permission.</returns>
        public async Task RevokeLocalPermissionTargetAsync
        (
            [NotNull] GlobalInfoContext db,
            [NotNull] IGuild discordServer,
            [NotNull] IUser discordUser,
            Permission permission,
            PermissionTarget revokedTarget
        )
        {
            var existingPermission = await GetLocalUserPermissions(db, discordUser, discordServer).FirstOrDefaultAsync
                                     (
                p =>
                p.Permission == permission &&
                p.ServerDiscordID == (long)discordServer.Id
                                     );

            if (existingPermission != null)
            {
                existingPermission.Target &= ~revokedTarget;
                await db.SaveChangesAsync();
            }
        }
Esempio n. 2
0
            public async Task RevokeTargetAsync([NotNull] IUser discordUser, Permission permission, PermissionTarget revokedTarget)
            {
                await this.Permissions.RevokeLocalPermissionTargetAsync(this.Database, this.Context.Guild, discordUser, permission, revokedTarget);

                await this.Feedback.SendConfirmationAsync
                (
                    this.Context,
                    $"{permission.ToString().Humanize().Transform(To.TitleCase)} ({revokedTarget.ToString().Humanize().Transform(To.TitleCase)}) revoked from {discordUser.Mention}."
                );
            }
Esempio n. 3
0
            public async Task Default([NotNull] IUser discordUser, Permission grantedPermission, PermissionTarget grantedTarget = PermissionTarget.Self)
            {
                var newPermission = new LocalPermission
                {
                    Permission      = grantedPermission,
                    Target          = grantedTarget,
                    ServerDiscordID = (long)this.Context.Guild.Id
                };

                await this.Permissions.GrantLocalPermissionAsync(this.Database, this.Context.Guild, discordUser, newPermission);

                await this.Feedback.SendConfirmationAsync(this.Context, $"{grantedPermission.ToString().Humanize().Transform(To.TitleCase)} granted to {discordUser.Mention}.");
            }