Upgraded Clive to new room user ID data.

This commit is contained in:
ThePendulum 2023-07-11 16:41:38 +02:00
parent a45d00c105
commit b9be447dba
1 changed files with 20 additions and 1 deletions

View File

@ -60,8 +60,27 @@ async function onRooms({ rooms }, bot) {
const usersRes = await bhttp.get(`${config.api}/room/${rooms.map((room) => room.id).join(',')}/users`); const usersRes = await bhttp.get(`${config.api}/room/${rooms.map((room) => room.id).join(',')}/users`);
const users = usersRes.body; const users = usersRes.body;
const userIdsByRoom = Object.values(users).reduce((acc, user) => {
user.sharedRooms.forEach((roomId) => {
if (!acc[roomId]) {
acc[roomId] = [];
}
acc[roomId].push(user.id);
});
return acc;
}, {});
/* eslint-disable no-param-reassign */ /* eslint-disable no-param-reassign */
bot.rooms = rooms.reduce((acc, room) => ({ ...acc, [room.id]: room }), {}); bot.rooms = rooms.reduce((acc, room) => ({
...acc,
[room.id]: {
...room,
userIds: userIdsByRoom[room.id],
},
}), {});
bot.users = { ...bot.users, ...users }; bot.users = { ...bot.users, ...users };
/* eslint-enable no-param-reassign */ /* eslint-enable no-param-reassign */