Added SChat code support, used in Letters board. Shielding style methods from empty inputs.

This commit is contained in:
ThePendulum 2022-10-23 03:25:39 +02:00
parent 5ec5711288
commit 6c3c442652
2 changed files with 20 additions and 6 deletions

View File

@ -22,7 +22,7 @@ const games = new Map();
function getBoard(context) {
const game = games.get(context.room.id);
return `${style.grey('[')}${game.word.split('').concat(Array.from({ length: config.letters.length - game.word.length })).map((letter) => style.bold(letter?.toUpperCase()) || '').join(style.grey('|'))}${style.grey(']')}`; // eslint-disable-line no-irregular-whitespace
return `${style.grey(style.code('['))}${game.word.split('').concat(Array.from({ length: config.letters.length - game.word.length })).map((letter) => style.bold(style.code(letter?.toUpperCase() || ''))).join(style.grey(style.code('|')))}${style.grey(style.code(']'))}`; // eslint-disable-line no-irregular-whitespace
}
function countLetters(word) {

View File

@ -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;