This commit is contained in:
2022-03-29 22:56:55 -05:00
parent bb50db4dec
commit 97c05f168d

View File

@@ -1,67 +0,0 @@
import { basicObject, basicObjectStringable, embedObject, LangObj } from '../types';
import { convertBasicObject, template } from '../util';
import { embedDataType } from './types';
import { embedObjEmbed } from './util';
import Lang, { getLang } from '..';
/**
* reads language json as an object (could be embed or just string)
* @param id ex: discord.error.noActiveQueue
* @param argsraw list of key/value pairs to represent template values
* @param otherOptions values to be passed through to the return value
* @returns language value, defaults to `id` parameter
*/
function getEmbed(id: string, argsraw: basicObjectStringable = {}, otherOptions: basicObject = {}): embedDataType {
const args = convertBasicObject(argsraw),
embedData: embedDataType = {
...otherOptions,
embeds: []
};
const keySpl = id.split('.').map(k => k.trim()).filter(k => k);
let finding = getLang();
for (const key of keySpl) {
if (key in finding) {
const found = finding[key];
if (typeof found === 'string') {
embedData.content = template(found, args);
break;
}
if (found.embed === true) {
const embedObj = found as embedObject,
{content} = embedObj,
embed = embedObjEmbed(embedObj, args);
embedData.embeds.push(embed);
if (content !== undefined)
embedData.content = content;
return embedData;
}
finding = found as LangObj;
} else
break;
}
return embedData;
}
export * from './types';
export * from './util';
export * from '..';
export default {
...Lang,
getEmbed
};