convai / server /personalities.ts
Julien Chaumond
server
d0aa19c
raw
history blame
960 Bytes
const __ = require('./lib/Extensions');
import * as fs from 'fs';
import fetch from 'node-fetch';
import { c } from './lib/Log';
import __rootDir from './lib/RootDirFinder';
(async () => {
const response = await fetch(`http://pouet.eastus.cloudapp.azure.com:8080/personality/all?all=true`, {
method: 'POST',
});
const personas = (await response.json()).personality as string[];
c.debug(`Personas from server: ${personas.length}`);
c.debug(`Deduped: ${ (new Set(personas)).size }`);
const o: Obj<string> = {};
for (const persona of personas) {
const slug = persona
.replace(/\W/g, '-')
.replace(/-+$/, "") // <- trim trailing dash
.replace(/--+/g, "-") // <- never allow more than one consecutive dash
;
o[slug] = persona;
}
c.debug(
`After slugification: ${ (new Set(Object.keys(o))).size }`
);
await fs.promises.writeFile(
__rootDir+`/server/data/personas.json`,
JSON.stringify(o, null, 2)
);
process.exit();
})();