/// <summary> /// Sets the protection type that the user has for transformations on the given server. /// </summary> /// <param name="discordUser">The user to set the protection for.</param> /// <param name="discordServer">The server to set the protection on.</param> /// <param name="protectionType">The protection type to set.</param> /// <returns>An entity modification result which may or may not have succeeded.</returns> public async Task <ModifyEntityResult> SetServerProtectionTypeAsync ( IUser discordUser, IGuild discordServer, ProtectionType protectionType ) { var getServerProtectionResult = await GetOrCreateServerUserProtectionAsync(discordUser, discordServer); if (!getServerProtectionResult.IsSuccess) { return(ModifyEntityResult.FromError(getServerProtectionResult)); } var protection = getServerProtectionResult.Entity; if (protection.Type == protectionType) { return(ModifyEntityResult.FromError($"{protectionType.Humanize()} is already your current setting.")); } protection.Type = protectionType; await _database.SaveChangesAsync(); return(ModifyEntityResult.FromSuccess()); }
public async Task <RuntimeResult> SetProtectionTypeAsync(ProtectionType protectionType) { var setProtectionTypeResult = await _transformation.SetServerProtectionTypeAsync(this.Context.User, this.Context.Guild, protectionType); if (!setProtectionTypeResult.IsSuccess) { return(setProtectionTypeResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess ( $"Protection type set to \"{protectionType.Humanize()}\"" )); }
public async Task <Result <FeedbackMessage> > SetDefaultProtectionTypeAsync(ProtectionType protectionType) { var setProtectionTypeResult = await _transformation.SetDefaultProtectionTypeAsync ( _context.User.ID, protectionType ); if (!setProtectionTypeResult.IsSuccess) { return(Result <FeedbackMessage> .FromError(setProtectionTypeResult)); } return(new FeedbackMessage ( $"Default protection type set to \"{protectionType.Humanize()}\"", _feedback.Theme.Secondary )); }
public async Task SetProtectionTypeAsync(ProtectionType protectionType) { var setProtectionTypeResult = await _transformation.SetServerProtectionTypeAsync(this.Context.User, this.Context.Guild, protectionType); if (!setProtectionTypeResult.IsSuccess) { await _feedback.SendErrorAsync(this.Context, setProtectionTypeResult.ErrorReason); return; } await _feedback.SendConfirmationAsync(this.Context, $"Protection type set to \"{protectionType.Humanize()}\""); }
public async Task SetDefaultProtectionTypeAsync(ProtectionType protectionType) { var setProtectionTypeResult = await this.Transformation.SetDefaultProtectionTypeAsync(this.Database, this.Context.User, protectionType); if (!setProtectionTypeResult.IsSuccess) { await this.Feedback.SendErrorAsync(this.Context, setProtectionTypeResult.ErrorReason); return; } await this.Feedback.SendConfirmationAsync(this.Context, $"Default protection type set to \"{protectionType.Humanize()}\""); }