Ind.ie is now Small Technology Foundation.
Commit 8fa7f541 authored by wim-vantomme's avatar wim-vantomme

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
// check for user preference
let locale = null
if(process.server) {
if (process.server) {
let cookies = req.headers.cookie
if(cookies) {
if (cookies) {
cookies = cookie.parse(cookies)
if(cookies.locale) {
if (cookies.locale) {
locale = cookies.locale
}
}
......
This diff is collapsed.
......@@ -12,4 +12,4 @@ export default ({app, store}) => {
'en-GB': require('~/locales/en-GB.json')
}
})
}
\ No newline at end of file
}
......@@ -61,6 +61,7 @@ class Service {
if (data.id === 7) {
try {
const email = data.response.email
console.log(data)
// TODO: add e-mail to database and send email.
} catch (err) {
return err
......
......@@ -27,7 +27,7 @@ class Service {
await this.app.service('bot').create(message)
return "OK"
return 'OK'
}
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