mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-05-23 22:27:06 +00:00
apply backer tier to their backer property, add tokens if not already there, disable ads, etc
This commit is contained in:
parent
53d76ed4fb
commit
9c061fadc1
1 changed files with 44 additions and 49 deletions
|
|
@ -5,76 +5,94 @@
|
|||
// mongo habitrpg ./node_modules/underscore/underscore.js migrations/20130327_apply_tokens.js
|
||||
|
||||
var mapping = [
|
||||
{ // $1
|
||||
{
|
||||
tier: 1,
|
||||
tokens: 0,
|
||||
users: []
|
||||
},
|
||||
{ // $5
|
||||
{
|
||||
tier: 5,
|
||||
tokens: 20,
|
||||
users: ['9']
|
||||
users: []
|
||||
},
|
||||
{ // $10
|
||||
{
|
||||
tier: 10,
|
||||
tokens: 50,
|
||||
users: []
|
||||
},
|
||||
{ // $15
|
||||
{
|
||||
tier: 15,
|
||||
tokens: 100,
|
||||
users: []
|
||||
},
|
||||
{ // $30
|
||||
{
|
||||
tier: 30,
|
||||
tokens: 150,
|
||||
users: []
|
||||
},
|
||||
{ // $45
|
||||
{
|
||||
tier: 45,
|
||||
tokens: 170,
|
||||
users: []
|
||||
},
|
||||
{ // $60
|
||||
{
|
||||
tier: 60,
|
||||
tokens: 200,
|
||||
users: []
|
||||
},
|
||||
{ // $70
|
||||
{
|
||||
tier: 70,
|
||||
tokens: 240,
|
||||
users: []
|
||||
},
|
||||
{ // $80
|
||||
{
|
||||
tier: 80,
|
||||
tokens: 240,
|
||||
users: []
|
||||
},
|
||||
{ // $90
|
||||
{
|
||||
tier: 90,
|
||||
tokens: 280,
|
||||
users: []
|
||||
},
|
||||
{ // $300
|
||||
{
|
||||
tier: 300,
|
||||
tokens: 500,
|
||||
users: []
|
||||
},
|
||||
{ // $800
|
||||
{
|
||||
tier: 800,
|
||||
tokens: 500,
|
||||
users: []
|
||||
}
|
||||
];
|
||||
|
||||
db.users.find().forEach(function(user){
|
||||
if (!user._id) return;
|
||||
|
||||
var possibleUserIds = [user._id];
|
||||
if (!!user.local) {
|
||||
if (!!user.local.username) possibleUserIds.push(user.local.username);
|
||||
if (!!user.local.email) possibleUserIds.push(user.local.email);
|
||||
}
|
||||
|
||||
_.each(mapping, function(tier){
|
||||
if(
|
||||
(!user.backer || !user.backer.tokensApplied) &&
|
||||
var userInTier = !_.isEmpty(_.intersection(tier.users, possibleUserIds));
|
||||
if (userInTier) {
|
||||
var tokenInc = 0,
|
||||
backer = user.backer || {};
|
||||
if (!backer.tokensApplied) {
|
||||
tokenInc = tier.tokens;
|
||||
backer.tokensApplied = true;
|
||||
}
|
||||
backer.tier = tier.tier;
|
||||
|
||||
(
|
||||
_.contains(tier.users, user._id) ||
|
||||
!!user.local && (
|
||||
_.contains(tier.users, user.local.username) ||
|
||||
_.contains(tier.users, user.local.email)
|
||||
)
|
||||
)
|
||||
) {
|
||||
try {
|
||||
db.users.update(
|
||||
{_id:user._id},
|
||||
{
|
||||
$set: { 'backer.tokensApplied': true, 'flags.ads': 'hide' },
|
||||
$inc: { balance: (tier.tokens/4) }
|
||||
$set: { backer: backer, 'flags.ads': 'hide' },
|
||||
$inc: { balance: (tokenInc/4) }
|
||||
}
|
||||
);
|
||||
} catch(e) {
|
||||
|
|
@ -83,27 +101,4 @@ db.users.find().forEach(function(user){
|
|||
}
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
// This doesn't work, but shows the idea we're after better than the above
|
||||
/*
|
||||
_.each(mapping, function(tier){
|
||||
db.users.update(
|
||||
{
|
||||
$or: [
|
||||
{ _id: { $in: tier.users } },
|
||||
{ 'auth.local.username': { $in: tier.users } },
|
||||
{ 'auth.local.email': { $in: tier.users } }
|
||||
],
|
||||
'backer.tokensApplied': { $exists: false }
|
||||
},
|
||||
|
||||
{
|
||||
$set: { 'backer.tokensApplied': true, 'flags.ads': 'hide' },
|
||||
$inc: { balance: (tier.tokens/4) }
|
||||
},
|
||||
|
||||
{ multi: true}
|
||||
)
|
||||
})
|
||||
*/
|
||||
})
|
||||
Loading…
Reference in a new issue