summary refs log tree commit diff
path: root/src/opcodes/Identify.ts
blob: f62f66b02b59446831ac241a22cb05de03cfc4f0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { CLOSECODES, Payload } from "../util/Constants";
import WebSocket from "../util/WebSocket";
import { checkToken, Intents } from "fosscord-server-util";
import { setupListener } from "../listener/listener";
import { instanceOf } from "lambert-server";
import { IdentifySchema } from "../schema/Identify";
// TODO: check priviliged intents

export async function onIdentify(this: WebSocket, data: Payload) {
	try {
		clearTimeout(this.readyTimeout);
		instanceOf(IdentifySchema, data.d);

		const identify: IdentifySchema = data.d;

		var decoded = await checkToken(identify.token);
		this.userid = decoded.id;
		this.intents = new Intents(identify.intents);

		await setupListener.call(this);
	} catch (error) {
		return this.close(CLOSECODES.Authentication_failed);
	}
}