Added linting.
This commit is contained in:
parent
126113bc9b
commit
d36fe65612
|
@ -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
|
|
@ -3,7 +3,8 @@
|
|||
"extends": "airbnb-base",
|
||||
"parser": "@babel/eslint-parser",
|
||||
"parserOptions": {
|
||||
"sourceType": "script"
|
||||
"sourceType": "script",
|
||||
"requireConfigFile": false
|
||||
},
|
||||
"env": {
|
||||
"es2020": true
|
||||
|
@ -12,7 +13,8 @@
|
|||
"strict": 0,
|
||||
"no-unused-vars": ["error", {"argsIgnorePattern": "^_"}],
|
||||
"no-console": 0,
|
||||
"indent": ["error", 4],
|
||||
"indent": ["error", "tab"],
|
||||
"no-tabs": 0,
|
||||
"max-len": [2, {"code": 400, "tabWidth": 4, "ignoreUrls": true}]
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -25,6 +25,8 @@
|
|||
"yargs": "^17.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.1.0"
|
||||
"@babel/eslint-parser": "^7.16.0",
|
||||
"eslint": "^7.2.0",
|
||||
"eslint-config-airbnb-base": "^14.2.1"
|
||||
}
|
||||
}
|
||||
|
|
16
src/app.js
16
src/app.js
|
@ -84,10 +84,10 @@ function getLeaderboard(game, { user, room }) {
|
|||
}
|
||||
|
||||
const curatedLeaderboard = Object.entries(leaderboard)
|
||||
.sort(([userKey, scoreA], [userKeyB, scoreB]) => scoreB - scoreA)
|
||||
.sort(([, scoreA], [, scoreB]) => scoreB - scoreA)
|
||||
.map(([userKey, score]) => {
|
||||
const username = userKey.split(':')[1];
|
||||
return `**${username === user.username ? '@' : ''}${username}** at **${score}** points`
|
||||
return `**${username === user.username ? '@' : ''}${username}** at **${score}** points`;
|
||||
})
|
||||
.slice(-10)
|
||||
.join(', ');
|
||||
|
@ -102,8 +102,10 @@ function onConnect(data, bot) {
|
|||
function onRooms({ rooms, users }, bot) {
|
||||
logger.info(`Joined ${rooms.map((room) => room.name).join(', ')}`);
|
||||
|
||||
/* eslint-disable no-param-reassign */
|
||||
bot.rooms = rooms;
|
||||
bot.users = { ...bot.users, ...users };
|
||||
/* eslint-enable no-param-reassign */
|
||||
|
||||
rooms.forEach((room) => {
|
||||
bot.transmit('message', {
|
||||
|
@ -117,7 +119,7 @@ function onRooms({ rooms, users }, bot) {
|
|||
function onMessage(message, bot, games) {
|
||||
const [, command, subcommand] = message.body?.match(new RegExp(`^${config.prefix}(\\w+)(?:\\:(\\w+))?`)) || [];
|
||||
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]) {
|
||||
getLeaderboard(games[command], { user, room });
|
||||
|
@ -201,7 +203,7 @@ async function init() {
|
|||
};
|
||||
|
||||
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) => {
|
||||
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) => {
|
||||
const [domain, data] = JSON.parse(msg);
|
||||
|
||||
messageHandlers[domain]?.(data, bot, games);
|
||||
if (messageHandlers[domain]) {
|
||||
messageHandlers[domain](data, bot, games);
|
||||
}
|
||||
});
|
||||
|
||||
await initPoints();
|
||||
|
|
Loading…
Reference in New Issue