change how namegen worked to be sync

This commit is contained in:
zkldi
2021-04-27 00:13:45 +01:00
parent 103cc9b050
commit 9c5acbd6e4
@@ -1,38 +1,9 @@
import db from "../../../../db/db";
import { KtLogger } from "../../../../types";
import { GetRandomAdjective, GetRandomNoun } from "../../../../data/words";
export async function GenerateRandomSessionName(logger: KtLogger) {
let adjectives = await db.adjectives.aggregate([
{
$sample: {
size: 2,
},
},
]);
export function GenerateRandomSessionName() {
let adj1 = GetRandomAdjective();
let adj2 = GetRandomAdjective();
let noun = GetRandomNoun();
let nouns = await db.nouns.aggregate([
{
$sample: {
size: 1,
},
},
]);
if (adjectives.length < 2) {
logger.severe(
`Could not source 2 adjectives from the adjectives DB. Filling in with defaults, but this should be investigated.`
);
adjectives = ["Ambient", "Scary"];
}
if (nouns.length < 1) {
logger.severe(
`Could not source a noun from the noun DB. Filling in with defaults, but this should be investigated.`
);
nouns = ["Noise"];
}
return `${adjectives[0].text} ${adjectives[1].text} ${nouns[0].text}`;
return `${adj1} ${adj2} ${noun}`;
}