proper versioning and v6 guilds
This commit is contained in:
parent
5d13edf1be
commit
fc40a3757d
Binary file not shown.
Binary file not shown.
BIN
package-lock.json
generated
BIN
package-lock.json
generated
Binary file not shown.
@ -111,8 +111,8 @@ export async function Connection(
|
|||||||
if (socket.encoding === "etf" && !erlpack)
|
if (socket.encoding === "etf" && !erlpack)
|
||||||
throw new Error("Erlpack is not installed: 'npm i @yukikaze-bot/erlpack'");
|
throw new Error("Erlpack is not installed: 'npm i @yukikaze-bot/erlpack'");
|
||||||
|
|
||||||
socket.version = Number(searchParams.get("version")) || 8;
|
socket.version = Number(searchParams.get("v")) || 9;
|
||||||
if (socket.version != 8)
|
if (socket.version != 9 && socket.version != 6)
|
||||||
return socket.close(CLOSECODES.Invalid_API_version);
|
return socket.close(CLOSECODES.Invalid_API_version);
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@ -409,41 +409,66 @@ export async function onIdentify(this: WebSocket, data: Payload) {
|
|||||||
const pending_guilds: Guild[] = [];
|
const pending_guilds: Guild[] = [];
|
||||||
|
|
||||||
// Generate guilds list ( make them unavailable if user is bot )
|
// Generate guilds list ( make them unavailable if user is bot )
|
||||||
const guilds: GuildOrUnavailable[] = members.map((member) => {
|
let guilds: GuildOrUnavailable[];
|
||||||
member.guild.channels = member.guild.channels
|
|
||||||
/*
|
|
||||||
//TODO maybe implement this correctly, by causing create and delete events for users who can newly view and not view the channels, along with doing these checks correctly, as they don't currently take into account that the owner of the guild is always able to view channels, with potentially other issues
|
|
||||||
.filter((channel) => {
|
|
||||||
const perms = Permissions.finalPermission({
|
|
||||||
user: {
|
|
||||||
id: member.id,
|
|
||||||
roles: member.roles.map((x) => x.id),
|
|
||||||
},
|
|
||||||
guild: member.guild,
|
|
||||||
channel,
|
|
||||||
});
|
|
||||||
|
|
||||||
return perms.has("VIEW_CHANNEL");
|
if (this.version === 6) {
|
||||||
})
|
const membersByGuild = new Map<string, any[]>();
|
||||||
*/
|
|
||||||
|
for (const member of members) {
|
||||||
|
if (!membersByGuild.has(member.guild_id)) {
|
||||||
|
membersByGuild.set(member.guild_id, []);
|
||||||
|
}
|
||||||
|
|
||||||
|
membersByGuild.get(member.guild_id)!.push({
|
||||||
|
...member.toPublicMember(),
|
||||||
|
roles: member.roles
|
||||||
|
.filter((r) => r.id !== member.guild.id)
|
||||||
|
.map((r) => r.id),
|
||||||
|
user: user.toPublicUser(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
guilds = members.map((member) => {
|
||||||
|
const g = member.guild;
|
||||||
|
|
||||||
|
return {
|
||||||
|
...g.toJSON(),
|
||||||
|
joined_at: member.joined_at,
|
||||||
|
channels: g.channels,
|
||||||
|
roles: g.roles,
|
||||||
|
emojis: g.emojis,
|
||||||
|
stickers: g.stickers,
|
||||||
|
voice_states: g.voice_states ?? [],
|
||||||
|
members: membersByGuild.get(g.id) ?? [],
|
||||||
|
member_count: membersByGuild.get(g.id)?.length ?? 1,
|
||||||
|
presences: [],
|
||||||
|
guild_scheduled_events: [],
|
||||||
|
threads: [],
|
||||||
|
large: false,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
guilds = members.map((member) => {
|
||||||
|
member.guild.channels = member.guild.channels
|
||||||
.map((channel) => {
|
.map((channel) => {
|
||||||
channel.position = member.guild.channel_ordering.indexOf(channel.id);
|
channel.position = member.guild.channel_ordering.indexOf(channel.id);
|
||||||
return channel;
|
return channel;
|
||||||
})
|
})
|
||||||
.sort((a, b) => a.position - b.position);
|
.sort((a, b) => a.position - b.position);
|
||||||
|
|
||||||
if (user.bot) {
|
if (user.bot) {
|
||||||
pending_guilds.push(member.guild);
|
pending_guilds.push(member.guild);
|
||||||
return { id: member.guild.id, unavailable: true };
|
return { id: member.guild.id, unavailable: true };
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...member.guild.toJSON(),
|
...member.guild.toJSON(),
|
||||||
joined_at: member.joined_at,
|
joined_at: member.joined_at,
|
||||||
guild_scheduled_events: [],
|
guild_scheduled_events: [],
|
||||||
threads: [],
|
threads: [],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
}
|
||||||
const generateGuildsListTime = taskSw.getElapsedAndReset();
|
const generateGuildsListTime = taskSw.getElapsedAndReset();
|
||||||
|
|
||||||
// Generate user_guild_settings
|
// Generate user_guild_settings
|
||||||
@ -555,7 +580,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
|
|||||||
d = {
|
d = {
|
||||||
v: 6,
|
v: 6,
|
||||||
...base,
|
...base,
|
||||||
heartbeat_interval: 45_000,
|
heartbeat_interval: 45000,
|
||||||
guilds,
|
guilds,
|
||||||
private_channels: channels,
|
private_channels: channels,
|
||||||
presences: [],
|
presences: [],
|
||||||
@ -745,50 +770,46 @@ export async function onIdentify(this: WebSocket, data: Payload) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const pendingGuildsTime = Date.now();
|
if (this.version == 9) {
|
||||||
|
const readySupplementalGuilds = (guilds.filter((guild) => !guild.unavailable) as Guild[]).map((guild) => {
|
||||||
|
return {
|
||||||
|
voice_states: guild.voice_states.map((state) => {
|
||||||
|
// quick fix -murdle
|
||||||
|
const voiceState: any = {};
|
||||||
|
PublicVoiceStateProjection.forEach((x) => {
|
||||||
|
voiceState[x] = state[x];
|
||||||
|
});
|
||||||
|
return voiceState as PublicVoiceState;
|
||||||
|
}),
|
||||||
|
id: guild.id,
|
||||||
|
embedded_activities: [],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
const readySupplementalGuilds = (guilds.filter((guild) => !guild.unavailable) as Guild[]).map((guild) => {
|
// TODO: ready supplemental
|
||||||
return {
|
await Send(this, {
|
||||||
voice_states: guild.voice_states.map((state) => {
|
op: OPCodes.DISPATCH,
|
||||||
// quick fix -murdle
|
t: EVENTEnum.ReadySupplemental,
|
||||||
const voiceState: any = {};
|
s: this.sequence++,
|
||||||
PublicVoiceStateProjection.forEach((x) => {
|
d: {
|
||||||
voiceState[x] = state[x];
|
merged_presences: {
|
||||||
});
|
guilds: [],
|
||||||
return voiceState as PublicVoiceState;
|
friends: [],
|
||||||
}),
|
},
|
||||||
id: guild.id,
|
// these merged members seem to be all users currently in vc in your guilds
|
||||||
embedded_activities: [],
|
merged_members: [],
|
||||||
};
|
lazy_private_channels: [],
|
||||||
});
|
guilds: readySupplementalGuilds, // { voice_states: [], id: string, embedded_activities: [] }
|
||||||
|
// embedded_activities are users currently in an activity?
|
||||||
// TODO: ready supplemental
|
disclose: [], // Config.get().general.uniqueUsernames ? ["pomelo"] : []
|
||||||
await Send(this, {
|
|
||||||
op: OPCodes.DISPATCH,
|
|
||||||
t: EVENTEnum.ReadySupplemental,
|
|
||||||
s: this.sequence++,
|
|
||||||
d: {
|
|
||||||
merged_presences: {
|
|
||||||
guilds: [],
|
|
||||||
friends: [],
|
|
||||||
},
|
},
|
||||||
// these merged members seem to be all users currently in vc in your guilds
|
});
|
||||||
merged_members: [],
|
}
|
||||||
lazy_private_channels: [],
|
|
||||||
guilds: readySupplementalGuilds, // { voice_states: [], id: string, embedded_activities: [] }
|
|
||||||
// embedded_activities are users currently in an activity?
|
|
||||||
disclose: [], // Config.get().general.uniqueUsernames ? ["pomelo"] : []
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const readySupplementalTime = Date.now();
|
|
||||||
|
|
||||||
//TODO send GUILD_MEMBER_LIST_UPDATE
|
//TODO send GUILD_MEMBER_LIST_UPDATE
|
||||||
//TODO send VOICE_STATE_UPDATE to let the client know if another device is already connected to a voice channel
|
//TODO send VOICE_STATE_UPDATE to let the client know if another device is already connected to a voice channel
|
||||||
|
|
||||||
await setupListener.call(this);
|
await setupListener.call(this);
|
||||||
|
|
||||||
const setupListenerTime = Date.now();
|
|
||||||
|
|
||||||
console.log(`[Gateway] IDENTIFY ${this.user_id} in ${totalSw.elapsed().totalMilliseconds}ms`, process.env.LOG_GATEWAY_TRACES ? JSON.stringify(d._trace, null, 2) : "");
|
console.log(`[Gateway] IDENTIFY ${this.user_id} in ${totalSw.elapsed().totalMilliseconds}ms`, process.env.LOG_GATEWAY_TRACES ? JSON.stringify(d._trace, null, 2) : "");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user