Skip to content

Instantly share code, notes, and snippets.

@crookedneighbor
Last active September 26, 2016 16:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crookedneighbor/5c8e1f8de9f6d370899b88c593d93751 to your computer and use it in GitHub Desktop.
Save crookedneighbor/5c8e1f8de9f6d370899b88c593d93751 to your computer and use it in GitHub Desktop.
Populate Guilds
'use strict'
var uuid = require('uuid').v4
var Habitica = require('habitica')
var ENDPOINT = 'http://localhost:3000' // whatever your endpoint url is
var GUILD_ID = 'your-public-guild-id'
var NUMBER_OF_MEMBERS = 100
var count = 0
function makeNewUser () {
var api = new Habitica({
endpoint: ENDPOINT
})
var name = uuid()
var email = name + '@example.com'
var password = 'password'
return api.register(name, email, password).then(function () {
return api
})
}
function joinGuild (api) {
return api.post('/groups/' + GUILD_ID + '/join').then(function (res) {
var guildName = res.data.name
console.log(++count + ' user(s) have joined ' + guildName)
})
}
function logError (err) {
if (err.message) {
console.error(err.message)
} else {
console.error(err)
}
}
var promise = Promise.resolve()
for (var i = 0; i < NUMBER_OF_MEMBERS; i++) {
promise = promise.then(makeNewUser).then(joinGuild)
}
promise.catch(logError)
{
"name": "guilds_script",
"version": "1.0.0",
"description": "",
"main": "guilds.js",
"repository": {
"type": "git",
"url": "git+ssh://git@gist.github.com/5c8e1f8de9f6d370899b88c593d93751.git"
},
"keywords": [],
"author": "Blade Barringer <blade@crookedneighbor.com> (http://crookedneighbor.com/)",
"license": "MIT",
"bugs": {
"url": "https://gist.github.com/5c8e1f8de9f6d370899b88c593d93751"
},
"homepage": "https://gist.github.com/5c8e1f8de9f6d370899b88c593d93751",
"dependencies": {
"habitica": "^4.0.0-beta.1",
"uuid": "^2.0.3"
}
}
@crookedneighbor
Copy link
Author

I've adjusted the script a little to catch and log any errors you might be receiving. Update it with the new file and see if it tells you anything.

In theory you can change the name section to var name = 'Test' + count, but since usernames and emails need to be unique, it'll fail to register a user if you run it a second time.The uuid function assures that it will be a random string of numbers and characters, so it won't fail to register the new users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment