Using room map instead of list, fixing user join registration.
This commit is contained in:
parent
f4df512031
commit
448f0ce3bd
10
src/app.js
10
src/app.js
|
@ -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 });
|
||||
|
|
Loading…
Reference in New Issue