✨ opcodes
This commit is contained in:
parent
471d1d6b28
commit
4eba7f5068
10
src/opcodes/Heartbeat.ts
Normal file
10
src/opcodes/Heartbeat.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { Payload } from "../util/Constants";
|
||||||
|
import { Send } from "../util/Send";
|
||||||
|
import { setHeartbeat } from "../util/setHeartbeat";
|
||||||
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
|
export function onHeartbeat(this: WebSocket, data: Payload) {
|
||||||
|
setHeartbeat(this);
|
||||||
|
|
||||||
|
Send(this, { op: 11 });
|
||||||
|
}
|
18
src/opcodes/Identify.ts
Normal file
18
src/opcodes/Identify.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { CLOSECODES, Payload } from "../util/Constants";
|
||||||
|
import Config from "../util/Config";
|
||||||
|
import WebSocket from "../util/WebSocket";
|
||||||
|
import { checkToken, IdentifySchema } from "discord-server-util";
|
||||||
|
import { check } from "./instanceOf";
|
||||||
|
|
||||||
|
export async function onIdentify(this: WebSocket, data: Payload) {
|
||||||
|
clearTimeout(this.readyTimeout);
|
||||||
|
if (check.call(this, IdentifySchema, data.d)) return;
|
||||||
|
|
||||||
|
const identify: IdentifySchema = data.d;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var { id } = await checkToken(identify.token);
|
||||||
|
} catch (error) {
|
||||||
|
return this.close(CLOSECODES.Authentication_failed);
|
||||||
|
}
|
||||||
|
}
|
4
src/opcodes/PresenceUpdate.ts
Normal file
4
src/opcodes/PresenceUpdate.ts
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
import { Payload } from "../util/Constants";
|
||||||
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
|
export function onPresenceUpdate(this: WebSocket, data: Payload) {}
|
5
src/opcodes/RequestGuildMembers.ts
Normal file
5
src/opcodes/RequestGuildMembers.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { Payload } from "../util/Constants";
|
||||||
|
|
||||||
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
|
export function onRequestGuildMembers(this: WebSocket, data: Payload) {}
|
5
src/opcodes/Resume.ts
Normal file
5
src/opcodes/Resume.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { Payload } from "../util/Constants";
|
||||||
|
|
||||||
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
|
export function onResume(this: WebSocket, data: Payload) {}
|
5
src/opcodes/VoiceStateUpdate.ts
Normal file
5
src/opcodes/VoiceStateUpdate.ts
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { Payload } from "../util/Constants";
|
||||||
|
|
||||||
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
|
export function onVoiceStateUpdate(this: WebSocket, data: Payload) {}
|
19
src/opcodes/index.ts
Normal file
19
src/opcodes/index.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { Payload } from "../util/Constants";
|
||||||
|
import WebSocket from "../util/WebSocket";
|
||||||
|
import { onHeartbeat } from "./Heartbeat";
|
||||||
|
import { onIdentify } from "./Identify";
|
||||||
|
import { onPresenceUpdate } from "./PresenceUpdate";
|
||||||
|
import { onRequestGuildMembers } from "./RequestGuildMembers";
|
||||||
|
import { onResume } from "./Resume";
|
||||||
|
import { onVoiceStateUpdate } from "./VoiceStateUpdate";
|
||||||
|
|
||||||
|
export type OPCodeHandler = (this: WebSocket, data: Payload) => any;
|
||||||
|
|
||||||
|
export default {
|
||||||
|
1: onHeartbeat,
|
||||||
|
2: onIdentify,
|
||||||
|
3: onPresenceUpdate,
|
||||||
|
4: onVoiceStateUpdate,
|
||||||
|
5: onResume,
|
||||||
|
8: onRequestGuildMembers,
|
||||||
|
};
|
13
src/opcodes/instanceOf.ts
Normal file
13
src/opcodes/instanceOf.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { instanceOf } from "lambert-server";
|
||||||
|
import { CLOSECODES } from "../util/Constants";
|
||||||
|
import WebSocket from "../util/WebSocket";
|
||||||
|
|
||||||
|
export function check(this: WebSocket, schema: any, data: any) {
|
||||||
|
try {
|
||||||
|
return instanceOf(schema, data);
|
||||||
|
} catch (error) {
|
||||||
|
// invalid identify struct
|
||||||
|
this.close(CLOSECODES.Decode_error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user