Compare commits

...

2 Commits

Author SHA1 Message Date
ThePendulum 39341178ff 1.4.9 2021-11-10 00:06:31 +01:00
ThePendulum 448f0ce3bd Using room map instead of list, fixing user join registration. 2021-11-10 00:06:28 +01:00
3 changed files with 8 additions and 8 deletions

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{
"name": "schat2-clive",
"version": "1.4.8",
"version": "1.4.9",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "schat2-clive",
"version": "1.4.8",
"version": "1.4.9",
"license": "ISC",
"dependencies": {
"bhttp": "^1.2.8",

View File

@ -1,6 +1,6 @@
{
"name": "schat2-clive",
"version": "1.4.8",
"version": "1.4.9",
"description": "Game host for SChat 2-powered chat sites",
"main": "src/app.js",
"scripts": {

View File

@ -105,7 +105,7 @@ function onRooms({ rooms, users }, bot) {
logger.info(`Joined ${rooms.map((room) => room.name).join(', ')}`);
/* eslint-disable no-param-reassign */
bot.rooms = rooms;
bot.rooms = rooms.reduce((acc, room) => ({ ...acc, [room.id]: room }), {});
bot.users = { ...bot.users, ...users };
/* eslint-enable no-param-reassign */
@ -120,22 +120,22 @@ function onRooms({ rooms, users }, bot) {
/* eslint-disable no-param-reassign */
function onJoin(data, bot) {
if (bot.rooms[data.roomId] && !bot.rooms[data.roomId]?.includes(data.user.id)) {
if (bot.rooms[data.roomId] && !bot.rooms[data.roomId].userIds?.includes(data.user.id)) {
bot.users[data.user.id] = data.user;
bot.rooms[data.roomId].push(data.user.id);
bot.rooms[data.roomId].userIds.push(data.user.id);
}
}
function onLeave(data, bot) {
if (bot.rooms[data.roomId]) {
bot.rooms[data.roomId].users = bot.rooms[data.roomId].users.filter((userId) => userId !== data.userId);
bot.rooms[data.roomId].userIds = bot.rooms[data.roomId].userIds.filter((userId) => userId !== data.userId);
}
}
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((roomX) => roomX.id === message.roomId);
const room = bot.rooms[message.roomId];
if (['leaderboard', 'lead', 'leader', 'leaders', 'scoreboard', 'best'].includes(subcommand) && games[command]) {
getLeaderboard(games[command], { user, room });