Merge branch 'master' of https://github.com/discord-open-source/discord-gateway into main
This commit is contained in:
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
export enum OPCODES {
|
||||
Dispatch,
|
||||
Heartbeat,
|
||||
Identify,
|
||||
Presence_Update,
|
||||
Voice_State_Update,
|
||||
Resume,
|
||||
Reconnect,
|
||||
Request_Guild_Members,
|
||||
Invalid_Session,
|
||||
Hello,
|
||||
Heartbeat_ACK,
|
||||
}
|
||||
export enum CLOSECODES {
|
||||
Unknown_error = 4000,
|
||||
Unknown_opcode,
|
||||
Decode_error,
|
||||
Not_authenticated,
|
||||
Authentication_failed,
|
||||
Already_authenticated,
|
||||
Invalid_session,
|
||||
Invalid_seq,
|
||||
Rate_limited,
|
||||
Session_timed_out,
|
||||
Invalid_shard,
|
||||
Sharding_required,
|
||||
Invalid_API_version,
|
||||
Invalid_intent,
|
||||
Disallowed_intent,
|
||||
}
|
||||
export enum SEQUENCENUM {}
|
||||
@@ -0,0 +1,15 @@
|
||||
//* https://discord.com/developers/docs/topics/gateway
|
||||
|
||||
import { OPCODES, SEQUENCENUM } from "./codes";
|
||||
|
||||
export interface message_prod {
|
||||
op: OPCODES;
|
||||
d: object;
|
||||
s: SEQUENCENUM;
|
||||
t: string;
|
||||
}
|
||||
|
||||
export interface message_dev {
|
||||
req_type: "new_auth" | "check_auth";
|
||||
token?: string;
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { MongoDatabase } from "lambert-db";
|
||||
|
||||
const db = new MongoDatabase();
|
||||
|
||||
export default db;
|
||||
@@ -0,0 +1,43 @@
|
||||
import WebSocket from "ws";
|
||||
import DB from "./extras/Database";
|
||||
import { message_dev } from "./assets/datastru";
|
||||
import { v4 } from "uuid";
|
||||
|
||||
class Server {
|
||||
db: any;
|
||||
constructor() {
|
||||
this.db = DB;
|
||||
}
|
||||
|
||||
async listen(): Promise<void> {
|
||||
await this.db.init();
|
||||
const wss = new WebSocket.Server({ port: 8080 });
|
||||
|
||||
wss.on("connection", (ws) => {
|
||||
ws.on("message", async (msg: any) => {
|
||||
const message: message_dev = msg;
|
||||
|
||||
if (message.req_type) {
|
||||
switch (message.req_type) {
|
||||
case "new_auth":
|
||||
const token = v4();
|
||||
await this.db.data.auth.push({ token });
|
||||
return ws.send({ new_token: token });
|
||||
case "check_auth":
|
||||
if (!message.token) {
|
||||
return ws.send({ error: "token not providen" });
|
||||
}
|
||||
return this.db.data.auth({ token: message.token }).get();
|
||||
}
|
||||
} else {
|
||||
ws.send({ error: "req_type not providen" });
|
||||
}
|
||||
});
|
||||
|
||||
ws.send("connected");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const s = new Server();
|
||||
s.listen();
|
||||
Reference in New Issue
Block a user