From b9be447dba1d92fa9f1fc0acd10fd183f641fddc Mon Sep 17 00:00:00 2001 From: ThePendulum Date: Tue, 11 Jul 2023 16:41:38 +0200 Subject: [PATCH] Upgraded Clive to new room user ID data. --- src/schat.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/schat.js b/src/schat.js index 3937441..72d52d3 100755 --- a/src/schat.js +++ b/src/schat.js @@ -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 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 */ - 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 }; /* eslint-enable no-param-reassign */