diff options
Diffstat (limited to 'src/gateway/opcodes/Identify.ts')
-rw-r--r-- | src/gateway/opcodes/Identify.ts | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index 1c3cab28..8d762967 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -1,3 +1,21 @@ +/* + Fosscord: A FOSS re-implementation and extension of the Discord.com backend. + Copyright (C) 2023 Fosscord and Fosscord Contributors + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ + import { WebSocket, Payload } from "@fosscord/gateway"; import { checkToken, @@ -72,7 +90,6 @@ export async function onIdentify(this: WebSocket, data: Payload) { "guild", "guild.channels", "guild.emojis", - "guild.emojis.user", "guild.roles", "guild.stickers", "user", @@ -141,18 +158,11 @@ export async function onIdentify(this: WebSocket, data: Payload) { }) as PublicMember[][]; let guilds = members.map((x) => ({ ...x.guild, joined_at: x.joined_at })); + const pending_guilds: typeof guilds = []; // @ts-ignore guilds = guilds.map((guild) => { if (user.bot) { - setTimeout(() => { - var promise = Send(this, { - op: OPCODES.Dispatch, - t: EVENTEnum.GuildCreate, - s: this.sequence++, - d: guild, - }); - if (promise) promise.catch(console.error); - }, 500); + pending_guilds.push(guild); return { id: guild.id, unavailable: true }; } @@ -314,6 +324,17 @@ export async function onIdentify(this: WebSocket, data: Payload) { d, }); + await Promise.all( + pending_guilds.map((guild) => + Send(this, { + op: OPCODES.Dispatch, + t: EVENTEnum.GuildCreate, + s: this.sequence++, + d: guild, + })?.catch(console.error), + ), + ); + //TODO send READY_SUPPLEMENTAL //TODO send GUILD_MEMBER_LIST_UPDATE //TODO send SESSIONS_REPLACE |