2013-03-27 21:07:25 +00:00
|
|
|
/**
|
|
|
|
|
* Applies backer tokens & items (this file will be updated periodically
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// mongo habitrpg ./node_modules/underscore/underscore.js migrations/20130327_apply_tokens.js
|
|
|
|
|
|
2017-03-01 16:10:48 +00:00
|
|
|
// IMPORTANT NOTE: this migration was written when we were using version 3 of lodash.
|
|
|
|
|
// We've now upgraded to lodash v4 but the code used in this migration has not been
|
|
|
|
|
// adapted to work with it. Before this migration is used again any lodash method should
|
|
|
|
|
// be checked for compatibility against the v4 changelog and changed if necessary.
|
|
|
|
|
// https://github.com/lodash/lodash/wiki/Changelog#v400
|
|
|
|
|
|
2013-03-27 21:07:25 +00:00
|
|
|
var mapping = [
|
2013-05-07 15:06:45 +00:00
|
|
|
{
|
|
|
|
|
tier: 1,
|
2013-03-27 21:07:25 +00:00
|
|
|
tokens: 0,
|
|
|
|
|
users: []
|
|
|
|
|
},
|
2013-05-07 15:06:45 +00:00
|
|
|
{
|
|
|
|
|
tier: 5,
|
2013-03-27 21:07:25 +00:00
|
|
|
tokens: 20,
|
2013-05-07 15:06:45 +00:00
|
|
|
users: []
|
2013-03-27 21:07:25 +00:00
|
|
|
},
|
2013-05-07 15:06:45 +00:00
|
|
|
{
|
|
|
|
|
tier: 10,
|
2013-03-27 21:07:25 +00:00
|
|
|
tokens: 50,
|
|
|
|
|
users: []
|
|
|
|
|
},
|
2013-05-07 15:06:45 +00:00
|
|
|
{
|
|
|
|
|
tier: 15,
|
2013-03-27 21:07:25 +00:00
|
|
|
tokens: 100,
|
|
|
|
|
users: []
|
|
|
|
|
},
|
2013-05-07 15:06:45 +00:00
|
|
|
{
|
|
|
|
|
tier: 30,
|
2013-03-27 21:07:25 +00:00
|
|
|
tokens: 150,
|
|
|
|
|
users: []
|
|
|
|
|
},
|
2013-05-07 15:06:45 +00:00
|
|
|
{
|
|
|
|
|
tier: 45,
|
2013-03-27 21:07:25 +00:00
|
|
|
tokens: 170,
|
|
|
|
|
users: []
|
|
|
|
|
},
|
2013-05-07 15:06:45 +00:00
|
|
|
{
|
|
|
|
|
tier: 60,
|
2013-03-27 21:07:25 +00:00
|
|
|
tokens: 200,
|
|
|
|
|
users: []
|
|
|
|
|
},
|
2013-05-07 15:06:45 +00:00
|
|
|
{
|
|
|
|
|
tier: 70,
|
2013-03-27 21:07:25 +00:00
|
|
|
tokens: 240,
|
|
|
|
|
users: []
|
|
|
|
|
},
|
2013-05-07 15:06:45 +00:00
|
|
|
{
|
|
|
|
|
tier: 80,
|
2013-03-27 21:07:25 +00:00
|
|
|
tokens: 240,
|
|
|
|
|
users: []
|
|
|
|
|
},
|
2013-05-07 15:06:45 +00:00
|
|
|
{
|
|
|
|
|
tier: 90,
|
2013-03-27 21:07:25 +00:00
|
|
|
tokens: 280,
|
|
|
|
|
users: []
|
|
|
|
|
},
|
2013-05-07 15:06:45 +00:00
|
|
|
{
|
|
|
|
|
tier: 300,
|
2013-03-27 21:07:25 +00:00
|
|
|
tokens: 500,
|
|
|
|
|
users: []
|
|
|
|
|
},
|
2013-05-07 15:06:45 +00:00
|
|
|
{
|
|
|
|
|
tier: 800,
|
2013-03-27 21:07:25 +00:00
|
|
|
tokens: 500,
|
|
|
|
|
users: []
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2013-03-28 07:25:45 +00:00
|
|
|
db.users.find().forEach(function(user){
|
2013-05-07 15:06:45 +00:00
|
|
|
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);
|
|
|
|
|
}
|
2013-03-28 07:25:45 +00:00
|
|
|
|
|
|
|
|
_.each(mapping, function(tier){
|
2013-05-07 15:06:45 +00:00
|
|
|
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;
|
2013-03-28 07:25:45 +00:00
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
db.users.update(
|
|
|
|
|
{_id:user._id},
|
|
|
|
|
{
|
2013-05-07 15:06:45 +00:00
|
|
|
$set: { backer: backer, 'flags.ads': 'hide' },
|
|
|
|
|
$inc: { balance: (tokenInc/4) }
|
2013-03-28 07:25:45 +00:00
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} catch(e) {
|
|
|
|
|
print(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2013-05-07 15:06:45 +00:00
|
|
|
})
|