Added code generation.

parent 92da6e0b
const assert = require('assert')
const fs = require('fs')
const yargs = require('yargs')
const {Picker} = require('RandomSelection')
const randomNumber = require('random-number-csprng')
const hhgttg = JSON.parse(fs.readFileSync('./all-unique-words-in-hitchhikers-guide-to-the-galaxy.json'))
const hhgttgPicker = new Picker(hhgttg)
const wordsToAvoid = ['mongoloid', 'buggering', 'cock', 'stupid', 'fingering']
const argv = yargs
.command('create', 'Create new accountcodes', {
amount: {
describe: 'The ammount of codes to generate, integer value',
demand: true,
alias: 'a'
}
})
.help()
.argv
const command = argv._[0]
switch (command) {
case 'create':
generateCodes(argv.amount)
break
default:
console.log('Command not recognised, run code --help to get an overview of all commands.')
}
function generateCodes (number) {
let promises = []
let codes = []
for (let i = 0; i < number; i++) {
const random = randomNumber(1001, 10000)
promises.push(random)
}
Promise.all(promises).then((randomNumbers) => {
for (let i = 0; i < number; i++) {
const code = `${pickWord()}-${pickWord()}-${randomNumbers[i]}`
codes.push(code)
}
// Check if all values are unique.
codes = codes.filter((v, i, a) => a.indexOf(v) === i)
console.log(codes)
return codes
})
}
function pickWord () {
let word = hhgttgPicker.pick().toLowerCase()
if (wordsToAvoid.includes(word)) {
word = pickWord()
}
return word
}
"Het antwoord op de ultieme vraag over het Leven, het Universum, en Alles"
...@@ -7,11 +7,11 @@ export default function ({ isHMR, app, store, route, params, error, redirect, re ...@@ -7,11 +7,11 @@ export default function ({ isHMR, app, store, route, params, error, redirect, re
// check for user preference // check for user preference
let locale = null let locale = null
if(process.server) { if (process.server) {
let cookies = req.headers.cookie let cookies = req.headers.cookie
if(cookies) { if (cookies) {
cookies = cookie.parse(cookies) cookies = cookie.parse(cookies)
if(cookies.locale) { if (cookies.locale) {
locale = cookies.locale locale = cookies.locale
} }
} }
......
This diff is collapsed.
...@@ -67,13 +67,17 @@ ...@@ -67,13 +67,17 @@
"winston": "^2.4.0" "winston": "^2.4.0"
}, },
"devDependencies": { "devDependencies": {
"RandomSelection": "^1.0.1",
"eslint": "^4.17.0", "eslint": "^4.17.0",
"expect": "^22.2.2", "expect": "^22.2.2",
"lodash": "^4.17.5",
"mocha": "^5.0.1", "mocha": "^5.0.1",
"random-number-csprng": "^1.0.2",
"request": "^2.83.0", "request": "^2.83.0",
"request-promise": "^4.2.2", "request-promise": "^4.2.2",
"sinon": "^4.3.0", "sinon": "^4.3.0",
"standard": "^10.0.3", "standard": "^10.0.3",
"supertest": "^3.0.0" "supertest": "^3.0.0",
"yargs": "^11.0.0"
} }
} }
...@@ -12,4 +12,4 @@ export default ({app, store}) => { ...@@ -12,4 +12,4 @@ export default ({app, store}) => {
'en-GB': require('~/locales/en-GB.json') 'en-GB': require('~/locales/en-GB.json')
} }
}) })
} }
\ No newline at end of file
...@@ -61,6 +61,7 @@ class Service { ...@@ -61,6 +61,7 @@ class Service {
if (data.id === 7) { if (data.id === 7) {
try { try {
const email = data.response.email const email = data.response.email
console.log(data)
// TODO: add e-mail to database and send email. // TODO: add e-mail to database and send email.
} catch (err) { } catch (err) {
return err return err
......
...@@ -27,7 +27,7 @@ class Service { ...@@ -27,7 +27,7 @@ class Service {
await this.app.service('bot').create(message) await this.app.service('bot').create(message)
return "OK" return 'OK'
} }
async create (data, params) { async create (data, params) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment