Added SChat code support, used in Letters board. Shielding style methods from empty inputs.
This commit is contained in:
@@ -15,6 +15,10 @@ function schatColor(text, color) {
|
||||
return `{${color}}(${text})`;
|
||||
}
|
||||
|
||||
function schatCode(text) {
|
||||
return `\`${text}\``;
|
||||
}
|
||||
|
||||
function curate(fn) {
|
||||
return (text) => {
|
||||
if (text) {
|
||||
@@ -29,16 +33,24 @@ function bypass(text) {
|
||||
return text;
|
||||
}
|
||||
|
||||
function shieldMethods(methods) {
|
||||
return Object.fromEntries(Object.entries(methods).map(([key, method]) => [key, curate(method)]));
|
||||
}
|
||||
|
||||
module.exports = (() => {
|
||||
if (config.platform === 'irc') {
|
||||
return styles;
|
||||
return shieldMethods({
|
||||
...styles,
|
||||
code: bypass,
|
||||
});
|
||||
}
|
||||
|
||||
if (config.platform === 'schat') {
|
||||
const methods = {
|
||||
bold: curate(schatBold),
|
||||
italic: curate(schatItalic),
|
||||
...Object.fromEntries(Object.entries(config.schatColors).map(([color, value]) => [color, curate((text) => schatColor(text, value))])),
|
||||
bold: schatBold,
|
||||
italic: schatItalic,
|
||||
code: schatCode,
|
||||
...Object.fromEntries(Object.entries(config.schatColors).map(([color, value]) => [color, (text) => schatColor(text, value)])),
|
||||
};
|
||||
|
||||
const handler = {
|
||||
@@ -47,7 +59,9 @@ module.exports = (() => {
|
||||
},
|
||||
};
|
||||
|
||||
return new Proxy(methods, handler);
|
||||
const shieldedMethods = shieldMethods(methods);
|
||||
|
||||
return new Proxy(shieldedMethods, handler);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user