From e49429784e35d29807ddeaeba339c6a9acf98580 Mon Sep 17 00:00:00 2001 From: Niels Simenon Date: Fri, 21 Oct 2022 22:11:31 +0200 Subject: [PATCH] Added HTML colors for SChat. Adapted Letters game for SChat. --- config/default.js | 18 +++++++++++++++--- src/games/letters.js | 6 +++++- src/utils/style.js | 19 +++++++++++++++++-- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/config/default.js b/config/default.js index 82868ea..3976db3 100644 --- a/config/default.js +++ b/config/default.js @@ -3,23 +3,35 @@ module.exports = { platform: 'schat', user: { + id: 'aisha', nick: 'aisha', username: 'Aisha', realName: 'Aisha', }, style: { - color: 'var(--message-56)', + // color: 'var(--message-56)', }, operators: ['admin'], server: 'irc.libera.chat', port: 6697, + socket: 'ws://127.0.0.1:3000/socket', + api: 'http://127.0.0.1:3000/api', reconnectDelay: 10, // seconds prefix: '~', labels: true, greeting: 'Hi, I am aisha, your game host!', usernamePrefix: '@', - channels: ['##pendulum'], - games: ['mash', 'trivia', 'duck', 'ping', 'say', 'kill'], + channels: ['GamesNight'], + games: ['mash', 'trivia', 'letters', 'duck', 'ping', 'say', 'kill'], + schatColors: { + red: 'var(--message-3)', + green: 'var(--message-23)', + yellow: 'var(--message-12)', + pink: 'var(--message-57)', + cyan: 'var(--message-31)', + grey: 'var(--shadow)', + // grey: 'var(--message-59)', + }, trivia: { mode: 'first', // first or timeout rounds: 10, diff --git a/src/games/letters.js b/src/games/letters.js index 01371ca..f0591db 100644 --- a/src/games/letters.js +++ b/src/games/letters.js @@ -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) => letter?.toUpperCase() || ' ').join(style.grey(' | '))} ${style.grey(']')}`; + 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 } function countLetters(word) { @@ -158,6 +158,10 @@ function onCommand(args, context) { function onMessage(message, context) { const game = games.get(context.room.id); + if (message.type !== 'message' || context.user?.id === config.user?.id) { // stop listening to yourself + return; + } + if (game?.state === 'letters') { const multi = message.body.match(/\b[vc]{2,}\b/i)?.[0]; diff --git a/src/utils/style.js b/src/utils/style.js index 7fb05bc..09c8232 100644 --- a/src/utils/style.js +++ b/src/utils/style.js @@ -11,6 +11,20 @@ function schatItalic(text) { return `*${text}*`; } +function schatColor(text, color) { + return `${text}`; +} + +function curate(fn) { + return (text) => { + if (text) { + return fn(text); + } + + return ''; + }; +} + function bypass(text) { return text; } @@ -22,8 +36,9 @@ module.exports = (() => { if (config.platform === 'schat') { const methods = { - bold: schatBold, - italic: schatItalic, + bold: curate(schatBold), + italic: curate(schatItalic), + ...Object.fromEntries(Object.entries(config.schatColors).map(([color, value]) => [color, curate((text) => schatColor(text, value))])), }; const handler = {