Added character slot limitations to tiers; added no-patreon tier for self hosting
This commit is contained in:
@@ -1,58 +1,78 @@
|
||||
import { findLast } from 'lodash';
|
||||
import getEntitledCents from '/imports/api/users/patreon/getEntitledCents.js';
|
||||
import Invites from '/imports/api/users/Invites.js';
|
||||
const patreonDisabled = !!process.env.DISABLE_PATREON;
|
||||
|
||||
const TIERS = [
|
||||
const TIERS = Object.freeze([
|
||||
{
|
||||
name: 'Commoner',
|
||||
minimumEntitledCents: 0,
|
||||
invites: 0,
|
||||
characterSlots: 5,
|
||||
paidBenefits: false,
|
||||
}, {
|
||||
name: 'Dreamer',
|
||||
minimumEntitledCents: 100,
|
||||
invites: 0,
|
||||
characterSlots: 5,
|
||||
paidBenefits: false,
|
||||
}, {
|
||||
name: 'Wanderer',
|
||||
minimumEntitledCents: 300,
|
||||
invites: 0,
|
||||
characterSlots: 5,
|
||||
paidBenefits: false,
|
||||
}, {
|
||||
//cost per user $5
|
||||
name: 'Adventurer',
|
||||
minimumEntitledCents: 500,
|
||||
invites: 0,
|
||||
characterSlots: 20,
|
||||
paidBenefits: true,
|
||||
}, {
|
||||
//cost per user $3.33
|
||||
name: 'Hero',
|
||||
minimumEntitledCents: 1000,
|
||||
invites: 2,
|
||||
characterSlots: 50,
|
||||
paidBenefits: true,
|
||||
}, {
|
||||
//cost per user $3.333
|
||||
name: 'Legend',
|
||||
minimumEntitledCents: 2000,
|
||||
invites: 5,
|
||||
characterSlots: 120,
|
||||
paidBenefits: true,
|
||||
}, {
|
||||
//cost per user $3.125
|
||||
name: 'Paragon',
|
||||
minimumEntitledCents: 5000,
|
||||
invites: 15,
|
||||
characterSlots: -1, // Unlimited characters
|
||||
paidBenefits: true,
|
||||
},
|
||||
];
|
||||
]);
|
||||
|
||||
const GUEST_TIER = {
|
||||
// Companion tier should be equivalent to the Adventurer tier
|
||||
const GUEST_TIER = Object.freeze({
|
||||
name: 'Companion',
|
||||
guest: true,
|
||||
invites: 0,
|
||||
characterSlots: 20,
|
||||
paidBenefits: true,
|
||||
}
|
||||
});
|
||||
|
||||
// When patreon features are disabled, give all the users the same tier
|
||||
// with no limitations
|
||||
const PATREON_DISABLED_TIER = Object.freeze({
|
||||
name: 'Outlander',
|
||||
invites: 0,
|
||||
characterSlots: -1, // Can have infinitely many characters
|
||||
paidBenefits: true,
|
||||
});
|
||||
|
||||
export function getTierByEntitledCents(entitledCents = 0){
|
||||
if (patreonDisabled) return PATREON_DISABLED_TIER;
|
||||
return findLast(TIERS, tier => entitledCents >= tier.minimumEntitledCents);
|
||||
}
|
||||
|
||||
@@ -66,6 +86,7 @@ export function getUserTier(user){
|
||||
});
|
||||
if (!user) throw 'User not found';
|
||||
}
|
||||
if (patreonDisabled) return PATREON_DISABLED_TIER;
|
||||
const entitledCents = getEntitledCents(user);
|
||||
const tier = getTierByEntitledCents(entitledCents);
|
||||
if (tier.paidBenefits) return tier;
|
||||
|
||||
Reference in New Issue
Block a user