Skip to content

Commit

Permalink
feat: Add debug scripts to easilly get all pets/mounts/gear
Browse files Browse the repository at this point in the history
  • Loading branch information
crookedneighbor committed Mar 15, 2016
1 parent ed013ee commit d62807f
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 0 deletions.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,21 @@ For an introduction to the technologies used and how the software is organized,
To set up a local install of Habitica for development and testing, see [Setting up Habitica Locally](http://habitica.wikia.com/wiki/Setting_up_Habitica_Locally), which contains instructions for Windows, *nix / Mac OS, and Vagrant.

Then read [Guidance for Blacksmiths](http://habitica.wikia.com/wiki/Guidance_for_Blacksmiths) for additional instructions and useful tips.

## Debug Scripts

In the `./debug-scripts/` folder, there are a few files. Here's a sample:

```bash
grant-all-equipment.js
grant-all-mounts.js
grant-all-pets.js
```

You can run them by doing:

```bash
node debug-scripts/name-of-script.js
```

If there are more arguments required to make the script work, it will print out the usage and an explanation of what the script does.
19 changes: 19 additions & 0 deletions debug-scripts/_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MongoClient as mongo } from 'mongodb';
import config from '../config';

module.exports.updateUser = (_id, path, value) => {
mongo.connect(config.NODE_DB_URI, (err, db) => {
if (err) throw err;

let collection = db.collection('users');
collection.updateOne(
{ _id },
{ $set: { [`${path}`]: value } },
(updateErr, result) => {
if (updateErr) throw updateErr;
console.log('done updating', _id);
db.close();
}
);
});
}
24 changes: 24 additions & 0 deletions debug-scripts/grant-all-equipment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

require('babel-register');

let _ = require('lodash');
let updateUser = require('./_helper').updateUser;

let userId = process.argv[2];

if (!userId) {
console.error('USAGE: node debug-scripts/grant-all-equipment.js <user_id>');
console.error('EFFECT: Adds all gear to specified user');
return;
}

let gearFlat = require('../common').content.gear.flat;

let userGear = {};

_.each(gearFlat, (piece, key) => {
userGear[key] = true;
});

updateUser(userId, 'items.gear.owned', userGear);
28 changes: 28 additions & 0 deletions debug-scripts/grant-all-mounts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

require('babel-register');

let _ = require('lodash');
let updateUser = require('./_helper').updateUser;
let userId = process.argv[2];

if (!userId) {
console.error('USAGE: node debug-scripts/grant-all-mounts.js <user_id>');
console.error('EFFECT: Adds all mounts to specified user');
return;
}

let dropMounts = require('../common').content.mounts;
let questMounts = require('../common').content.questMounts;
let specialMounts = require('../common').content.specialMounts;
let premiumMounts = require('../common').content.premiumPets; // premium mounts isn't exposed on the content object

let userMounts = {};

_.each([ dropMounts, questMounts, specialMounts, premiumMounts ], (set) => {
_.each(set, (pet, key) => {
userMounts[key] = true;
});
})

updateUser(userId, 'items.mounts', userMounts);
28 changes: 28 additions & 0 deletions debug-scripts/grant-all-pets.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

require('babel-register');

let _ = require('lodash');
let updateUser = require('./_helper').updateUser;
let userId = process.argv[2];

if (!userId) {
console.error('USAGE: node debug-scripts/grant-all-pets.js <user_id>');
console.error('EFFECT: Adds all pets to specified user');
return;
}

let dropPets = require('../common').content.pets;
let questPets = require('../common').content.questPets;
let specialPets = require('../common').content.specialPets;
let premiumPets = require('../common').content.premiumPets;

let userPets = {};

_.each([ dropPets, questPets, specialPets, premiumPets ], (set) => {
_.each(set, (pet, key) => {
userPets[key] = 95;
});
})

updateUser(userId, 'items.pets', userPets);

0 comments on commit d62807f

Please sign in to comment.