Last active
September 26, 2016 16:50
-
-
Save crookedneighbor/5c8e1f8de9f6d370899b88c593d93751 to your computer and use it in GitHub Desktop.
Populate Guilds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "guilds_script", | |
"version": "1.0.0", | |
"description": "", | |
"main": "guilds.js", | |
"repository": { | |
"type": "git", | |
"url": "git+ssh://[email protected]/5c8e1f8de9f6d370899b88c593d93751.git" | |
}, | |
"keywords": [], | |
"author": "Blade Barringer <[email protected]> (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" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 tovar 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.