This commit is contained in:
Madeline
2023-01-05 17:16:55 +11:00
parent a665a39523
commit df449169bd
124 changed files with 3639 additions and 1697 deletions
+2 -2
View File
@@ -12,7 +12,7 @@ import { Config } from "@fosscord/util";
var erlpack: any;
try {
erlpack = require("@yukikaze-bot/erlpack");
} catch (error) { }
} catch (error) {}
// TODO: check rate limit
// TODO: specify rate limit in config
@@ -48,7 +48,7 @@ export async function Connection(
"open",
"ping",
"pong",
"unexpected-response"
"unexpected-response",
].forEach((x) => {
socket.on(x, (y) => console.log(x, y));
});
+31 -22
View File
@@ -10,30 +10,36 @@ const bigIntJson = BigIntJson({ storeAsString: true });
var erlpack: any;
try {
erlpack = require("@yukikaze-bot/erlpack");
} catch (error) { }
} catch (error) {}
export async function Message(this: WebSocket, buffer: WS.Data) {
// TODO: compression
var data: Payload;
if ((buffer instanceof Buffer && buffer[0] === 123) || // ASCII 123 = `{`. Bad check for JSON
(typeof buffer === "string")) {
if (
(buffer instanceof Buffer && buffer[0] === 123) || // ASCII 123 = `{`. Bad check for JSON
typeof buffer === "string"
) {
data = bigIntJson.parse(buffer.toString());
}
else if (this.encoding === "json" && buffer instanceof Buffer) {
} else if (this.encoding === "json" && buffer instanceof Buffer) {
if (this.inflate) {
try { buffer = this.inflate.process(buffer) as any; }
catch { buffer = buffer.toString() as any; }
try {
buffer = this.inflate.process(buffer) as any;
} catch {
buffer = buffer.toString() as any;
}
}
data = bigIntJson.parse(buffer as string);
}
else if (this.encoding === "etf" && buffer instanceof Buffer) {
try { data = erlpack.unpack(buffer); }
catch { return this.close(CLOSECODES.Decode_error); }
}
else return this.close(CLOSECODES.Decode_error);
} else if (this.encoding === "etf" && buffer instanceof Buffer) {
try {
data = erlpack.unpack(buffer);
} catch {
return this.close(CLOSECODES.Decode_error);
}
} else return this.close(CLOSECODES.Decode_error);
if (process.env.WS_VERBOSE) console.log(`[Websocket] Incomming message: ${JSON.stringify(data)}`);
if (process.env.WS_VERBOSE)
console.log(`[Websocket] Incomming message: ${JSON.stringify(data)}`);
check.call(this, PayloadSchema, data);
@@ -46,14 +52,17 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
return;
}
const transaction = data.op != 1 ? Sentry.startTransaction({
op: OPCODES[data.op],
name: `GATEWAY ${OPCODES[data.op]}`,
data: {
...data.d,
token: data?.d?.token ? "[Redacted]" : undefined,
},
}) : undefined;
const transaction =
data.op != 1
? Sentry.startTransaction({
op: OPCODES[data.op],
name: `GATEWAY ${OPCODES[data.op]}`,
data: {
...data.d,
token: data?.d?.token ? "[Redacted]" : undefined,
},
})
: undefined;
try {
var ret = await OPCodeHandler.call(this, data);
+5 -2
View File
@@ -259,7 +259,10 @@ export async function onIdentify(this: WebSocket, data: Payload) {
const d: ReadyEventData = {
v: 9,
application: { id: application?.id ?? '', flags: application?.flags ?? 0 }, //TODO: check this code!
application: {
id: application?.id ?? "",
flags: application?.flags ?? 0,
}, //TODO: check this code!
user: privateUser,
user_settings: user.settings,
// @ts-ignore
@@ -267,7 +270,7 @@ export async function onIdentify(this: WebSocket, data: Payload) {
return {
...new ReadyGuildDTO(x as Guild & { joined_at: Date }).toJSON(),
guild_hashes: {},
joined_at: x.joined_at
joined_at: x.joined_at,
};
}),
guild_experiments: [], // TODO
+5 -1
View File
@@ -159,7 +159,11 @@ async function getMembers(guild_id: string, range: [number, number]) {
groups,
range,
members: items
.map((x) => ("member" in x ? { ...x.member, settings: undefined } : undefined))
.map((x) =>
"member" in x
? { ...x.member, settings: undefined }
: undefined,
)
.filter((x) => !!x),
};
}
+1 -1
View File
@@ -62,7 +62,7 @@ export async function onVoiceStateUpdate(this: WebSocket, data: Payload) {
}
// 'Fix' for this one voice state error. TODO: Find out why this is sent
// It seems to be sent on client load,
// It seems to be sent on client load,
// so maybe its trying to find which server you were connected to before disconnecting, if any?
if (body.guild_id == null) {
return;