Added linting.

This commit is contained in:
ThePendulum 2021-11-01 16:06:48 +01:00
parent 126113bc9b
commit d36fe65612
5 changed files with 3439 additions and 489 deletions

14
.editorconfig Normal file
View File

@ -0,0 +1,14 @@
# 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,7 +3,8 @@
"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
@ -12,7 +13,8 @@
"strict": 0, "strict": 0,
"no-unused-vars": ["error", {"argsIgnorePattern": "^_"}], "no-unused-vars": ["error", {"argsIgnorePattern": "^_"}],
"no-console": 0, "no-console": 0,
"indent": ["error", 4], "indent": ["error", "tab"],
"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

@ -25,6 +25,8 @@
"yargs": "^17.2.1" "yargs": "^17.2.1"
}, },
"devDependencies": { "devDependencies": {
"eslint": "^8.1.0" "@babel/eslint-parser": "^7.16.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(([userKey, scoreA], [userKeyB, scoreB]) => scoreB - scoreA) .sort(([, scoreA], [, 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,8 +102,10 @@ 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', {
@ -117,7 +119,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((room) => room.id === message.roomId); const room = bot.rooms.find((roomX) => roomX.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 });
@ -201,7 +203,7 @@ async function init() {
}; };
const games = config.games.reduce((acc, key) => { const games = config.games.reduce((acc, key) => {
const game = require(`./games/${key}`); const game = require(`./games/${key}`); // eslint-disable-line global-require, import/no-dynamic-require
const sendMessage = (body, roomId) => { const sendMessage = (body, roomId) => {
bot.transmit('message', { bot.transmit('message', {
@ -225,12 +227,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);
messageHandlers[domain]?.(data, bot, games); if (messageHandlers[domain]) {
messageHandlers[domain](data, bot, games);
}
}); });
await initPoints(); await initPoints();