Compare commits

..

No commits in common. "aed92bfefaae6e29f58e74be358a56c0207e730b" and "126113bc9b042c9cb09651e61324af477f570720" have entirely different histories.

5 changed files with 488 additions and 3438 deletions

View File

@ -1,14 +0,0 @@
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = tab
indent_size = 4
# Matches multiple files with brace expansion notation
# Set default charset
[*.js]
charset = utf-8

View File

@ -3,8 +3,7 @@
"extends": "airbnb-base", "extends": "airbnb-base",
"parser": "@babel/eslint-parser", "parser": "@babel/eslint-parser",
"parserOptions": { "parserOptions": {
"sourceType": "script", "sourceType": "script"
"requireConfigFile": false
}, },
"env": { "env": {
"es2020": true "es2020": true
@ -13,8 +12,7 @@
"strict": 0, "strict": 0,
"no-unused-vars": ["error", {"argsIgnorePattern": "^_"}], "no-unused-vars": ["error", {"argsIgnorePattern": "^_"}],
"no-console": 0, "no-console": 0,
"indent": ["error", "tab"], "indent": ["error", 4],
"no-tabs": 0,
"max-len": [2, {"code": 400, "tabWidth": 4, "ignoreUrls": true}] "max-len": [2, {"code": 400, "tabWidth": 4, "ignoreUrls": true}]
} }
} }

3594
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "schat2-clive", "name": "schat2-clive",
"version": "1.1.1", "version": "1.1.0",
"description": "Game host for SChat 2-powered chat sites", "description": "Game host for SChat 2-powered chat sites",
"main": "src/app.js", "main": "src/app.js",
"scripts": { "scripts": {
@ -25,8 +25,6 @@
"yargs": "^17.2.1" "yargs": "^17.2.1"
}, },
"devDependencies": { "devDependencies": {
"@babel/eslint-parser": "^7.16.0", "eslint": "^8.1.0"
"eslint": "^7.2.0",
"eslint-config-airbnb-base": "^14.2.1"
} }
} }

View File

@ -84,10 +84,10 @@ function getLeaderboard(game, { user, room }) {
} }
const curatedLeaderboard = Object.entries(leaderboard) const curatedLeaderboard = Object.entries(leaderboard)
.sort(([, scoreA], [, scoreB]) => scoreB - scoreA) .sort(([userKey, scoreA], [userKeyB, scoreB]) => scoreB - scoreA)
.map(([userKey, score]) => { .map(([userKey, score]) => {
const username = userKey.split(':')[1]; const username = userKey.split(':')[1];
return `**${username === user.username ? '@' : ''}${username}** at **${score}** points`; return `**${username === user.username ? '@' : ''}${username}** at **${score}** points`
}) })
.slice(-10) .slice(-10)
.join(', '); .join(', ');
@ -102,10 +102,8 @@ function onConnect(data, bot) {
function onRooms({ rooms, users }, bot) { function onRooms({ rooms, users }, bot) {
logger.info(`Joined ${rooms.map((room) => room.name).join(', ')}`); logger.info(`Joined ${rooms.map((room) => room.name).join(', ')}`);
/* eslint-disable no-param-reassign */
bot.rooms = rooms; bot.rooms = rooms;
bot.users = { ...bot.users, ...users }; bot.users = { ...bot.users, ...users };
/* eslint-enable no-param-reassign */
rooms.forEach((room) => { rooms.forEach((room) => {
bot.transmit('message', { bot.transmit('message', {
@ -119,7 +117,7 @@ function onRooms({ rooms, users }, bot) {
function onMessage(message, bot, games) { function onMessage(message, bot, games) {
const [, command, subcommand] = message.body?.match(new RegExp(`^${config.prefix}(\\w+)(?:\\:(\\w+))?`)) || []; const [, command, subcommand] = message.body?.match(new RegExp(`^${config.prefix}(\\w+)(?:\\:(\\w+))?`)) || [];
const user = bot.users[message.userId]; const user = bot.users[message.userId];
const room = bot.rooms.find((roomX) => roomX.id === message.roomId); const room = bot.rooms.find((room) => room.id === message.roomId);
if (['leaderboard', 'lead', 'leader', 'leaders', 'scoreboard', 'best'].includes(subcommand) && games[command]) { if (['leaderboard', 'lead', 'leader', 'leaders', 'scoreboard', 'best'].includes(subcommand) && games[command]) {
getLeaderboard(games[command], { user, room }); getLeaderboard(games[command], { user, room });
@ -203,7 +201,7 @@ async function init() {
}; };
const games = config.games.reduce((acc, key) => { const games = config.games.reduce((acc, key) => {
const game = require(`./games/${key}`); // eslint-disable-line global-require, import/no-dynamic-require const game = require(`./games/${key}`);
const sendMessage = (body, roomId) => { const sendMessage = (body, roomId) => {
bot.transmit('message', { bot.transmit('message', {
@ -227,12 +225,12 @@ async function init() {
}; };
}, {}); }, {});
const gamesWithListeners = Object.entries(games).filter(([key, game]) => game.onMessage).map(([key, game]) => ({ ...game, key }));
ws.on('message', (msg) => { ws.on('message', (msg) => {
const [domain, data] = JSON.parse(msg); const [domain, data] = JSON.parse(msg);
if (messageHandlers[domain]) { messageHandlers[domain]?.(data, bot, games);
messageHandlers[domain](data, bot, games);
}
}); });
await initPoints(); await initPoints();