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" | |
} | |
} |
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
The code actually makes sense to me, incredible as it may seem (except that I don't know how promise works), but I'm having trouble running it. I copied the files to my Habitica root folder (above the habitrpg folder) and ran the
npm install [email protected] uuid
command and it worked fine, created a node_modules folder and everything. But when I donode guilds.js
nothing happens, did I have to do something else? Oh and I did change theGUILD_ID
value, and http://localhost:3000 is the right url.Just to make sure I understood the code, it would still work if I changed
var name = uuid()
tovar name = 'Test' + count
right?