diff --git a/src/opcodes/Heartbeat.ts b/src/opcodes/Heartbeat.ts
new file mode 100644
index 00000000..d7e7fb5f
--- /dev/null
+++ b/src/opcodes/Heartbeat.ts
@@ -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 });
+}
diff --git a/src/opcodes/Identify.ts b/src/opcodes/Identify.ts
new file mode 100644
index 00000000..ebb5ca70
--- /dev/null
+++ b/src/opcodes/Identify.ts
@@ -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);
+ }
+}
diff --git a/src/opcodes/PresenceUpdate.ts b/src/opcodes/PresenceUpdate.ts
new file mode 100644
index 00000000..95cf2306
--- /dev/null
+++ b/src/opcodes/PresenceUpdate.ts
@@ -0,0 +1,4 @@
+import { Payload } from "../util/Constants";
+import WebSocket from "../util/WebSocket";
+
+export function onPresenceUpdate(this: WebSocket, data: Payload) {}
diff --git a/src/opcodes/RequestGuildMembers.ts b/src/opcodes/RequestGuildMembers.ts
new file mode 100644
index 00000000..38be738a
--- /dev/null
+++ b/src/opcodes/RequestGuildMembers.ts
@@ -0,0 +1,5 @@
+import { Payload } from "../util/Constants";
+
+import WebSocket from "../util/WebSocket";
+
+export function onRequestGuildMembers(this: WebSocket, data: Payload) {}
diff --git a/src/opcodes/Resume.ts b/src/opcodes/Resume.ts
new file mode 100644
index 00000000..57a9a033
--- /dev/null
+++ b/src/opcodes/Resume.ts
@@ -0,0 +1,5 @@
+import { Payload } from "../util/Constants";
+
+import WebSocket from "../util/WebSocket";
+
+export function onResume(this: WebSocket, data: Payload) {}
diff --git a/src/opcodes/VoiceStateUpdate.ts b/src/opcodes/VoiceStateUpdate.ts
new file mode 100644
index 00000000..e602f652
--- /dev/null
+++ b/src/opcodes/VoiceStateUpdate.ts
@@ -0,0 +1,5 @@
+import { Payload } from "../util/Constants";
+
+import WebSocket from "../util/WebSocket";
+
+export function onVoiceStateUpdate(this: WebSocket, data: Payload) {}
diff --git a/src/opcodes/index.ts b/src/opcodes/index.ts
new file mode 100644
index 00000000..d3b4180b
--- /dev/null
+++ b/src/opcodes/index.ts
@@ -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,
+};
diff --git a/src/opcodes/instanceOf.ts b/src/opcodes/instanceOf.ts
new file mode 100644
index 00000000..b0c9bf26
--- /dev/null
+++ b/src/opcodes/instanceOf.ts
@@ -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;
+ }
+}
|