From d62807f7602ba8888524d926bd28c6fd0eae419d Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Tue, 15 Mar 2016 12:47:24 -0500 Subject: [PATCH] feat: Add debug scripts to easilly get all pets/mounts/gear --- README.md | 18 ++++++++++++++++++ debug-scripts/_helper.js | 19 +++++++++++++++++++ debug-scripts/grant-all-equipment.js | 24 ++++++++++++++++++++++++ debug-scripts/grant-all-mounts.js | 28 ++++++++++++++++++++++++++++ debug-scripts/grant-all-pets.js | 28 ++++++++++++++++++++++++++++ 5 files changed, 117 insertions(+) create mode 100644 debug-scripts/_helper.js create mode 100644 debug-scripts/grant-all-equipment.js create mode 100644 debug-scripts/grant-all-mounts.js create mode 100644 debug-scripts/grant-all-pets.js diff --git a/README.md b/README.md index e546a4295d..79581bd175 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/debug-scripts/_helper.js b/debug-scripts/_helper.js new file mode 100644 index 0000000000..2055e251a5 --- /dev/null +++ b/debug-scripts/_helper.js @@ -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(); + } + ); + }); +} diff --git a/debug-scripts/grant-all-equipment.js b/debug-scripts/grant-all-equipment.js new file mode 100644 index 0000000000..905abce4e7 --- /dev/null +++ b/debug-scripts/grant-all-equipment.js @@ -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 '); + 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); diff --git a/debug-scripts/grant-all-mounts.js b/debug-scripts/grant-all-mounts.js new file mode 100644 index 0000000000..1e23446b37 --- /dev/null +++ b/debug-scripts/grant-all-mounts.js @@ -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 '); + 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); diff --git a/debug-scripts/grant-all-pets.js b/debug-scripts/grant-all-pets.js new file mode 100644 index 0000000000..2cec573a5e --- /dev/null +++ b/debug-scripts/grant-all-pets.js @@ -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 '); + 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);